@@ -49,6 +49,27 @@ def vim_repr(value):
49
49
def make_vim_range (start , stop ):
50
50
return [[start [0 ] + 1 , start [2 ] + 1 ], [stop [0 ] + 1 , stop [2 ] + 1 ]]
51
51
52
+ # Return a list of all windows that are displaying the buffer, along with their
53
+ # current cursor positions.
54
+ def get_cursors_for_buffer (vim_buffer ):
55
+ result = []
56
+ for win in vim .windows :
57
+ if win .buffer is vim_buffer :
58
+ result .append ((win , win .cursor ))
59
+ return result
60
+
61
+ # Takes the list of window cursor positions from get_cursor_for_buffer. If the
62
+ # cursor position is now lower for any of the windows, they are entered to
63
+ # rescroll the window.
64
+ def fix_scroll (cursors ):
65
+ refresh_now = None
66
+ for win , (row , col ) in cursors :
67
+ if win .cursor [0 ] < row or win .cursor [1 ] < col :
68
+ win .vars ['coquille_needs_scroll_fix' ] = 1
69
+ if win .tabpage is vim .current .tabpage :
70
+ vim .command ("call coquille#FixWindowScrollTabWin(%d, %d)" %
71
+ (win .tabpage .number , win .number ))
72
+
52
73
# All the python side state associated with the vim source buffer
53
74
class BufferState (object ):
54
75
# Dict mapping source buffer id to BufferState
@@ -274,6 +295,7 @@ def show_goal(self, response):
274
295
modifiable = self .goal_buffer .options ["modifiable" ]
275
296
self .goal_buffer .options ["modifiable" ] = True
276
297
try :
298
+ cursors = get_cursors_for_buffer (self .goal_buffer )
277
299
del self .goal_buffer [:]
278
300
279
301
if response is None :
@@ -320,6 +342,8 @@ def show_goal(self, response):
320
342
lines = map (lambda s : s .encode ('utf-8' ), ccl .split ('\n ' ))
321
343
self .goal_buffer .append (list (lines ))
322
344
self .goal_buffer .append ('' )
345
+
346
+ fix_scroll (cursors )
323
347
finally :
324
348
self .goal_buffer .options ["modifiable" ] = modifiable
325
349
return True
@@ -329,6 +353,7 @@ def show_info(self, message):
329
353
modifiable = self .info_buffer .options ["modifiable" ]
330
354
self .info_buffer .options ["modifiable" ] = True
331
355
try :
356
+ cursors = get_cursors_for_buffer (self .info_buffer )
332
357
del self .info_buffer [:]
333
358
lst = []
334
359
if message is not None :
@@ -346,6 +371,7 @@ def show_info(self, message):
346
371
# extend function, and its append mostly behaves like extend.
347
372
self .info_buffer [0 ] = lst [0 ]
348
373
self .info_buffer .append (lst [1 :])
374
+ fix_scroll (cursors )
349
375
finally :
350
376
self .info_buffer .options ["modifiable" ] = modifiable
351
377
0 commit comments