Permalink
Browse files

Add more protections to cursor leaving prompt

Override several more movement and editing functions on all three platforms
to prevent corrupting the REPL history buffer, including delete-by-word,
move to BOL, and delete to BOL.
  • Loading branch information...
1 parent 98c67b5 commit 2f8c93f0759a968e8502c5d1af0b42aad5120906 @mbauman mbauman committed Sep 16, 2012
Showing with 60 additions and 8 deletions.
  1. +7 −0 Default (Linux).sublime-keymap
  2. +27 −0 Default (OSX).sublime-keymap
  3. +7 −0 Default (Windows).sublime-keymap
  4. +19 −8 sublimerepl.py
@@ -32,6 +32,13 @@
{ "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true }
]
},
+ { "keys": ["ctrl+backspace"], "command": "repl_ctrl_backspace", "args": {},
+ "context":
+ [
+ { "key": "setting.repl", "operator": "equal", "operand": true },
+ { "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true }
+ ]
+ },
{ "keys": ["left"], "command": "repl_left", "args": {},
"context":
[
@@ -32,6 +32,27 @@
{ "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true }
]
},
+ { "keys": ["ctrl+backspace"], "command": "repl_ctrl_backspace", "args": {},
+ "context":
+ [
+ { "key": "setting.repl", "operator": "equal", "operand": true },
+ { "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true }
+ ]
+ },
+ { "keys": ["super+backspace"], "command": "repl_super_backspace", "args": {},
+ "context":
+ [
+ { "key": "setting.repl", "operator": "equal", "operand": true },
+ { "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true }
+ ]
+ },
+ { "keys": ["alt+backspace"], "command": "repl_ctrl_backspace", "args": {},
+ "context":
+ [
+ { "key": "setting.repl", "operator": "equal", "operand": true },
+ { "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true }
+ ]
+ },
{ "keys": ["left"], "command": "repl_left", "args": {},
"context":
[
@@ -44,6 +65,12 @@
{ "key": "setting.repl", "operator": "equal", "operand": true }
]
},
+ { "keys": ["ctrl+a"], "command": "repl_home", "args": {},
+ "context":
+ [
+ { "key": "setting.repl", "operator": "equal", "operand": true }
+ ]
+ },
{ "keys": ["shift+left"], "command": "repl_shift_left", "args": {},
"context":
[
@@ -32,6 +32,13 @@
{ "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true }
]
},
+ { "keys": ["ctrl+backspace"], "command": "repl_ctrl_backspace", "args": {},
+ "context":
+ [
+ { "key": "setting.repl", "operator": "equal", "operand": true },
+ { "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true }
+ ]
+ },
{ "keys": ["left"], "command": "repl_left", "args": {},
"context":
[
View
@@ -179,6 +179,15 @@ def on_backspace(self):
if self.delta < 0:
self._view.run_command("left_delete")
+ def on_ctrl_backspace(self):
+ if self.delta < 0:
+ self._view.run_command("delete_word", { "forward": False, "sub_words": True })
+
+ def on_super_backspace(self):
+ if self.delta < 0:
+ for i in range(abs(self.delta)):
+ self._view.run_command("left_delete") # Hack to delete to BOL
+
def on_left(self):
if self.delta != 0:
self._window.run_command("move", {"by": "characters", "forward": False, "extend": False})
@@ -191,7 +200,7 @@ def on_home(self):
if self.delta > 0:
self._window.run_command("move_to", {"to": "bol", "extend": False})
else:
- for i in range(1, self.delta + 1):
+ for i in range(abs(self.delta)):
self._window.run_command("move", {"by": "characters", "forward": False, "extend": False})
def on_shift_home(self):
@@ -546,49 +555,51 @@ def run(self, edit):
rv = manager.repl_view(self.view)
if rv: rv.on_backspace()
+class ReplCtrlBackspaceCommand(sublime_plugin.TextCommand):
+ def run(self,edit):
+ rv = manager.repl_view(self.view)
+ if rv: rv.on_ctrl_backspace()
+
+class ReplSuperBackspaceCommand(sublime_plugin.TextCommand):
+ def run(self,edit):
+ rv = manager.repl_view(self.view)
+ if rv: rv.on_super_backspace()
class ReplLeftCommand(sublime_plugin.TextCommand):
def run(self, edit):
rv = manager.repl_view(self.view)
if rv: rv.on_left()
-
class ReplShiftLeftCommand(sublime_plugin.TextCommand):
def run(self, edit):
rv = manager.repl_view(self.view)
if rv: rv.on_shift_left()
-
class ReplHomeCommand(sublime_plugin.TextCommand):
def run(self, edit):
rv = manager.repl_view(self.view)
if rv: rv.on_home()
-
class ReplShiftHomeCommand(sublime_plugin.TextCommand):
def run(self, edit):
rv = manager.repl_view(self.view)
if rv: rv.on_shift_home()
-
class ReplViewPreviousCommand(sublime_plugin.TextCommand):
def run(self, edit):
rv = manager.repl_view(self.view)
if rv: rv.previous_command(edit)
-
class ReplViewNextCommand(sublime_plugin.TextCommand):
def run(self, edit):
rv = manager.repl_view(self.view)
if rv: rv.next_command(edit)
-
class ReplKillCommand(sublime_plugin.TextCommand):
def run(self, edit):
rv = manager.repl_view(self.view)
if rv: rv.repl.kill()
-
class SublimeReplListener(sublime_plugin.EventListener):
def on_selection_modified(self, view):
rv = manager.repl_view(view)

0 comments on commit 2f8c93f

Please sign in to comment.