Sublime Forum

Switch focus away from sublime console on pressing F9

#1

Hi,

I am trying to create a keybinding that allows me to move my cursor (i.e focus ) to group 0, when the focus is on the console.

The first keybinding works for the sidebar tree, but the second one ofcourse wrong.

where can I find all the list on possible values for “operands”, etc ?

  {
    "keys": [","],
    "command": "focus_group",
    "args": {"group": 0},
    "context": [
        {"key": "control", "operand": "sidebar_tree"}
    ]
  },

The below is a sample of what my aim is, but I am tough out of luck trying to figure out a solution.

  {
    "keys": ["f9"],
    "command": "focus_group",
    "args": {"group": 0},
    "context": [
        {"operand": "console"}
    ]
  },

One important caveat is that, when my focus is group 0, f9 does something else, the keybinding for F9 should only work when the focus is on the console.

Thanks for your help.

0 Likes

#2

A little plugin is required to provide a focus_active_sheet command.

import sublime_plugin


class FocusActiveSheetCommand(sublime_plugin.WindowCommand):
	def run(self):
		active_sheet = self.window.active_sheet()
		if active_sheet:
			self.window.focus_sheet(active_sheet)

It can then be bound to keys.

[
	{ // focus active sheet unconditionally
		"keys": ["alt+0"],
		"command": "focus_active_sheet" ,
	},

	{ // focus active sheet and leave console open
		"keys": ["ctrl+`"],
		"command": "focus_active_sheet" ,
		"context": [
			{ "key": "panel_type", "operand": "console" },
			{ "key": "panel_has_focus" }
		],
	},

	{ // focus active sheet and leave find panel open
		"keys": ["ctrl+f"],
		"command": "focus_active_sheet" ,
		"context": [
			{ "key": "panel_type", "operand": "find" },
			{ "key": "panel_has_focus" }
		],
	},

	{ // focus active sheet and leave replace panel open
		"keys": ["ctrl+h"],
		"command": "focus_active_sheet" ,
		"context": [
			{ "key": "panel_type", "operand": "replace" },
			{ "key": "panel_has_focus" }
		],
	},
]
1 Like

Open console without focusing it
#3

Sorry for being a little uninformed regarding the complexities.

but what is the function of “key”,“operand” and then you have a second key object ?

what is find operand and replace operand ? I also cannot find good documentation regarding the vocabulary being used.

The python code does make sense to me, so that is some progress I suppose.

0 Likes

#4

The context specifies circumstances in which a key binding is enabled. It is built of various operations, which all neet to evaluate to true. Operations consist of key, operator and operand where key is the queried “variable”.

I just use them to keep the related panels open and just switch focus with the same key binding, which opens a panel.

Documentation can be found at https://www.sublimetext.com/docs/key_bindings.html

A list of possible values may be found in ST’s default key bindings settings file.

2 Likes