python-black icon indicating copy to clipboard operation
python-black copied to clipboard

IndexError in is_visible() when view has no selection

Open dpc00 opened this issue 6 months ago • 1 comments

Bug

When Sublime Text opens certain views (output panels, quick panels, or views before any cursor is set), sel() returns an empty selection. BlackCommand.is_visible() calls self.view.sel()[0] unconditionally, which raises an IndexError that surfaces as a traceback in the ST console.

Traceback

Traceback (most recent call last):
  File "sublime_plugin.py", in run_
    return self.run(**args)
  File "commands.py", in is_visible
    region = self.view.sel()[0]
IndexError: list index out of range

Fix

Guard against an empty selection before indexing:

def is_visible(self, *args):
    if not self.view.sel():
        return False
    region = self.view.sel()[0]
    return self.view.match_selector(region.b, "source.python")

Environment

  • python-black 1.2.10
  • Sublime Text 4200, Windows x64

dpc00 avatar May 28 '26 16:05 dpc00

I haven't used the Sublime Text editor for many years, so I no longer maintain this plugin. You can fix this bug by submitting a pull request.

thep0y avatar May 29 '26 03:05 thep0y

I only use ST constantly because PyCharm is too hard, but it does have compelling debugger. I work now on sublime-MCP and replacement for Terminus "GhostShell" with better features. Running Claude in one tab and OMP in another, and another claude in Windows Terminal. Logging to text and asciicast so claude cannot forget anything. You say I can file a PR but I don't know about those things enough.

dpc00 avatar Sep 15 '26 00:09 dpc00