Sublime Forum

Show_quick_panel Input box explicit default string

#1

Sublime show_quick_panel how to default explicit string in the input box, used to distinguish different filter boxes, thanks

0 Likes

#2

Not sure what this mean ? Do you want to have a default string in the input widget when you open the quick panel ?

0 Likes

#3

The red box explicitly specifies the string by default, indicating the currently filtered content of the drop-down box

0 Likes

#4

Alright. The show_overlay command (that is used by the default keybindings for showing the goto panels & command palette) has a text argument you can use for that purpose. Here is a keybinding example, but you can just as easily use it in a plugin.

{
	"keys": ["ctrl+alt+w"],
	"command": "show_overlay",
	"args": {
		"overlay": "goto", // use command_palette if you want it in command palette.
		"text": "some_text", // some_text will appear in the red box when you press ctrl + alt + w.
	},
},

Replace some_text with what you want pre populated in the red box you have indicated (It’s technically called a widget view)

0 Likes

#5

thank!:kiss_smiling_eyes:

0 Likes

#6

Hello, how do you code it?

0 Likes

#7

How show_overlay macro calls custom commands

0 Likes

#8

Ok. Looking at your code, the show_overlay is not what is wanted. You need to follow a different approach.

Here is a short plugin that puts text in a custom quick panel widget view created via a plugin.

import sublime
import sublime_plugin

class ShowTextInPanelCommand(sublime_plugin.WindowCommand):

	def run(self):
		some_list = ["This is item 1", "This is item 2", "This is item 3"]
		self.window.show_quick_panel(some_list, on_select=lambda id: self.on_done(id, some_list))
                # This is where we put text in the widget view.
		self.window.run_command("append", {
			"characters": "item"
		})

	def on_done(self, id, some_list):
		if id >= 0:
			print(some_list[id])

Currently, I don’t know how to shift the cursor to the end of the word in the panel (because for some reason, I am unable to grab hold of the view object representing the command palette input widget view)

So in your code, adding

self.now_windows.run_command("append", { "characters": "some_text" })

after the show_quick_panel call should do it.

0 Likes

#9

Thank you! Very easy to use, I wish you a happy life!

0 Likes

#10

You can add in an additional command for that:

self.window.run_command("move_to", {"to": "eol"})

As a side note, the code above isn’t valid Python because it’s using C-style comments.

0 Likes

#11

Thanks for the tip and the heads up about the comment. Side effect from writing too much JavaScript lately :slightly_smiling_face:

1 Like

#12

Thanks for guidance!

0 Likes