Skip to content

Commit a3d15aa

Browse files
committed
Detect visual blocks too
1 parent 97418c9 commit a3d15aa

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

autoload/augment.vim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ function! s:CommandChat(range, args) abort
173173

174174
" If range arguments were provided (when using :Augment chat) or in visual
175175
" mode, get the selected text
176-
if a:range == 2 || mode() ==# 'v' || mode() ==# 'V'
176+
if a:range == 2 || mode() ==# 'v' || mode() ==# 'V' || mode() ==# nr2char(22)
177177
let selected_text = augment#chat#GetSelectedText()
178178
else
179179
let selected_text = ''

autoload/augment/chat.vim

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -160,16 +160,26 @@ function! s:GetBufSelection(line_start, col_start, line_end, col_end) abort
160160
return getline(a:line_start)[a:col_start - 1:a:col_end - 1]
161161
endif
162162

163+
" mode() == 'n' means we're working with Ex mode using marks
164+
if mode() ==# 'n' || mode() ==# 'v' || mode() ==# 'V'
165+
let lines = []
166+
call add(lines, getline(a:line_start)[a:col_start - 1:])
167+
call extend(lines, getline(a:line_start + 1, a:line_end - 1))
168+
call add(lines, getline(a:line_end)[0:a:col_end - 1])
169+
return join(lines, "\n")
170+
endif
171+
172+
" We're in visual block mode
163173
let lines = []
164-
call add(lines, getline(a:line_start)[a:col_start - 1:])
165-
call extend(lines, getline(a:line_start + 1, a:line_end - 1))
166-
call add(lines, getline(a:line_end)[0:a:col_end - 1])
174+
for lnum in range(a:line_start, a:line_end)
175+
call add(lines, getline(lnum)[a:col_start - 1:a:col_end - 1])
176+
endfor
167177
return join(lines, "\n")
168178
endfunction
169179

170180
function! augment#chat#GetSelectedText() abort
171181
" If in visual mode use the current selection
172-
if mode() ==# 'v' || mode() ==# 'V'
182+
if mode() ==# 'v' || mode() ==# 'V' || mode() ==# nr2char(22)
173183
let [line_one, col_one] = getpos('.')[1:2]
174184
let [line_two, col_two] = getpos('v')[1:2]
175185

@@ -197,10 +207,6 @@ function! augment#chat#GetSelectedText() abort
197207
endif
198208
endif
199209

200-
" . and v return column positions one lower than '< and '>
201-
let col_start += 1
202-
let col_end += 1
203-
204210
" In visual line mode, the columns will be incorrect
205211
if mode() ==# 'V'
206212
let col_start = 1

0 commit comments

Comments
 (0)