#Issue:
I have a plugin that was crashing when hotkey commands were executed while a panel was focused.
EG: find
, console
, quick panel
, etc.
In order to resolve the issue, I had to figure out a way to differentiate between focused panels & active views.
This method works, but will also disable the plugin for unsaved views:
fileName = self.view.file_name()
if not fileName:
return
This method works, and will also function on unsaved views IF they have a non-Plain Text
syntax:
fileName = self.view.file_name()
viewSyntax = self.view.settings().get ( "syntax" )
plainText_Syntax = "Packages/Text/Plain text.tmLanguage"
if not fileName \
and viewSyntax == plainText_Syntax:
return
Is there a better way to avoid executing a command at a focused panel, that will also include unsaved documents with a Plain Text
syntax?
#Attempted Solutions:
These are the other things I’ve tried, which aside from the above examples, proved to be unhelpful:
window.active_panel()
active_panel is not a valid solution because it only establishes that a panel is visible.
It does include information as to whether or not the panel has focus.
KEYS = [ file | file_base_name | file_extension | file_name | file_path | folder | packages | platform | project | project_base_name | project_extension | project_name | project_path ]
window().extract_variables()[ "KEY" ]
KEYS = [ em_width | encoding | file_name | id | line_height | name | scope_name(point) | syntax | viewport_position | visible_region ]
view.settings().get( "KEY" )
Most of these variables & settings will return the same values for focused panels & unsaved views.