@@ -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 " )
168178endfunction
169179
170180function ! 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