Skip to content

Commit

Permalink
Don’t do anything if there is no selection region
Browse files Browse the repository at this point in the history
On some occasions (on startup and on executing some commands such as `lsp_document_symbols` which in turn executes `lsp_selection_clear`), the `show_unicode` function might be executed with an empty selection set (i.e. not even one empty region). Previously the function would try to call `view.sel()[0]`, which would generate an IndexError in that case.
  • Loading branch information
sylbru authored Apr 21, 2021
1 parent 209a840 commit 3edd56b
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions show_unicode_name.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,13 @@ def on_activated(self, view):
self.show_unicode(view)

def show_unicode(self, view):
selected = view.substr(view.sel()[0].a)
view.set_status('a-ned-unicode', "U+{0:0>4X} #{0} {1}".format(ord(selected), unicodedata.name(selected, selected.encode('unicode_escape').decode('utf-8')).title()))
regions = view.sel()
if len(regions) > 0:
selected = view.substr(regions[0].a)
view.set_status(
'a-ned-unicode',
"U+{0:0>4X} #{0} {1}".format(
ord(selected),
unicodedata.name(selected, selected.encode('unicode_escape').decode('utf-8')).title()
)
)

0 comments on commit 3edd56b

Please sign in to comment.