GNOME Bugzilla – Bug 742442
gb-source-vim: Add support for vim scrolloff
Last modified: 2015-01-11 13:08:07 UTC
Vim scrolloff allow the user to set a margin of a number of lines while moving through the buffer. Add support to it and add a setting to let the user adjust the number of lines. As a detail, a scrolloff greater than half of the number of lines in the buffer keeps the current line always in the middle.
Created attachment 293905 [details] [review] gb-source-vim: Add support for vim scrolloff
Not sure what to do to keep the scrolloff in insert mode thoug... But I guess is working enough for now.
Review of attachment 293905 [details] [review]: Couple spelling things and nits. Fairly detailed on the nits because I want you to help maintain at some point :) -- Christian ::: src/vim/gb-source-vim.c @@ +81,3 @@ GPtrArray *captured_events; GbSourceVimMode mode; + GSettings *vim_settings; Lingering tab here. @@ +110,3 @@ typedef enum { + GB_SOURCE_VIM_ALIGMENT_NONE, Missing N in ALIGNMENT @@ +114,3 @@ + GB_SOURCE_VIM_ALIGMENT_TOP, + GB_SOURCE_VIM_ALIGMENT_BOTTOM +} GbSourceVimAligment; Same. @@ +228,3 @@ +gb_source_vim_adjust_scroll (GbSourceVim *vim, + gint line, + GbSourceVimAligment aligment); Align parameter names @@ +1551,3 @@ insert = gtk_text_buffer_get_insert (buffer); gtk_text_view_scroll_mark_onscreen (vim->priv->text_view, insert); + scroll= gb_source_vim_adjust_scroll (vim, line + 1, GB_SOURCE_VIM_ALIGMENT_NONE); Same. @@ +2660,3 @@ +{ + GdkRectangle rect; + gint line_top, line_bottom, line_current; Each declaration on it's own line. @@ +2681,3 @@ + line_bottom = gtk_text_iter_get_line (&iter_bottom); + line_current = gtk_text_iter_get_line (&iter_current); + page_lines = line_bottom - line_top; Short circuit if page_lines is zero to avoid divide by zero. @@ +2691,3 @@ + result.yalign = CLAMP (yalign, min_yalign, max_yalign); + result.line = line; + break; Newline after break. @@ +5345,3 @@ g_ptr_array_new_with_free_func ((GDestroyNotify)gdk_event_free); + + vim->priv->vim_settings= g_settings_new ("org.gnome.builder.editor.vim"); space before =
(In reply to comment #2) > Not sure what to do to keep the scrolloff in insert mode thoug... But I guess > is working enough for now. Can we hook in the key-press-event when in insert mode?
Created attachment 293935 [details] [review] gb-source-vim: Add support for vim scrolloff Vim scrolloff allow the user to set a margin of a number of lines while moving through the buffer. Add support to it and add a setting to let the user adjust the number of lines. One downside of the implementation is that movement commands scroll horizontally not just the needed movement but also scrolls making the word position the left as possible. This is noticed when the scroll view has horizontal scrolling and the user moves backward in word motions in the words that are normally outside the view when the view is scrolled maximum to the left. The other downside is that insert mode doesn't take scroll off into account. But the view position right after entering modal mode. I guess this is good enough for now. As a detail, a scrolloff greater than half of the number of lines in the buffer keeps the current line always in the middle.
(In reply to comment #4) > (In reply to comment #2) > > Not sure what to do to keep the scrolloff in insert mode thoug... But I guess > > is working enough for now. > > Can we hook in the key-press-event when in insert mode? just saw your comment after attaching the new patch. Let me try that then.
Created attachment 294028 [details] [review] gb-source-vim: Add support for vim scrolloff Vim scrolloff allow the user to set a margin of a number of lines while moving through the buffer. Add support to it and add a setting to let the user adjust the number of lines. One downside of the implementation is that movement commands scroll horizontally not just the needed movement but also scrolls making the word position the left as possible. This is noticed when the scroll view has horizontal scrolling and the user moves backward in word motions in the words that are normally outside the view when the view is scrolled maximum to the left. The other downside is that insert mode doesn't take scroll off into account. But the view position right after entering modal mode. I guess this is good enough for now. As a detail, a scrolloff greater than half of the number of lines in the buffer keeps the current line always in the middle.
Created attachment 294029 [details] [review] gb-source-vim: Add support for vim scrolloff Vim scrolloff allow the user to set a margin of a number of lines while moving through the buffer. Add support to it and add a setting to let the user adjust the number of lines. One downside of the implementation is that movement commands scroll horizontally not just the needed movement but also scrolls making the word position the left as possible. This is noticed when the scroll view has horizontal scrolling and the user moves backward in word motions in the words that are normally outside the view when the view is scrolled maximum to the left. As a detail, a scrolloff greater than half of the number of lines in the buffer keeps the current line always in the middle.
(In reply to comment #3) > Review of attachment 293905 [details] [review]: > > Couple spelling things and nits. Fairly detailed on the nits because I want you > to help maintain at some point :) > > -- Christian > > ::: src/vim/gb-source-vim.c > @@ +81,3 @@ > GPtrArray *captured_events; > GbSourceVimMode mode; > + GSettings *vim_settings; > > Lingering tab here. > > @@ +110,3 @@ > typedef enum > { > + GB_SOURCE_VIM_ALIGMENT_NONE, > > Missing N in ALIGNMENT > > @@ +114,3 @@ > + GB_SOURCE_VIM_ALIGMENT_TOP, > + GB_SOURCE_VIM_ALIGMENT_BOTTOM > +} GbSourceVimAligment; > > Same. > > @@ +228,3 @@ > +gb_source_vim_adjust_scroll (GbSourceVim *vim, > + gint line, > + GbSourceVimAligment aligment); > > Align parameter names > > @@ +1551,3 @@ > insert = gtk_text_buffer_get_insert (buffer); > gtk_text_view_scroll_mark_onscreen (vim->priv->text_view, insert); > + scroll= gb_source_vim_adjust_scroll (vim, line + 1, > GB_SOURCE_VIM_ALIGMENT_NONE); > > Same. > > @@ +2660,3 @@ > +{ > + GdkRectangle rect; > + gint line_top, line_bottom, line_current; > > Each declaration on it's own line. This file doesn't follow the guidelines then, since this file do it like I did it. Changed to your preference (which I noticed is also what you do in other files). Probably this file needs a reformating. > > @@ +2681,3 @@ > + line_bottom = gtk_text_iter_get_line (&iter_bottom); > + line_current = gtk_text_iter_get_line (&iter_current); > + page_lines = line_bottom - line_top; > > Short circuit if page_lines is zero to avoid divide by zero. > > @@ +2691,3 @@ > + result.yalign = CLAMP (yalign, min_yalign, max_yalign); > + result.line = line; > + break; > > Newline after break. Same, this file doesn't do that. Changed the part of my code. > > @@ +5345,3 @@ > g_ptr_array_new_with_free_func ((GDestroyNotify)gdk_event_free); > + > + vim->priv->vim_settings= g_settings_new ("org.gnome.builder.editor.vim"); > > space before =
(In reply to comment #4) > (In reply to comment #2) > > Not sure what to do to keep the scrolloff in insert mode thoug... But I guess > > is working enough for now. > > Can we hook in the key-press-event when in insert mode? Indeed, done, and also improved current code which was failing to follow scrolloff in some cases. I'm pretty happy with the result now.
Sorry for taking so long to push this! I also added support for ":set scrolloff=10" or using its alias, "so". Attachment 294029 [details] pushed as c4f71f7 - gb-source-vim: Add support for vim scrolloff
(In reply to comment #11) > Sorry for taking so long to push this! > > I also added support for ":set scrolloff=10" or using its alias, "so". > > Attachment 294029 [details] pushed as c4f71f7 - gb-source-vim: Add support for vim > scrolloff Nice! Thanks Christian!