Repository: kovidgoyal/kitty

Issue:
Indices for name section of unicode input use incorrect base
**Describe the bug**
When selecting a result by index using the `.<number>` notation in the Name tab of the unicode input kitten, the results are indexed in base 36, but your input is decoded as base 16. 

**To Reproduce**
Steps to reproduce the behavior:
1. Open Unicode Input
2. Switch to name tab (F2)
3. type in 'musical note .18'
4. The 24th symbol in the results is returned, which has index `o`
![image](https://user-images.githubusercontent.com/1489052/103831562-f0eb9780-5041-11eb-9a91-9561f8983021.png)
![image](https://user-images.githubusercontent.com/1489052/103831568-f5b04b80-5041-11eb-94ba-f11256583a9f.png)

**Expected behavior**
I would expect the musical note emoji to be selected, as visually it has index 18.
![image](https://user-images.githubusercontent.com/1489052/103831545-ea5d2000-5041-11eb-80c2-2701e923d02a.png)


**Screenshots**
I put screenshots where relevant

**Environment details**
OS: Ubuntu 20.10

```
Output of kitty --debug-config, 
tested on a clean install from source, and with config=NONE
```



Discussion:

Resolving patch:
diff --git a/kittens/unicode_input/main.py b/kittens/unicode_input/main.py
--- 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 <kovid at kovidgoyal.net>
-
 import os
 import string
 import subprocess
@@ -172,11 +171,11 @@ def current_codepoint(self) -> Optional[int]:
         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 +269,10 @@ def move_current(self, rows: int = 0, cols: int = 0) -> None:
 
 
 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), 36)
         return True
     except Exception:
         return False
@@ -306,6 +307,7 @@ def resolved_current_char(self) -> Optional[str]:
 
     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 +326,11 @@ def update_codepoints(self) -> None:
                 if index_words:
                     index_word = words[index_words[0]]
                     words = words[:index_words[0]]
+                    iindex_word = int(index_word.lstrip(INDEX_CHAR), 36)
                 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()


Test patch: