Sublime Forum

Help with toggling non-boolean setting using keybind

#1

Hey there, I’m wanting to have a key bind to toggle open_files_in_new_window between never and always

Here’s what I’ve got in my keybind settings

{
    "keys": ["f8"], 
    "command": "set_user_setting", 
    "args": {
        "file": "Preferences.sublime-settings",
        "setting": "open_files_in_new_window",
        "value": "never"
    },
    "context" :
    [
        {
            "key": "setting.open_files_in_new_window",
            "operator": "regex_match",
            "operand": "always"
        },
    ]
},
{
    "keys": ["f8"], 
    "command": "set_user_setting", 
    "args": {
        "file": "Preferences.sublime-settings",
        "setting": "open_files_in_new_window",
        "value": "always"
    },
    "context" :
    [
        {
            "key": "setting.open_files_in_new_window",
            "operator": "regex_match",
            "operand": "never"
        },
    ]
}

If I remove the context and keep one, it works to change the setting, but I want one button to toggle it. What’s not working here?

0 Likes

#2

I suspect the context resolution logic for setting. keys only supports equal/not_equal operators and boolean operands. There is a plugin implementing an extended version you could try instead of set_user_setting:

0 Likes

#3

No that’s no true, because if I use the keybind setting without the context, it works:

{
    "keys": ["f8"], 
    "command": "set_user_setting", 
    "args": {
        "file": "Preferences.sublime-settings",
        "setting": "open_files_in_new_window",
        "value": "never" <-- swap this between "always" and "never" and works it both ways 
    }
}

However, considering all I’m needing is a toggle, the extension you listed is actually a perfect alternative, cheers!

0 Likes