-
Notifications
You must be signed in to change notification settings - Fork 35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Do not change selection to update lists #145
Do not change selection to update lists #145
Conversation
let l:prev_indent = -1 | ||
let l:levels = {} " stores all the info about the current outline/list | ||
|
||
for l:line in l:selection_lines |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are using just the line numbers anyway so a loop is sufficient
" Reset the starting visual selection | ||
call setpos("'<", [0, a:1[0], a:1[1], 0]) | ||
call setpos("'>", [0, a:2[0], a:2[1], 0]) | ||
execute 'normal! gv' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need any of the reset visual selection code
" Iterate the cursor position over each line and then call | ||
" s:change_bullet_level for that cursor position. | ||
call setpos('.', [0, l:lnum, 1, 0]) | ||
call s:change_bullet_level(a:direction) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just pass in the number to save on a lot of unnecessary work
if g:bullets_renumber_on_change | ||
" Pass the current visual selection so that it gets reset after | ||
" renumbering the list. | ||
call s:renumber_whole_list(l:start, l:end) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not needed now!
@@ -1089,9 +1075,10 @@ fun! s:get_visual_selection_lines() | |||
let l:index = l:lnum1 | |||
let l:lines_with_index = [] | |||
for l:line in l:lines | |||
let l:lines_with_index += [{'text': l:line, 'nr': l:index}] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an optimisation.
However, the entire get_visual_selection_lines()
is not needed anymore and perhaps ought to be removed.
" When setting the selection we set the start and end at the same _offset_ | ||
" From the new line start and end. As we manipulate line prefixes, the | ||
" offset from the end represents the correct new cursor position | ||
fun! s:get_selection(is_visual) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to pass in is_visual because this state is lost by the time the function is triggered.
This is ready to merge |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
copied from bullets-vim/bullets.vim#145 By harshad1
In this PR I have modified several functions to eliminate the need for modifying the current selection or cursor position.
This results in:
I have also added logic to explicitly save the cursor / selection position and have it restored after the change.