diff --git a/Default.sublime-keymap b/Default.sublime-keymap index 4711807..0f363a8 100644 --- a/Default.sublime-keymap +++ b/Default.sublime-keymap @@ -59,8 +59,8 @@ }, { "keys": ["z", "z"], "command" : "center_on_cursor", "context": [{"key": "setting.command_mode"}] }, - { "keys": ["z", "t"], "command" : "scroll_cursor_line_to_top", "context": [{"key": "setting.command_mode"}] }, - { "keys": ["z", "b"], "command" : "scroll_cursor_line_to_bottom", "context": [{"key": "setting.command_mode"}] }, + { "keys": ["z", "t"], "command" : "scroll_cursor_line", "args": {"to": "top"}, "context": [{"key": "setting.command_mode"}] }, + { "keys": ["z", "b"], "command" : "scroll_cursor_line", "args": {"to": "bottom"}, "context": [{"key": "setting.command_mode"}] }, { "keys": ["Z", "Z"], "command" : "vi_save_and_exit", "context": [{"key": "setting.command_mode"}] }, diff --git a/vintage.py b/vintage.py index e5413db..2831c27 100644 --- a/vintage.py +++ b/vintage.py @@ -975,15 +975,27 @@ class CenterOnCursor(sublime_plugin.TextCommand): def run(self, edit): self.view.show_at_center(self.view.sel()[0]) -class ScrollCursorLineToTop(sublime_plugin.TextCommand): - def run(self, edit): - self.view.set_viewport_position((self.view.viewport_position()[0], self.view.layout_extent()[1])) - self.view.show(self.view.sel()[0], False) - -class ScrollCursorLineToBottom(sublime_plugin.TextCommand): - def run(self, edit): - self.view.set_viewport_position((self.view.viewport_position()[0], 0.0)) - self.view.show(self.view.sel()[0], False) +class ScrollCursorLineCallback(sublime_plugin.TextCommand): + def run(self, edit, region_set, motion_mode): + for region in region_set: + self.view.sel().add(sublime.Region(long(region[0]), long(region[1]))) + set_motion_mode(self.view, int(motion_mode)) + +class ScrollCursorLine(sublime_plugin.TextCommand): + def run(self, edit, to): + if to == 'top': + self.view.set_viewport_position((self.view.viewport_position()[0], self.view.layout_extent()[1])) + self.view.show(self.view.sel()[0], False) + elif to == 'bottom': + self.view.set_viewport_position((self.view.viewport_position()[0], 0)) + self.view.show(self.view.sel()[-1], False) + region_set = [] + for region in self.view.sel(): + region_set.append([region.a, region.b]) + motion_mode = g_input_state.motion_mode + self.view.sel().clear() + sublime.set_timeout(lambda: self.view.run_command('scroll_cursor_line_callback', + {'region_set': region_set, 'motion_mode': motion_mode}), 0) class ViScrollLines(ViPrefixableCommand): def run(self, edit, forward = True, repeat = None):