From a57e96500a947437f55f7db6de66854e2297cac7 Mon Sep 17 00:00:00 2001 From: Maxim Baz Date: Sat, 10 Nov 2018 13:19:40 +0100 Subject: [PATCH] hints: optionally add trailing space --- kittens/hints/main.py | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/kittens/hints/main.py b/kittens/hints/main.py index 7c60cecbd..50c66126b 100644 --- a/kittens/hints/main.py +++ b/kittens/hints/main.py @@ -84,9 +84,19 @@ 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 '' + if args.multiple and args.program == '-': + return ' ' + return '' + def reset(self): self.current_input = '' self.current_text = None @@ -112,7 +122,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 +140,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 +373,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 and pasting match into the terminal window. '''.format(','.join(sorted(URL_PREFIXES))).format help_text = 'Select text from the screen using the keyboard. Defaults to searching for URLs.' usage = ''