diff options
-rw-r--r-- | ranger/defaults/keys.py | 29 | ||||
-rw-r--r-- | ranger/gui/widgets/console.py | 21 |
2 files changed, 31 insertions, 19 deletions
diff --git a/ranger/defaults/keys.py b/ranger/defaults/keys.py index 32e3e142..8683e466 100644 --- a/ranger/defaults/keys.py +++ b/ranger/defaults/keys.py @@ -53,6 +53,17 @@ def _vimlike_aliases(map): alias(KEY_HOME, 'gg') alias(KEY_END, 'G') + +def _emacs_aliases(map): + alias = map.alias + alias(KEY_LEFT, ctrl('b')) + alias(KEY_RIGHT, ctrl('f')) + alias(KEY_HOME, ctrl('a')) + alias(KEY_END, ctrl('e')) + alias(KEY_DC, ctrl('d')) + alias(DEL, ctrl('h')) + + def initialize_commands(map): """Initialize the commands for the main user interface""" @@ -222,27 +233,24 @@ def initialize_commands(map): def initialize_console_commands(map): """Initialize the commands for the console widget only""" + _basic_movement(map) + _emacs_aliases(map) + # -------------------------------------------------------- movement map(KEY_UP, wdg.history_move(-1)) map(KEY_DOWN, wdg.history_move(1)) - - map(ctrl('b'), KEY_LEFT, wdg.move(relative = -1)) - map(ctrl('f'), KEY_RIGHT, wdg.move(relative = 1)) - map(ctrl('a'), KEY_HOME, wdg.move(absolute = 0)) - map(ctrl('e'), KEY_END, wdg.move(absolute = -1)) + map(KEY_HOME, wdg.move(right=0, absolute=True)) + map(KEY_END, wdg.move(right=-1, absolute=True)) # ----------------------------------------- deleting / pasting text - map(ctrl('d'), KEY_DC, wdg.delete(0)) - map(ctrl('h'), KEY_BACKSPACE, DEL, wdg.delete(-1)) + map(KEY_DC, wdg.delete(0)) + map(KEY_BACKSPACE, DEL, wdg.delete(-1)) map(ctrl('w'), wdg.delete_word()) map(ctrl('k'), wdg.delete_rest(1)) map(ctrl('u'), wdg.delete_rest(-1)) map(ctrl('y'), wdg.paste()) # ------------------------------------------------ system functions - _system_functions(map) - map.unbind('Q') # we don't want to quit with Q in the console... - map(KEY_F1, lambda arg: arg.fm.display_command_help(arg.wdg)) map(ctrl('c'), ESC, wdg.close()) map(ctrl('j'), KEY_ENTER, wdg.execute()) @@ -282,6 +290,7 @@ def initialize_embedded_pager_commands(map): map('q', 'i', ESC, lambda arg: arg.fm.ui.close_embedded_pager()) map.rebuild_paths() + def _base_pager_commands(map): _basic_movement(map) _vimlike_aliases(map) diff --git a/ranger/gui/widgets/console.py b/ranger/gui/widgets/console.py index 777ef3f6..d7040a4f 100644 --- a/ranger/gui/widgets/console.py +++ b/ranger/gui/widgets/console.py @@ -27,6 +27,7 @@ from ranger.defaults import commands from ranger.gui.widgets.console_mode import is_valid_mode, mode_to_class from ranger import log, relpath_conf from ranger.ext.shell_escape import shell_quote +from ranger.ext.direction import Direction import ranger DEFAULT_HISTORY = 0 @@ -214,14 +215,16 @@ class Console(Widget): self.history.fast_forward() self.history.modify(self.line) - def move(self, relative = 0, absolute = None): - if absolute is not None: - if absolute < 0: - self.pos = len(self.line) + 1 + absolute - else: - self.pos = absolute - - self.pos = min(max(0, self.pos + relative), len(self.line)) + def move(self, **keywords): + from ranger import log + log(keywords) + direction = Direction(keywords) + if direction.horizontal(): + self.pos = direction.move( + direction=direction.right(), + minimum=0, + maximum=len(self.line) + 1, + current=self.pos) def delete_rest(self, direction): self.tab_deque = None @@ -260,7 +263,7 @@ class Console(Widget): pos = self.pos + mod self.line = self.line[0:pos] + self.line[pos+1:] - self.move(relative = mod) + self.move(right=mod) self.on_line_change() def execute(self): |