erietz / vim-terminator

:dagger: Run your code in an output buffer or a vim terminal conveniently
GNU General Public License v3.0
116 stars 2 forks source link

Fix delimiter search. #5

Closed joalof closed 3 years ago

joalof commented 3 years ago

This PR is an attempt to fix a couple of minor issues with the sending of delimited text aka "code cells". Two issues in the main branch have been identified: 1) Running a cell with the cursor positioned on the first character of a delimiter line also triggers the above cell. 2) If the entire cell doesn't fit within the current visible window the delimiters are not found.

The proposed fix changes the delimiter search in fterminator#get_in_delimiter() so it always starts at the end of the current line and also limit searches to the first/last actual line rather than first/last visible line.

erietz commented 3 years ago

I was able to reproduce both of the mentioned issues in vim and neovim. This PR is a clean solution to the problem. I ended up replacing the function charcol with virtcol since the former does not exist in neovim. The two functions appear to have the same effect, though I cannot quite make sense out of :help virtcol() :). This should close #4

joalof commented 3 years ago

Awesome, thanks!

Looking at my code again I think there actually a small mistake. For the search_pos I obtained the character index of the last column with charcol($) but then use setpos to move the cursor, which uses the column byte position and not character index. I think this can make a difference with multibyte characters. So, in vanilla vim, we should probably use col($) instead so the correct line becomes let search_pos = [save_pos[0], save_pos[1], col('$'), save_pos[3]]. Hopefully there is a corresponding function in neovim. virtcol() seems to give the visual column position, so different tabsizes would give different numbers, not sure if this can mess up anything though.

erietz commented 3 years ago

Yes, this is correct. After rereading the :help, all of setpos, getpos, and col use the byte index. I will change virtcol to just col.