select_tab: Use stable numbers when selecting the tab

Fixes #4792
This commit is contained in:
Kovid Goyal 2022-03-31 13:16:08 +05:30
parent 6e838b83d8
commit 30cad2e0a6
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
3 changed files with 21 additions and 12 deletions

View File

@ -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]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

View File

@ -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', '''

View File

@ -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