diff --git a/docs/changelog.rst b/docs/changelog.rst index a1036f708..2ae02556b 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -22,6 +22,9 @@ To update |kitty|, :doc:`follow the instructions `. - Linux: Fix rendering of emoji followed by the graphics variation selector not being colored with some fonts (:iss:`3211`) +- Unicode input: Fix using index in select by name mode not working for indices + larger than 16. Also using an index does not filter the list of matches. (:pull:`3219`) + 0.19.3 [2020-12-19] ------------------- diff --git a/kittens/unicode_input/main.py b/kittens/unicode_input/main.py index 6cf6ea116..e6a48779a 100644 --- a/kittens/unicode_input/main.py +++ b/kittens/unicode_input/main.py @@ -1,7 +1,6 @@ #!/usr/bin/env python3 # vim:fileencoding=utf-8 # License: GPL v3 Copyright: 2018, Kovid Goyal - import os import string import subprocess @@ -49,6 +48,7 @@ F4 = K['F4'] F12 = K['F12'] favorites_path = os.path.join(config_dir, 'unicode-input-favorites.conf') INDEX_CHAR = '.' +INDEX_BASE = 36 DEFAULT_SET = tuple(map( ord, '‘’“”‹›«»‚„' '😀😛😇😈😉😍😎😮👍👎' '—–§¶†‡©®™' '→⇒•·°±−×÷¼½½¾' @@ -152,7 +152,7 @@ def encode_hint(num: int, digits: str = string.digits + string.ascii_lowercase) def decode_hint(x: str) -> int: - return int(x, 36) + return int(x, INDEX_BASE) class Table: @@ -172,11 +172,11 @@ class Table: if self.codepoints: return self.codepoints[self.current_idx] - def set_codepoints(self, codepoints: List[int], mode: str = HEX) -> None: + def set_codepoints(self, codepoints: List[int], mode: str = HEX, current_idx: int = 0) -> None: self.codepoints = codepoints self.mode = mode self.layout_dirty = True - self.current_idx = 0 + self.current_idx = current_idx if current_idx < len(codepoints) else 0 def codepoint_at_hint(self, hint: str) -> int: return self.codepoints[decode_hint(hint)] @@ -270,8 +270,10 @@ class Table: def is_index(w: str) -> bool: + if w[0] != INDEX_CHAR: + return False try: - int(w.lstrip(INDEX_CHAR), 16) + int(w.lstrip(INDEX_CHAR), INDEX_BASE) return True except Exception: return False @@ -306,6 +308,7 @@ class UnicodeInput(Handler): def update_codepoints(self) -> None: codepoints = None + iindex_word = 0 if self.mode is HEX: q: Tuple[str, Optional[Union[str, Sequence[int]]]] = (self.mode, None) codepoints = self.recent @@ -324,14 +327,11 @@ class UnicodeInput(Handler): if index_words: index_word = words[index_words[0]] words = words[:index_words[0]] + iindex_word = int(index_word.lstrip(INDEX_CHAR), INDEX_BASE) codepoints = codepoints_matching_search(tuple(words)) - if index_words: - iindex_word = int(index_word.lstrip(INDEX_CHAR), 16) - if codepoints and iindex_word < len(codepoints): - codepoints = [codepoints[iindex_word]] if q != self.last_updated_code_point_at: self.last_updated_code_point_at = q - self.table.set_codepoints(codepoints or [], self.mode) + self.table.set_codepoints(codepoints or [], self.mode, iindex_word) def update_current_char(self) -> None: self.update_codepoints()