From 0913362a7584af5730aa4668b33366dad0e571a8 Mon Sep 17 00:00:00 2001 From: Jon Skinner Date: Tue, 14 Feb 2012 20:38:02 +1100 Subject: [PATCH] Minor key binding simplification --- Default (OSX).sublime-keymap | 22 +-------------------- Default.sublime-keymap | 38 ++---------------------------------- vintage.py | 8 +++++++- 3 files changed, 10 insertions(+), 58 deletions(-) diff --git a/Default (OSX).sublime-keymap b/Default (OSX).sublime-keymap index 33fa21b..b973361 100644 --- a/Default (OSX).sublime-keymap +++ b/Default (OSX).sublime-keymap @@ -22,27 +22,7 @@ "context": [ { "key": "setting.command_mode" }, - { "key": "vi_has_action" }, - { "key": "selection_empty", "operator": "equal", "operand": true, "match_all": false }, - { "key": "setting.vintage_ctrl_keys" } - ] - }, - - { "keys": ["ctrl+c"], "command": "vi_cancel_current_action", - "context": - [ - { "key": "setting.command_mode" }, - { "key": "vi_has_repeat_digit" }, - { "key": "selection_empty", "operator": "equal", "operand": true, "match_all": false }, - { "key": "setting.vintage_ctrl_keys" } - ] - }, - - { "keys": ["ctrl+c"], "command": "vi_cancel_current_action", - "context": - [ - { "key": "setting.command_mode" }, - { "key": "vi_has_register" }, + { "key": "vi_has_input_state" }, { "key": "selection_empty", "operator": "equal", "operand": true, "match_all": false }, { "key": "setting.vintage_ctrl_keys" } ] diff --git a/Default.sublime-keymap b/Default.sublime-keymap index 80fa988..4751f9f 100644 --- a/Default.sublime-keymap +++ b/Default.sublime-keymap @@ -26,23 +26,7 @@ [ { "key": "setting.command_mode" }, { "key": "selection_empty", "operator": "equal", "operand": true, "match_all": false }, - { "key": "vi_has_action" } - ] - }, - - { "keys": ["escape"], "command": "vi_cancel_current_action", "context": - [ - { "key": "setting.command_mode" }, - { "key": "selection_empty", "operator": "equal", "operand": true, "match_all": false }, - { "key": "vi_has_repeat_digit" } - ] - }, - - { "keys": ["escape"], "command": "vi_cancel_current_action", "context": - [ - { "key": "setting.command_mode" }, - { "key": "selection_empty", "operator": "equal", "operand": true, "match_all": false }, - { "key": "vi_has_register" } + { "key": "vi_has_input_state" } ] }, @@ -68,25 +52,7 @@ { "keys": ["ctrl+["], "command": "vi_cancel_current_action", "context": [ { "key": "setting.command_mode" }, - { "key": "vi_has_action" }, - { "key": "selection_empty", "operator": "equal", "operand": true, "match_all": false }, - { "key": "setting.vintage_ctrl_keys" } - ] - }, - - { "keys": ["ctrl+["], "command": "vi_cancel_current_action", "context": - [ - { "key": "setting.command_mode" }, - { "key": "vi_has_repeat_digit" }, - { "key": "selection_empty", "operator": "equal", "operand": true, "match_all": false }, - { "key": "setting.vintage_ctrl_keys" } - ] - }, - - { "keys": ["ctrl+["], "command": "vi_cancel_current_action", "context": - [ - { "key": "setting.command_mode" }, - { "key": "vi_has_register" }, + { "key": "vi_has_input_state" }, { "key": "selection_empty", "operator": "equal", "operand": true, "match_all": false }, { "key": "setting.vintage_ctrl_keys" } ] diff --git a/vintage.py b/vintage.py index 99e5ee5..afa056b 100644 --- a/vintage.py +++ b/vintage.py @@ -14,7 +14,6 @@ # * set_action # * set_motion # * push_repeat_digit - class InputState: prefix_repeat_digits = [] action_command = None @@ -176,6 +175,13 @@ def on_query_context(self, view, key, operator, operand, match_all): v = len(g_input_state.prefix_repeat_digits) > 0 if operator == sublime.OP_EQUAL: return v == operand if operator == sublime.OP_NOT_EQUAL: return v != operand + elif key == "vi_has_input_state": + v = (len(g_input_state.motion_repeat_digits) > 0 or + len(g_input_state.prefix_repeat_digits) > 0 or + g_input_state.action_command is not None or + g_input_state.register is not None) + if operator == sublime.OP_EQUAL: return v == operand + if operator == sublime.OP_NOT_EQUAL: return v != operand elif key == "vi_can_enter_text_object": v = (g_input_state.action_command is not None) or view.has_non_empty_selection_region() if operator == sublime.OP_EQUAL: return v == operand