7

So the problem is to assign this to Escape without overriding any other functionality. I've tried the following, but it doesn't work.

{
  "keys": ["escape"],
  "command": "exec",
  "args": {"hide_phantoms_only" : true },
  "context": [ { "key": "phantom_visible", "operator": "equal", "operand": true }],
},

I haven't found any documentation on which context keys exist, so phantom_visible was just a guess.

Andreas Haferburg
  • 5,189
  • 3
  • 37
  • 63
  • 3
    good question - unfortunately it seems like there is no context atm to tell when build error phantoms are visible: https://forum.sublimetext.com/t/keyboard-binding-to-dismiss-inline-build-errors/21956 – Keith Hall Jan 28 '17 at 16:02

2 Answers2

4

Unfortunately, at the moment Sublime Text (at the time of writing, build 3126) does not have a context that you can use in a keybinding to tell when inline build error phantoms are shown. This has been briefly discussed in the ST forums so it is possible that a future build will contain this functionality.

In the meantime, inspired by this post, we could potentially try to create a keybinding that won't conflict with the default Esc behavior. But it's worth bearing in mind that the default keybindings may change so we will need to watch for it when updating ST, to see whether this is still relevant/correctly covers all scenarios:

{ "keys": ["escape"], "command": "exec", "args": { "hide_phantoms_only": true },
    "context":
    [
        // inverse of all the "escape" key contexts found in the Default keybindings
        { "key": "num_selections", "operator": "equal", "operand": 1 },
        { "key": "has_next_field", "operator": "equal", "operand": false },
        { "key": "has_prev_field", "operator": "equal", "operand": false },
        { "key": "panel_visible", "operator": "equal", "operand": false },
        { "key": "overlay_visible", "operator": "equal", "operand": false },
        { "key": "auto_complete_visible", "operator": "equal", "operand": false }
    ]
}
Keith Hall
  • 15,362
  • 3
  • 53
  • 71
0

I used Package Control to install Chain of Command, which allows me to do more than 1 command for each context.

When I press the [esc] key, now it does three things when the panel is visible:

  • Hides the panel
  • Hides the red error boxes
  • Kills the running program

Here is my key mapping for this:

[ 
    { "keys": ["escape"],
        "context": [
            { "key": "panel_visible", "operator": "equal", "operand": true }
                   ],
        "command": "chain",
        "args": {
            "commands": [
                ["hide_panel", {"cancel": true}],
                ["exec", {"hide_phantoms_only": true}],
                ["exec", {"kill": true}]
            ]
        }
    }
]
Kade
  • 901
  • 13
  • 18