Merge branch 'hints-add-trailing-space' of https://github.com/maximbaz/kitty

This commit is contained in:
Kovid Goyal 2018-11-11 11:03:11 +05:30
commit 34aea3bca1
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 21 additions and 2 deletions

View File

@ -29,6 +29,10 @@ Changelog
- icat kitten: Implement reading image data from STDIN, if STDIN is not
connected to a terminal (:iss:`1130`)
- hints kitten: Insert trailing spaces after matches when using the
``--multiple`` option. Also add a separate ``--add-traling-space``
option to control this behavior (:pull:`1132`)
- Fix the ``*_with_cwd`` actions using the cwd of the overlay window rather
than the underlying window's cwd (:iss:`1045`)

View File

@ -84,9 +84,17 @@ class Hints(Handler):
self.args = args
self.window_title = _('Choose URL') if args.type == 'url' else _('Choose text')
self.multiple = args.multiple
self.match_suffix = self.get_match_suffix(args)
self.chosen = []
self.reset()
def get_match_suffix(self, args):
if args.add_trailing_space == 'always':
return ' '
if args.add_trailing_space == 'never':
return ''
return ' ' if args.multiple else ''
def reset(self):
self.current_input = ''
self.current_text = None
@ -112,7 +120,7 @@ class Hints(Handler):
if encode_hint(idx).startswith(self.current_input)
]
if len(matches) == 1:
self.chosen.append(matches[0].text)
self.chosen.append(matches[0].text + self.match_suffix)
if self.multiple:
self.ignore_mark_indices.add(matches[0].index)
self.reset()
@ -130,7 +138,7 @@ class Hints(Handler):
elif key_event is enter_key and self.current_input:
try:
idx = decode_hint(self.current_input)
self.chosen.append(self.index_map[idx].text)
self.chosen.append(self.index_map[idx].text + self.match_suffix)
self.ignore_mark_indices.add(idx)
except Exception:
self.current_input = ''
@ -363,6 +371,13 @@ The minimum number of characters to consider a match.
type=bool-set
Select multiple matches and perform the action on all of them together at the end.
In this mode, press :kbd:`Esc` to finish selecting.
--add-trailing-space
default=auto
choices=auto,always,never
Add trailing space after matched text. Defaults to auto, which adds the space
when used together with --multiple.
'''.format(','.join(sorted(URL_PREFIXES))).format
help_text = 'Select text from the screen using the keyboard. Defaults to searching for URLs.'
usage = ''