1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-01-23 17:40:06 +08:00

Improve autoscroll feature (#3134)

This commit is contained in:
Wang Shidong 2019-10-08 23:02:09 +08:00 committed by GitHub
parent 8a6baac866
commit e934f6e21d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 3 deletions

View File

@ -88,6 +88,21 @@ function! s:self.filter_do(expr) abort
endfor
endfunction
if exists('*nvim_buf_line_count')
function! s:self.line_count(buf) abort
return nvim_buf_line_count(a:buf)
endfunction
elseif has('lua')
function! s:self.line_count(buf) abort
" lua numbers are floats, so use float2nr
return float2nr(luaeval('#vim.buffer(vim.eval("a:buf"))'))
endfunction
else
function! s:self.line_count(buf) abort
return len(getbufline(a:buf, 1, '$'))
endfunction
endif
" just same as nvim_buf_set_lines
function! s:self.buf_set_lines(buffer, start, end, strict_indexing, replacement) abort

View File

@ -8,6 +8,7 @@
let s:JOB = SpaceVim#api#import('job')
let s:BUFFER = SpaceVim#api#import('vim#buffer')
let s:WINDOW = SpaceVim#api#import('vim#window')
let s:STRING = SpaceVim#api#import('data#string')
let s:VIM = SpaceVim#api#import('vim')
@ -73,6 +74,7 @@ function! s:start(exe) abort
let s:start_time = reltime()
call s:open_windows()
call s:BUFFER.buf_set_lines(s:bufnr, s:lines , s:lines + 3, 0, ['[REPL executable] ' . string(a:exe), '', repeat('-', 20)])
call s:VIM.win_set_cursor(s:winid, [s:VIM.buf_line_count(s:bufnr), 1])
let s:lines += 3
let s:_out_data = ['']
let s:_current_line = ''
@ -97,7 +99,9 @@ if has('nvim') && exists('*chanclose')
if bufexists(s:bufnr)
call s:BUFFER.buf_set_lines(s:bufnr, s:lines , s:lines + 1, 0, map(s:_out_data[:-2], "substitute(v:val, ' $', '', 'g')"))
let s:lines += len(s:_out_data) - 1
if s:WINDOW.get_cursor(s:winid)[0] == s:BUFFER.line_count(s:bufnr) - len(s:_out_data) + 1
call s:VIM.win_set_cursor(s:winid, [s:VIM.buf_line_count(s:bufnr), 1])
endi
call s:update_statusline()
endif
let s:_out_data = ['']
@ -105,7 +109,9 @@ if has('nvim') && exists('*chanclose')
if bufexists(s:bufnr)
call s:BUFFER.buf_set_lines(s:bufnr, s:lines , s:lines + 1, 0, map(s:_out_data[:-2], "substitute(v:val, ' $', '', 'g')"))
let s:lines += len(s:_out_data) - 1
if s:WINDOW.get_cursor(s:winid)[0] == s:BUFFER.line_count(s:bufnr) - len(s:_out_data) + 1
call s:VIM.win_set_cursor(s:winid, [s:VIM.buf_line_count(s:bufnr), 1])
endi
call s:update_statusline()
endif
let s:_out_data = [s:_out_data[-1]]
@ -116,7 +122,9 @@ else
if bufexists(s:bufnr)
call s:BUFFER.buf_set_lines(s:bufnr, s:lines , s:lines + 1, 0, a:data)
let s:lines += len(a:data)
if s:WINDOW.get_cursor(s:winid)[0] == s:BUFFER.line_count(s:bufnr) - len(a:data) + 1
call s:VIM.win_set_cursor(s:winid, [s:VIM.buf_line_count(s:bufnr), 1])
endi
call s:update_statusline()
endif
endfunction