From 71b0e0fb94f4cd5102fb0ece4fdccf2a97649367 Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Fri, 17 May 2024 21:48:08 +0900 Subject: [PATCH] [Changes] Fix 'List index out of range: 0' error Ignore change item that points to a non-existent line --- autoload/fzf/vim.vim | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/autoload/fzf/vim.vim b/autoload/fzf/vim.vim index c2e57c5..8e9fd9f 100755 --- a/autoload/fzf/vim.vim +++ b/autoload/fzf/vim.vim @@ -1218,7 +1218,11 @@ endfunction " ------------------------------------------------------------------ function! s:format_change(bufnr, offset, item) - return printf("%3d %s %4d %3d %s", a:bufnr, s:yellow(printf('%6s', a:offset)), a:item.lnum, a:item.col, getbufline(a:bufnr, a:item.lnum)[0]) + let buflines = getbufline(a:bufnr, a:item.lnum) + if empty(buflines) + return '' + endif + return printf("%3d %s %4d %3d %s", a:bufnr, s:yellow(printf('%6s', a:offset)), a:item.lnum, a:item.col, buflines[0]) endfunction function! s:changes_sink(lines) @@ -1260,7 +1264,7 @@ function! fzf#vim#changes(...) if current let cursor = len(changes) - position_or_length endif - let all_changes += map(reverse(changes), { idx, val -> s:format_change(bufnr, s:format_change_offset(current, idx, cursor), val) }) + let all_changes += filter(map(reverse(changes), { idx, val -> s:format_change(bufnr, s:format_change_offset(current, idx, cursor), val) }), '!empty(v:val)') endfor return s:fzf('changes', {