Sublime Forum

ST3 API: view.sel() changes work intermittently for newly opened files

#1

Hi,

I’m writing a “Goto Usage” plugin (opposite of Goto Definition).

When invoked the plugin pops up a list of “usages” of a given class/function/var using window.show_quick_panel and highlighting any of them opens the file, scrolls to the “usage” and selects it.

During the first 500ms or so after the file gets opened it works, after that highilighting items in the quick panel simply scrolls the view but the selection doesn’t change!?

Here’s a gif of the problem. It pops up the quick panel and moving up and down in it, it scrolls to the correct place and for the first 3 times it also selects one or the other “usage” but at some point it doesn’t anymore:


(note the text background and the highlighted line number)

I’m opening the quick panel here: https://github.com/syko/SublimeGotoUsage/blob/master/GotoUsage.py#L57

Upon highlighting core.open_usage gets called: https://github.com/syko/SublimeGotoUsage/blob/master/core.py#L367

There I open the file and add a callback to stack that gets executed upon opening the file (this feels like a hack, if there’s a better way to do this, I’m all ears).

Anyway, in the final show_usage function I’m simply doing:
sel = view.sel() sel.clear() sel.add(select and usage['region'] or usage['region'].a)

Could this be a bug in ST3?

1 Like

#2

You might find that you are encountering this bug: https://github.com/SublimeTextIssues/Core/issues/485

I find that updating the selection from a quick panel isn’t reliable, I have to use the workaround mentioned in the OP in that issue.

2 Likes

#3

Indeed that looks like it’s the same issue. I’ll see if the workaround does the trick.

Thanks :+1:

0 Likes