Sublime Forum

Multiple items selection in command palette

#1

this seemed simple af

i got an example https://github.com/sublimetext-io/docs.sublimetext.io/blob/master/docs/guide/extensibility/plugins/input_handlers/code/insert_html_entity.py
i just want to select multiple items from Command Palette (in this example case , html tags)
however, did not achieved it yet. after many tries. :thinking:
:question: some slight adjustments needed to my script.

here is my script


from html.entities import html5
import sublime
import sublime_plugin

class InsertHtmlEntityCommand(sublime_plugin.TextCommand):
    def run(self, edit, entity):
        if isinstance(entity, str):
            entities = [entity]
        else:
            entities = entity
            
        for region in self.view.sel():
            tags = ''.join([f"&{e};" for e in entities]) 
            self.view.replace(edit, region, tags)

    def input(self, args):
        return EntityInputHandler()


class EntityInputHandler(sublime_plugin.ListInputHandler):
    def want_event(self):
        return True

    def list_items(self):
        items = []
        for key in sorted(html5.keys()):
            item = sublime.ListInputItem(
                text=key,
                value=key,
                details=f"Character: {html5.get(key)}",
                annotation=html5.get(key)
            )
            items.append(item)
        return items

    #def confirm(self, value):
    #    return value

    def preview(self, value):
        if isinstance(value, list):
            return "Characters: " + ", ".join(html5.get(v) for v in value)
        return "Character: {}".format(html5.get(value))
0 Likes