Sublime Forum

Show_popup_menu selects last item by default


I am using view.show_popup_menu to show items, but i noticed a weird behavior that even if i not select/click on any item of the popup menu it by default selects the last item and triggers the callback.



Without seeing a code sample it is hard to say for sure, but note that the documentation for show_popup_menu mentions about the on_done callback:

Called once with the index of the selected item. If the popup was cancelled -1 is passed instead.

In Python,my_array_of_items[-1] will return the last item in the array.

Or, if you will, you need to check the index that is being passed to your callback; when it’s -1, it means the user didn’t pick anything. It sounds like you’re not doing that, which would make cancels appear to always pick the last item in the list.



damn, i read about that but totally forgot about that, yeah that totally will solve the issue.