Kiln » TortoiseHg » TortoiseHg
Clone URL:  
Pushed to one repository · View In Graph Contained in 2.0.3, 2.0.4, and 2.0.5

stable fileview: Remember scroll position when switching between annotate and file view

Changeset 97af7374008c

Parent a1230c4a44f4

by Angel Ezquerra

Changes to one file · Browse files at 97af7374008c Showing diff from parent a1230c4a44f4 Diff from another changeset...

 
137
138
139
 
140
141
142
 
264
265
266
 
267
268
269
 
276
277
278
 
 
 
279
280
281
 
 
 
282
283
284
 
348
349
350
 
 
 
 
 
 
 
351
352
353
 
356
357
358
 
 
 
 
 
 
 
359
360
361
 
137
138
139
140
141
142
143
 
265
266
267
268
269
270
271
 
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
 
356
357
358
359
360
361
362
363
364
365
366
367
368
 
371
372
373
374
375
376
377
378
379
380
381
382
383
@@ -137,6 +137,7 @@
  self._mode = None   self._lostMode = None   self._lastSearch = u'', False + self._lastScrollPosition = 0     self.actionDiffMode = QAction(qtlib.geticon('view-diff'),   _('View change as unified diff output'), @@ -264,6 +265,7 @@
  @pyqtSlot()   def clearDisplay(self):   self._filename = None + self._lastScrollPosition = 0   self.forceMode('diff')   self.clearMarkup()   @@ -276,9 +278,15 @@
  self.extralabel.hide()     def displayFile(self, filename=None, rev=None, status=None): + # Get the last visible line to restore it after reloading the editor + self._lastScrollPosition = self.sci.firstVisibleLine() +   if filename is None:   filename, status = self._filename, self._status   else: + if self._filename != filename: + # Reset the scroll positions when the file is changed + self._lastScrollPosition = 0   self._filename, self._status = filename, status   if isinstance(filename, (unicode, QString)):   filename = hglib.fromunicode(filename) @@ -348,6 +356,13 @@
  return   elif self._mode == 'ann':   self.sci.setSource(filename, self._ctx.rev()) + + # Recover the last scroll position + # Make sure that _lastScrollPosition never exceeds the amount of + # lines on the editor + self._lastScrollPosition = min(self._lastScrollPosition, \ + self.sci.lines() - 1) + self.sci.verticalScrollBar().setValue(self._lastScrollPosition)   else:   lexer = lexers.get_lexer(filename, fd.contents, self)   self.sci.setLexer(lexer) @@ -356,6 +371,13 @@
  self.sci.setText(fd.contents)   self.sci._updatemarginwidth()   + # Recover the last scroll position + # Make sure that _lastScrollPosition never exceeds the amount of + # lines on the editor + self._lastScrollPosition = min(self._lastScrollPosition, \ + self.sci.lines() - 1) + self.sci.verticalScrollBar().setValue(self._lastScrollPosition) +   self.highlightText(*self._lastSearch)   uf = hglib.tounicode(self._filename)   self.fileDisplayed.emit(uf, fd.contents or QString())