diff --git a/docs/changelog.rst b/docs/changelog.rst index 881d49ff5..d678463e4 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -67,6 +67,8 @@ Detailed list of changes - A new action :ac:`scroll_prompt_to_top` to move the current prompt to the top (:pull:`4891`) +- :ac:`select_tab`: Use stable numbers when selecting the tab (:iss:`4792`) + 0.24.4 [2022-03-03] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/kitty/boss.py b/kitty/boss.py index b3cfa5c6d..09a940aac 100644 --- a/kitty/boss.py +++ b/kitty/boss.py @@ -2135,16 +2135,16 @@ class Boss: callback: Callable[[Union[_T, str, None]], None], subtitle: str = '' ) -> Optional[Window]: - lines = [title, subtitle, ''] if subtitle else [title, ''] - idx_map: List[Union[_T, str]] = [] + lines = [title, subtitle, ' '] if subtitle else [title, ' '] + idx_map: List[Union[_T, str, None]] = [] ans: Union[str, _T, None] = None fmt = ': {1}' for obj, text in entries: + idx_map.append(obj) if obj is None: lines.append(text) else: - idx_map.append(obj) lines.append(fmt.format(len(idx_map), text)) def done(data: Dict[str, Any], target_window_id: int, self: Boss) -> None: @@ -2157,7 +2157,7 @@ class Boss: q = self._run_kitten( 'hints', args=( '--ascending', '--customize-processing=::import::kitty.choose_entry', - r'--regex=(?m)^:\s+.+$', '--window-title', title, + '--window-title', title, ), input_data='\r\n'.join(lines).encode('utf-8'), custom_callback=done, action_on_removal=done2 ) return q if isinstance(q, Window) else None @@ -2176,13 +2176,10 @@ class Boss: return f'{tab.name or tab.title} [{tab.num_window_groups} {w}]' ct = self.active_tab - st = '' - if ct is not None: - st = f'Current tab: {format_tab_title(ct)}' self.choose_entry( 'Choose a tab to switch to', - ((t.id, format_tab_title(t)) for t in self.all_tabs if t is not ct), - chosen, subtitle=st + ((None, f'Current tab: {format_tab_title(t)}') if t is ct else (t.id, format_tab_title(t)) for t in self.all_tabs), + chosen ) @ac('win', ''' diff --git a/kitty/choose_entry.py b/kitty/choose_entry.py index c575461a3..4fc321ff5 100644 --- a/kitty/choose_entry.py +++ b/kitty/choose_entry.py @@ -10,7 +10,17 @@ from .typing import MarkType def mark(text: str, args: HintsCLIOptions, Mark: Type[MarkType], extra_cli_args: List[str], *a: Any) -> Generator[MarkType, None, None]: - for idx, m in enumerate(re.finditer(args.regex, text)): + idx = 0 + found_start_line = False + for m in re.finditer(r'(?m)^.+$', text): start, end = m.span() - mark_text = text[start:end].replace('\n', '').replace('\0', '') - yield Mark(idx, start, end, mark_text, {'index': idx}) + line = text[start:end].replace('\0', '').replace('\n', '') + if line == ' ': + found_start_line = True + continue + if line.startswith(': '): + yield Mark(idx, start, end, line, {'index': idx}) + idx += 1 + elif found_start_line: + # skip this line incrementing the index + idx += 1