randy3k / Terminus

Bring a real terminal to Sublime Text
https://packagecontrol.io/packages/Terminus
MIT License
1.38k stars 84 forks source link

Key binding to move the cursor between the Sublime Text file tab/Panel and the Terminus Panel #302

Open iago-pssjd opened 2 years ago

iago-pssjd commented 2 years ago

Is there a key binding (or a way to define a key binding) such that it places the cursor in Terminus console when it was in file in Sublime Text and reciprocally? (like Ctrl+1, Ctrl+2 in RStudio)

I tried Ctrl+k and Ctrl+p but they do not work. (I use Sublime Text 4 on Debian 10).

Thanks!

randy3k commented 2 years ago

Check the setting preserved_keys. Oh, I misunderstood your question.

iago-pssjd commented 2 years ago

Let me know if I am not clear enough. I would like to jump between panes with keyboard. (I was going to ask you where should I found preserved_keys, because it does not appear to me on Terminus > Settings). Thanks

randy3k commented 2 years ago

By the way, it should be preserve_keys. https://github.com/randy3k/Terminus/blob/master/Terminus.sublime-settings#L97

iago-pssjd commented 2 years ago

Ok!, found, but I do not understand yet what should I do. As I told above, ctrl+k, ctrl+p do not work. Ctrl+k on file remove lines, ctrl+p opens a dialog and ctrl+p on terminus seems to navigate through terminal history.

iago-pssjd commented 2 years ago

I realized now about the toggle terminal panel key binding. Well, I expected the cursor-switching behaviour without hiding the terminal (does it exist?), but otherwise, it is ok!

willrowe commented 2 years ago

I wanted to do something similar and ended up just added a Python file to the Packages/User directory:

import re
import sublime_plugin

class TogglePanelFocus(sublime_plugin.WindowCommand):
    TARGET_TYPE_PANEL = 'panel'
    TARGET_TYPE_VIEW = 'view'

    def is_enabled(self):
        return (
            self.window.active_view() is not None
                and
            self.window.active_panel() is not None
        )

    def run(self, target_type):
        if target_type == self.TARGET_TYPE_VIEW:
            target_view = self.window.active_view()
        elif target_type == self.TARGET_TYPE_PANEL:
            active_panel = self.window.active_panel()
            target_view = self.window.find_output_panel(re.sub(r'^output\.', '', active_panel))
            self.window.run_command('show_panel', {'panel': active_panel})

        self.window.focus_view(target_view)

This is more general, so it has the added benefit of working on all panels, not just Terminus. I then added my preferred keybindings:

[
    {
        "args": {
            "target_type": "view"
        },
        "command": "toggle_panel_focus",
        "context": [
            {
                "key": "panel_has_focus",
                "operand": true,
                "operator": "equal"
            }
        ],
        "keys": [
            "super+t",
            "super+f"
        ]
    },
    {
        "args": {
            "target_type": "panel"
        },
        "command": "toggle_panel_focus",
        "context": [
            {
                "key": "panel_has_focus",
                "operand": false,
                "operator": "equal"
            }
        ],
        "keys": [
            "super+t",
            "super+f"
        ]
    }
]
highandmighty commented 8 months ago

Seems that possibility of defining such a key binding depends on behaviour of toggle_terminus_panel command. If the issue #391 will be resolved, moving focus between editor and Terminus panel will be possible with it natively without need of custom Python plugin.

flansch commented 5 months ago

As #391 has been resolved in the meantime I am able to use Ctrl+Shift+T to switch focus to an already open Terminus panel and Ctrl+1 to go back to the code editor.

To make this working I had to upgrade the Terminus package.