hints kitten: Allow copying matches to named buffers

This commit is contained in:
pagedown 2023-03-01 22:10:24 +08:00
parent bd32019b91
commit 854529c443
No known key found for this signature in database
GPG key ID: E921CF18AC8FF6EB
3 changed files with 22 additions and 3 deletions

View file

@ -65,6 +65,8 @@ Detailed list of changes
- ssh kitten: Change the syntax of glob patterns slightly to match common usage
elsewhere. Now the syntax is the same a "extendedglob" in most shells.
- hints kitten: Allow copying matches to named buffers (:disc:`6073`)
0.27.1 [2023-02-07]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

View file

@ -545,6 +545,9 @@ def run(args: HintsCLIOptions, text: str, extra_cli_args: Sequence[str] = ()) ->
:code:`*`
copy the match to the primary selection (on systems that support primary selections)
:code:`#NAME`
copy the match to the specified buffer, e.g. :code:`#a`
:code:`default`
run the default open program.
@ -746,7 +749,7 @@ def linenum_handle_result(args: List[str], data: Dict[str, Any], target_window_i
if action == 'self':
if w is not None:
is_copy_action = cmd[0] in ('-', '@', '*')
is_copy_action = cmd[0] in ('-', '@', '*') or cmd[0].startswith('#')
if is_copy_action:
text = ' '.join(cmd[1:])
if cmd[0] == '-':
@ -755,6 +758,8 @@ def linenum_handle_result(args: List[str], data: Dict[str, Any], target_window_i
set_clipboard_string(text)
elif cmd[0] == '*':
set_primary_selection(text)
elif cmd[0].startswith('#'):
boss.set_clipboard_buffer(cmd[0].lstrip('#'), text)
else:
import shlex
text = ' '.join(shlex.quote(arg) for arg in cmd)
@ -815,6 +820,8 @@ def joined_text() -> str:
set_clipboard_string(joined_text())
elif program == '*':
set_primary_selection(joined_text())
elif program.startswith('#'):
boss.set_clipboard_buffer(program.lstrip('#'), joined_text())
else:
from kitty.conf.utils import to_cmdline
cwd = data['cwd']

View file

@ -1998,6 +1998,16 @@ def has_active_selection(self) -> bool:
return w.has_selection()
return False
def set_clipboard_buffer(self, buffer_name: str, text: Optional[str] = None) -> None:
if buffer_name:
if text is not None:
self.clipboard_buffers[buffer_name] = text
elif buffer_name in self.clipboard_buffers:
del self.clipboard_buffers[buffer_name]
def get_clipboard_buffer(self, buffer_name: str) -> Optional[str]:
return self.clipboard_buffers.get(buffer_name)
@ac('cp', '''
Copy the selection from the active window to the specified buffer
@ -2013,7 +2023,7 @@ def copy_to_buffer(self, buffer_name: str) -> None:
elif buffer_name == 'primary':
set_primary_selection(text)
else:
self.clipboard_buffers[buffer_name] = text
self.set_clipboard_buffer(buffer_name, text)
@ac('cp', '''
Paste from the specified buffer to the active window
@ -2026,7 +2036,7 @@ def paste_from_buffer(self, buffer_name: str) -> None:
elif buffer_name == 'primary':
text = get_primary_selection()
else:
text = self.clipboard_buffers.get(buffer_name)
text = self.get_clipboard_buffer(buffer_name)
if text:
self.paste_to_active_window(text)