Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial selection doesn't work for ListInputHandler #6175

Closed
jwortmann opened this issue Oct 25, 2023 · 1 comment
Closed

Initial selection doesn't work for ListInputHandler #6175

jwortmann opened this issue Oct 25, 2023 · 1 comment
Assignees
Labels
Milestone

Comments

@jwortmann
Copy link

Description of the bug

There was the initial_selection method introduced in ST 4081 for the CommandInputHandler API, but it doesn't work for ListInputHandlers. For an easy fix see below.


Now after writing this, I see that there already is a similar issue report for TextInputHandler at #5972.

But I'll open this regardless, providing more information about the cause and with the hope that it will quickly be fixed with the solution below.

Steps to reproduce

  1. Start ST in safe mode.
  2. Create a plugin, either in the User package or in a separate package:
import sublime_plugin

class InputHandlerTestCommand(sublime_plugin.WindowCommand):

    def run(self, arg1):
        pass

    def input(self, args):
        if 'arg1' not in args:
            return MyListInputHandler()

class MyListInputHandler(sublime_plugin.ListInputHandler):

    def list_items(self):
        return ['first item', 'second item', 'third item']

    def initial_text(self):
        return 'item'

    def initial_selection(self):
        return [(0, 2)]

add the command to the command palette, and run it:

[
    { "caption": "Input Handler Test", "command": "input_handler_test" },
]

Expected behavior

Only first two letters are selected.

Actual behavior

The whole input text is selected.

Sublime Text build number

4152

Operating system & version

Windows 11

(Linux) Desktop environment and/or window manager

No response

Additional information

It seems the reason is that in the Python 3.8 environment in sublime_plugin.py it was only implemented in TextInputHandler.setup_, but not in ListInputHandler.setup_.

It's easy to fix it manually, and I can confirm that it works as expected then (ST4152):

--- C:\Program Files\Sublime Text\Lib\python38\sublime_plugin.py
+++ C:\Program Files\Sublime Text\Lib\python38\sublime_plugin.py
@@ -1432,6 +1432,7 @@
 
         props = {
             "initial_text": self.initial_text(),
+            "initial_selection": self.initial_selection(),
             "placeholder_text": self.placeholder(),
             "selected": selected_item_index,
             "type": "list",

For the Python 3.3 API environment the initial_selection method is even missing in the CommandInputHandler class, but if you add it works fine as well:

--- C:\Program Files\Sublime Text\Lib\python33\sublime_plugin.py
+++ C:\Program Files\Sublime Text\Lib\python33\sublime_plugin.py
@@ -1182,6 +1182,9 @@
     def initial_text(self):
         return ""
 
+    def initial_selection(self):
+        return []
+
     def preview(self, arg):
         return ""
 
@@ -1237,6 +1240,7 @@
     def setup_(self, args):
         props = {
             "initial_text": self.initial_text(),
+            "initial_selection": self.initial_selection(),
             "placeholder_text": self.placeholder(),
             "type": "text",
         }
@@ -1295,6 +1299,7 @@
 
         props = {
             "initial_text": self.initial_text(),
+            "initial_selection": self.initial_selection(),
             "placeholder_text": self.placeholder(),
             "selected": selected_item_index,
             "type": "list",

OpenGL context information

No response

@BenjaminSchaaf
Copy link
Member

Fixed in build 4161.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants