It is great to have io_panel
,can the associated inputbox have the abilities of input_panel
. For example, can I bind a on_change
method to the inputbox in addition to on_input
.
Version 4200, io_panel with on_change method
weiwang2021
#1
0 Likes
deathaxe
#2
create_io_panel()
returns two ordinary sublime.View
instances both of which ordinary sublime_plugin.EventListener
classes can be created for to handle all sorts of events.
As view.element()
returns None
for io panels’ input_views, a view specific setting (e.g. is_input_widget
) may be required to identify input panel and handle specific events.
Here’s a minimal example with auto completion enabled.
from __future__ import annotations
import sublime
import sublime_plugin
class CreateIoPanel(sublime_plugin.WindowCommand):
def run(self):
self.out_view, self.input_view = self.window.create_io_panel("my_panel", on_input=self.on_input)
# configure output view
settings = self.out_view.settings()
settings.set("gutter", False)
# configure input view
settings = self.input_view.settings()
settings.set("is_input_widget", True)
settings.set("auto_complete", True)
settings.set("auto_complete_disabled", False)
settings.set("auto_complete_selector", "source, text")
def on_input(self, input):
self.out_view.run_command("insert", {"characters": input + "\n"})
class IoPanelEventListener(sublime_plugin.EventListener):
def on_modified(self, view: sublime.View):
# only handle input_widget events
if not view.settings().get("is_input_widget"):
return
print(f"View {view} changed")
def on_query_completions(self, view: sublime.View, prefix: str, locations: list[sublime.Point]):
# only handle input_widget events
if not view.settings().get("is_input_widget"):
return
print(f"View {view} changed")
0 Likes