Sublime-Text-2-Stackoverflow-Plugin icon indicating copy to clipboard operation
Sublime-Text-2-Stackoverflow-Plugin copied to clipboard

Search Selection with nothing selected searches for an empty string

Open dpc00 opened this issue 1 month ago • 1 comments

Claude reports: with nothing selected, "Stackoverflow: Search Selection" searches for an empty string instead of the word under the cursor.

In StackoverflowSearchSelectionCommand.run:

if selection.empty():
    text = self.view.word(selection)

text = self.view.substr(selection)

The second assignment runs unconditionally and overwrites text with the text of the empty selection, so SearchFor('') is called. (It is also a Region, not a string, in the first branch.) Test: Sublime Text build 4200, typed enumerate in a new tab, cursor at the end, ran the command: the default browser opened a Stack Overflow page. I could not read the URL (the page showed a human-verification check), so the empty q= is from reading the code, not from seeing the address.

Fix: text = self.view.substr(self.view.word(selection)) in the empty case, else: text = self.view.substr(selection).

dpc00 avatar Oct 19 '26 23:10 dpc00

Claude reports: confirmed. After the human-verification page was passed, the browser tab opened by the command was titled "Posts matching '' - Stack Overflow", i.e. the search was for an empty string (typed word enumerate, cursor at its end, nothing selected).

dpc00 avatar Oct 19 '26 23:10 dpc00