Sublime Forum

Feature Request: Plugins access quickpanel text

#1

Id like to request that plugins have access to the text someone inputs into the quickpanel. Im specifically interested in addressing this issue:

but in general, it seems like a natural feature for plugins to have (unless Im missing something)

1 Like

How to map ctrl+m as enter, in command palette
#2

a quickpanel textbox is a view widget and is accessible via plugins, though the API doesn’t make it as easy as it could… maybe I will put together a poof of concept when I get time

0 Likes

#3

Thanks @kingkeith!

1 Like

#4

It’s pretty ugly, using global variables, because ST doesn’t seem to offer an easy way to tie a TextCommand in with an EventListener:

import sublime
import sublime_plugin


def get_view_content(view_id):
    view = sublime.View(view_id)
    return view.substr(sublime.Region(0, view.size()))

quick_panel_view_id = 0
capture_quick_panel = False
last_known_quick_panel_text = ''

class ExampleQuickPanelCommand(sublime_plugin.TextCommand):
    def run(self, edit):
        global capture_quick_panel
        capture_quick_panel = True
        show_text = lambda index: sublime.message_dialog(get_view_content(quick_panel_view_id) or last_known_quick_panel_text)
        self.view.window().show_quick_panel(['item1', 'item2'], show_text)

class ExampleQuickPanelListener(sublime_plugin.EventListener):
    def on_activated(self, view):
        global capture_quick_panel
        global quick_panel_view_id
        if capture_quick_panel:
            quick_panel_view_id = view.id()
            capture_quick_panel = False
    def on_deactivated(self, view):
        if view.id() == quick_panel_view_id:
            global last_known_quick_panel_text
            last_known_quick_panel_text = get_view_content(quick_panel_view_id)

5 Likes

#5

Sadly it’s not possible hide it when you press enter, only when focus changed

0 Likes