Sublime Forum

Dev Build 3154

#55

Nearly all packages requiring some input or at least those providing extra quick panels to list values can and should use it. I already thought about using that for my Skins package and change the Theme-Menu-Switcher, too. Both are very good examples for the value the new API adds to ST.

I am pretty sure this feature will find a couple of friends in the near future as one could create a dynamically created command line with user input out of it.

0 Likes

#56

You are correct, if the size is changing very often could be bad, like expanding and shrinking. But this could be solved by not shrinking it, after expanding, so when I enter on Arithmetic mode, the size would not be shrinked to fit only this:

But kept on the maximum size it was required to be since it was opened. For example,

  1. When I open the command palette, its size is calculated to WIDTH as it was on build 3153.
  2. Then if I enter on some special mode which has a narrower width, its width is kept WIDTH
  3. But if the special mode requires WIDTH bigger than the original WIDTH, its width is expanded to WIDTH2
  4. If the special mode does not requires more such increased width, it width is not shrinked and is kept to WIDTH2
  5. If the special mode requires more than WIDTH2, then its with is increase to WIDTH3.
  6. If the special mode does not requires more such increased width WIDTH3, its WIDTH3 is kept.

Can you add a setting to enable dynamically increase the size without shrinking it? This setting would be disabled by default, then who do not like a standard big size can experiment with it.

0 Likes

#57

@jps, @wbond: How about using the folder_exclude_patterns in the View Package File command?

A package developer might have a couple of packages as VCS repositories installed. The list currently shows all files, even all the database files located under .git folders or .hg, … Maybe even some cache paths like .mypy_cache, … .

Using the folder_exclude_patterns could help to keep the list clean.

I also played with the file_exclude_patterns but using fnmatch slows down list creation drastically.

Here is an example of the file with global folder excludes applied:

import sublime
import sublime_plugin

class ResourceNameInputHandler(sublime_plugin.ListInputHandler):
    def name(self):
        return "name"

    def placeholder(self):
        return "Name"

    def list_items(self):
        settings = sublime.load_settings("Preferences.sublime-settings")
        folder_exclude = [f + '/' for f in settings.get("folder_exclude_patterns", [])]
        file_exclude = settings.get("file_exclude_patterns", [])

        items = []
        for f in sublime.find_resources(''):
            if f.startswith("Packages/") and not any(fe in f for fe in folder_exclude):
                items.append(f[len("Packages/"):])
        return items


class ViewResourceCommand(sublime_plugin.WindowCommand):
    def run(self, name):
        self.window.run_command("open_file", {"file": "${packages}/" + name})

    def input(self, args):
        if "name" not in args:
            return ResourceNameInputHandler()
        else:
            return None

1 Like

#58

Perhaps then, the command palette size:

  1. Could always be set to 85%, when it enter on some special mode like Arithmetic, but kept its original size as on build 3153 when it is first opened.
  2. Be kept on 85% size when exiting the Arithmetic mode, to respecting the do not shrink policy.

If you think it would be bad for the user, just let the user decides the behavior by settings.

This would solve the problem of having the command palette hiding the code 100% of the times it is opened. Therefore it would only hide the code when some special mode requires wider width.

0 Likes

#59

There isn’t an arithmetic mode. The new command palette doesn’t close and reopen, but instead allows a continuous flow of command -> input*. If you play around with Arithmetic, you can see that if you backspace with no input, it removes the Arithmetic selection and returns to the command palette.

0 Likes

#60

In the default Monokai theme the result of arithmetic operation is black making it invisible.

0 Likes

Build 3154 Arithmetic Result Text Colour
#61

This is what I meant to when said when exiting the Arithmetic mode. So, after calling a command like Arithmetic and returning to the main list as you explained, the extended width of 85% would stay.

But would be better let the command palette have its original size, when returning to the main list. So the code is not hidden anymore. Therefore:

  1. The special size of 85% would only be set when entering on special modes like Arithmetic, which uses phantom.
  2. The special size of 85% would not be used for other commands which just display a list of commands.

The only thing which bothers about this big size my code being hidden behind the command palette, while its open, when there is no need to. Why hide more code while I am searching for a simple command?

About the dynamic resizing, it would be a problem while moving between list menus, like this plugin implements with multiple quick panel menus:

0 Likes

#62

Yes, and the point I am trying to make is that this is conceptually the wrong model to use when thinking about the new command palette.

There is no new “mode”, but instead the command palette stays open if a command needs input. So instead of invoking new instances of the quick panel and so forth, everything is done in the command palette proper.

It is clear that you would prefer dynamic sizing, and I understand that. I am just trying to help you (as a package developer) to understand the implementation and implications of the new command palette.

0 Likes

#63

To me, the obvious solution would be a configurable max width, like website layouts are setup. They usually have no limit on shrinking, but when growing, their width stops at around 1000-1300 pixels. For the command palette, I would set it around 900px. Or it could be an amount of characters: 80 chars wide.

Another thing:

Because from a user experience, having the width jump around and your text/input jump around feels jarring.

Shouldn’t all quick panels be the same size? When jumping between GoTo panel and the Command Palette, you jump between two widths. When invoking a command from the cmdPal that calls another quick panel, you also jump between two widths. At least it’d be consistent.

3 Likes

#65

I got this behavior as well on Windows.

Open the Command Palette with Ctrl+Shift+P, then click on the buffer somewhere, then refocus the palette with Ctrl+Shift+P, and notice that the cursor isn’t drawn anymore.

It seems the palette enters in a weird state when doing this. If you don’t click in the palette’s input area, you can’t see what you’re typing, but if you close and open it again with the keyboard shortcut, it will display the characters entered the last time it was open. At this point, I need to restart Sublime to make the palette behave as expected.

Can you reproduce this as well?

0 Likes

#66

Confirm that. It’s reproduceable on my Win 10 box. I was a bit confused when I ran into that situation this afternoon and even got ST to crash after some retries. Thank’s for clarifying what caused it.

0 Likes

#67

Why can’t I trigger sublime commands that use the new InputHandler classes with run_command?

For example, window.run_command("rename_file", {'new_name': "test.py"}) works as expected but window.run_command("rename_file") throws an error: missing 1 required positional argument: 'new_name'

window.run_command("rename_file") should open the input dialog. That would make the new API more useful.

0 Likes

#68

Thanks for patience. Now you explained, it seems pretty obvious. Indeed, I would prefer the command palette width to be resizable. Now the width is more complex then, it would be two types of widths:

  1. When the command palette contents are commands, .i.e., a list of commands. This is just usual as when showing a quick panel with a list of options for the user to choose.
  2. When the command palette is accepting user input, as when the Arithmetic command is selected. On this case, the Arithmetic command seems to be opening a html phantom attached to the command palette bottom.

I would favor the command palette to be dynamically sizable when switching between the width types 1 and 2, i.e.:

  1. When I open the command palette for the first time, its size is computed as on build 3153.
  2. When a command is accepting input from the command palette with a embed phantom, its size can be set higher as 85%.

This would define the first part of the dynamically width. However there is a second part which can be though of, which is when you are inside the step 2 (accepting input with a phantom). On this case the command palette width could be just set to a default/standard width as of 85%, or it can follow the increment width adjustment:

  1. When opening the command palette for the first time, set WIDTH accordingly to the list items.
  2. When an input phantom is open, the command palette width is kept WIDTH
  3. But if the input phantom requires a WIDTH bigger than the original WIDTH, its width is expanded to WIDTH2
  4. If the input phantom does not requires such increased width, its width is not shrinked and is kept to WIDTH2
  5. If the input phantom requires more than WIDTH2, then its with is increase to WIDTH3.
  6. … this would follow until the input phantom mode exists

Now when the command is not requiring more inputs the the command palette is back displaying the commands list, its width would be set back to WIDTH.

This solution seems to would also helps with my problem. To be more clear, I would like them on the following order:

  1. First I would like most to the dynamic width to be implemented as described at the beginning of the post
  2. Second, something implemented like described at the beginning of the post would be also nice.
  3. Third, a maximum width as proposed by @dubeg would also seem to help.
  4. Forth, write my own command palette parsing all .sublime-command files, and sadly losing this nice new feature of input phantom. Or perhaps this is also implemented for quick panels, but without this width constraint of 85% width?
0 Likes

#69

It would be great to change the text to show in the Command Palette when I invoke a command. For the ‘Rename Text’ command, it shows ‘Rename Text’, which is a great default. But many package use things like “Package Name: command name” and I would like to change that.

1 Like

#70

I also would like it. It could be something like, if a package command is called Package Name: Rename File, then it would show Renaming file when the command is selected.

It could be possible by an API addiction to allow the package to return the command name when using the new input phantom, like this bellow where the command is called display_name(), which returns Renaming file, then instead of display Package Name: Rename file, it would display Renaming file:

class RenameInputHandler(sublime_plugin.TextInputHandler):

    def __init__(self, view):
        self.view = view

   def name():
       return "new_name"

    def display_name(self):
        return "Renaming file"

    def placeholder(self):
        return "Expressions"

   ...

class PackageNameRenameFile(sublime_plugin.TextCommand):

   def run(self, edit, new_name):
      do_command_stuff(new_name)

   def is_visible(self):
      return is_this_visible()

   def input(self):
      return RenameInputHandler(self.view)
1 Like

#71

The idea is that you are creating a chain of inputs to launch a command. Note that you can also hit backspace to delete inputs and even the command. The UI is more of a “flow” than entering a separate mode, so it would strike me as odd to have the thing you previously selected change once you selected it.

1 Like

#72

I am only asking to change the initial command name so that selecting “Package Name: command name” in the command palette becomes “command name”.

More important: It would be great if we could invoke these commands in other ways then the palette. Why can’t I use a keyboard shortcut the invoke the arithmetic command { "keys": ["super+option+control+a"], "command": "arithmetic" }? Why can’t I use window.run_command("rename_file")? That would be extremely useful (and require a different way to set the command caption, I guess).

0 Likes

#73

Disable colored title bars and your issue will be fixed. Sublime Text for some reason doesn’t like them in custom themes.

Details:

https://github.com/ihodev/sublime-da-ui/issues/30

1 Like

#74

Support for multiple rows per entry in sublime_plugin.ListInputHandler

show_quick_panel supports multiple rows for each entry in the quick panel. From the API documentation: "items may be a list of strings, or a list of string lists. In the latter case, each entry in the quick panel will show multiple rows". It would be great to have the same support in sublime_plugin.ListInputHandler. I know that list_items function uses [(str,value)] for the command argument. Still I think it would be great if the two API were consistent. With the current implementation, I sometimes have to pick between a chain of inputs vs multiple rows.

0 Likes

#75

My plan is to look into this over the next day or two to figure out what is going on.

1 Like