Skip to content

Commit

Permalink
Add Escape keybinding to dismiss inline messages. (#211)
Browse files Browse the repository at this point in the history
Fixes #200.
  • Loading branch information
ehuss authored and Jason Williams committed Oct 28, 2017
1 parent d76638e commit cf07fd1
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Default (Linux).sublime-keymap
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,10 @@
{"key": "selector", "operator":"equal", "operand": "source.rust"}
]
},
{"keys": ["escape"], "command": "rust_dismiss_messages", "context":
[
{"key": "selector", "operator":"equal", "operand": "source.rust"},
{"key": "rust_has_messages", "operator": "equal", "operand": true}
]
},
]
6 changes: 6 additions & 0 deletions Default (OSX).sublime-keymap
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,10 @@
{"key": "selector", "operator":"equal", "operand": "source.rust"}
]
},
{"keys": ["escape"], "command": "rust_dismiss_messages", "context":
[
{"key": "selector", "operator":"equal", "operand": "source.rust"},
{"key": "rust_has_messages", "operator": "equal", "operand": true}
]
},
]
6 changes: 6 additions & 0 deletions Default (Windows).sublime-keymap
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,10 @@
{"key": "selector", "operator":"equal", "operand": "source.rust"}
]
},
{"keys": ["escape"], "command": "rust_dismiss_messages", "context":
[
{"key": "selector", "operator":"equal", "operand": "source.rust"},
{"key": "rust_has_messages", "operator": "equal", "operand": true}
]
},
]
18 changes: 18 additions & 0 deletions cargo_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,16 @@ def on_load(self, view):
sublime.set_timeout(
lambda: messages.show_messages_for_view(view), 1)

def on_query_context(self, view, key, operator, operand, match_all):
# Used by the Escape-key keybinding to dismiss inline phantoms.
if key == 'rust_has_messages':
has_messages = view.window().id() in messages.WINDOW_MESSAGES
if operator == sublime.OP_EQUAL:
return operand == has_messages
elif operator == sublime.OP_NOT_EQUAL:
return operand != has_messages
return None


class NextPrevBase(sublime_plugin.WindowCommand):

Expand Down Expand Up @@ -266,3 +276,11 @@ def run(self):
# Also call Sublime's cancel command, in case the user is using a
# normal Sublime build.
self.window.run_command('cancel_build')


class RustDismissMessagesCommand(sublime_plugin.WindowCommand):

"""Removes all inline messages."""

def run(self):
messages.clear_messages(self.window)

0 comments on commit cf07fd1

Please sign in to comment.