Skip to content

Commit b87230f

Browse files
committed
llama.vim : handle space
1 parent 6affdbd commit b87230f

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

examples/llama.vim

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -127,14 +127,16 @@ function! llama#fim() abort
127127
inoremap <buffer> <Tab> <C-O>:call llama#cancel_virtual_text()<CR>
128128
endif
129129

130-
for l:key in range(33, 127) + [8, 27]
130+
for l:key in range(32, 127) + [8, 27]
131131
if l:key != 0x7C
132132
if l:key == 8
133-
execute 'inoremap <buffer> <Bs> <C-O>:call llama#cancel_virtual_text()<CR><Bs>'
133+
execute 'inoremap <buffer> <Bs> <C-O>:call llama#cancel_virtual_text()<CR><Bs>'
134134
elseif l:key == 27
135-
execute 'inoremap <buffer> <Esc> <C-O>:call llama#cancel_virtual_text()<CR><Esc>'
135+
execute 'inoremap <buffer> <Esc> <C-O>:call llama#cancel_virtual_text()<CR><Esc>'
136+
elseif l:key == 32
137+
execute 'inoremap <buffer> <Space> <C-O>:call llama#cancel_virtual_text()<CR><Space>'
136138
elseif l:key == 127
137-
execute 'inoremap <buffer> <Del> <C-O>:call llama#cancel_virtual_text()<CR><Del>'
139+
execute 'inoremap <buffer> <Del> <C-O>:call llama#cancel_virtual_text()<CR><Del>'
138140
else
139141
execute 'inoremap <buffer> ' . nr2char(l:key) . ' <C-O>:call llama#cancel_virtual_text()<CR>' . nr2char(l:key)
140142
endif
@@ -153,11 +155,7 @@ function! llama#accept_virtual_text()
153155

154156
let l:line_cur = getline('.')
155157

156-
let l:pos0 = l:pos_x - 2
157-
158-
if l:pos_x == len(l:line_cur)
159-
let l:pos0 = l:pos_x - 1
160-
endif
158+
let l:pos0 = l:pos_x == len(l:line_cur) ? l:pos_x - 1 : l:pos_x - 2
161159

162160
" insert the suggestion at the cursor location
163161
call setline(l:pos_y, l:line_cur[:l:pos0] . s:content[0])
@@ -179,12 +177,14 @@ function! llama#cancel_virtual_text()
179177
" remove the mappings
180178
iunmap <buffer> <Tab>
181179

182-
for l:key in range(33, 127) + [8, 27]
180+
for l:key in range(32, 127) + [8, 27]
183181
if l:key != 0x7C
184182
if l:key == 8
185183
execute 'iunmap <buffer> <Bs>'
186184
elseif l:key == 27
187185
execute 'iunmap <buffer> <Esc>'
186+
elseif l:key == 32
187+
execute 'iunmap <buffer> <Space>'
188188
elseif l:key == 127
189189
execute 'iunmap <buffer> <Del>'
190190
else

0 commit comments

Comments
 (0)