Skip to content

Instantly share code, notes, and snippets.

@mattst
Last active November 12, 2016 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattst/1a7a194a76dd8e4f34b86cd3c3ff048c to your computer and use it in GitHub Desktop.
Save mattst/1a7a194a76dd8e4f34b86cd3c3ff048c to your computer and use it in GitHub Desktop.
ST plugin to try to reproduce r-stein quick panel bug
# { "keys": ["ctrl+whatever"], "command": "example" },
# { "keys": ["ctrl+whatever"], "command": "example_two" }
import sublime, sublime_plugin
# *********************
# WindowCommand Version
# *********************
class ExampleCommand(sublime_plugin.WindowCommand):
def run(self):
self.items = ["a", "b", "c"]
self.window.show_quick_panel(self.items,
self.on_done,
sublime.KEEP_OPEN_ON_FOCUS_LOST)
def on_done(self, index):
if index == -1:
msg = "You cancelled the quick panel"
else:
msg = "You selected: %s" % self.items[index]
sublime.status_message(msg)
class ExampleTwoCommand(sublime_plugin.WindowCommand):
def run(self):
self.items = ["d", "e", "f"]
self.window.show_quick_panel(self.items,
self.on_done,
sublime.KEEP_OPEN_ON_FOCUS_LOST)
def on_done(self, index):
if index == -1:
msg = "You cancelled the quick panel"
else:
msg = "You selected: %s" % self.items[index]
sublime.status_message(msg)
# **************************
# ApplicationCommand Version
# **************************
# class ExampleCommand(sublime_plugin.ApplicationCommand):
# def run(self):
# self.items = ["a", "b", "c"]
# window = sublime.active_window()
# window.show_quick_panel(self.items,
# self.on_done,
# sublime.KEEP_OPEN_ON_FOCUS_LOST)
# def on_done(self, index):
# if index == -1:
# msg = "You cancelled the quick panel"
# else:
# msg = "You selected: %s" % self.items[index]
# sublime.status_message(msg)
# class ExampleTwoCommand(sublime_plugin.ApplicationCommand):
# def run(self):
# self.items = ["d", "e", "f"]
# window = sublime.active_window()
# window.show_quick_panel(self.items,
# self.on_done,
# sublime.KEEP_OPEN_ON_FOCUS_LOST)
# def on_done(self, index):
# if index == -1:
# msg = "You cancelled the quick panel"
# else:
# msg = "You selected: %s" % self.items[index]
# sublime.status_message(msg)
@r-stein
Copy link

r-stein commented Nov 12, 2016

An error example would be opened twice in the same window:

import random

import sublime
import sublime_plugin


class ExampleQuickpanelCommand(sublime_plugin.WindowCommand):
    def selected(self, index):
        if index == -1:
            return
        item = self.items[index]
        sublime.message_dialog("You selected {0}.".format(item))

    def run(self):
        self.items = [
            str(int(random.random() * 20)) for x in range(5)
        ]
        self.window.show_quick_panel(
            self.items,
            self.selected,
            flags=sublime.KEEP_OPEN_ON_FOCUS_LOST
        )

The behavior:

wrong_result_example

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment