diff --git a/README.md b/README.md index 30b561d..eb11bfd 100644 --- a/README.md +++ b/README.md @@ -149,7 +149,8 @@ Then just describe the task: *"find why the login test is flaky and fix it"*. | `Enter` / `Shift+Enter` (or `Ctrl+J`) | send / new line | | `Enter` while the agent works | steer: the message is delivered mid-turn | | `Alt+Enter` | queue a follow-up for after the current task | -| `Esc`, `Ctrl+C` | interrupt; `Ctrl+C` twice when idle quits | +| `Esc`, `Ctrl+C` | interrupt; `Ctrl+C` twice when idle quits (with text selected, `Ctrl+C` copies instead) | +| `Super+C` / `Ctrl+Shift+C` | copy the mouse selection (`Super+V` / `Ctrl+Shift+V` paste) | | `Shift+Tab` | cycle thinking level | | `/` | command palette | | `Ctrl+R` | sessions | diff --git a/docs/learning-rust.md b/docs/learning-rust.md index 6d545d4..3a36892 100644 --- a/docs/learning-rust.md +++ b/docs/learning-rust.md @@ -30,7 +30,8 @@ cargo test # 跑测试 | Ctrl+V / Ctrl+Y | 从剪贴板粘贴(图片、文件路径或文本)/ 复制最后一条回复 | | 鼠标拖动 | 选中文字,松开即复制到剪贴板(终端原生选择:按住 Shift 拖动,或 `/mouse` 关闭鼠标捕获) | | Ctrl+G | 子代理面板(任务板 + 选中任务的记录) | -| Esc、Ctrl+C | 打断当前回合;空闲时连按两次 Ctrl+C 退出 | +| Esc、Ctrl+C | 打断当前回合;空闲时连按两次 Ctrl+C 退出(有选中文字时 Ctrl+C 改为复制) | +| Super+C / Ctrl+Shift+C | 复制鼠标选中的文字(Super+V / Ctrl+Shift+V 粘贴);Super 组合键不会再被当成 Ctrl | | agent 忙时按 Enter | 把消息排进队列,作为“插话”发给 agent | | ↑ / ↓ | 翻输入历史 | | PageUp / PageDown、Ctrl+↑/↓ | 滚动对话 | diff --git a/src/tui/app.rs b/src/tui/app.rs index a9af3d2..229eebd 100644 --- a/src/tui/app.rs +++ b/src/tui/app.rs @@ -289,6 +289,9 @@ pub struct App { selecting: bool, /// The next frame reads the selection's text back for copying. pub copy_selection: bool, + /// Drop the selection once it is copied (a key copy, not a mouse one, + /// so the next Ctrl+C interrupts again). + pub clear_after_copy: bool, pub toast: Option<(String, Instant)>, pub skills: Vec, /// Workdir and daily flag the skills were discovered for (the agent is @@ -390,6 +393,7 @@ impl App { selection: None, selecting: false, copy_selection: false, + clear_after_copy: false, toast: None, skills, skills_scope, @@ -1166,12 +1170,41 @@ impl App { return; } self.dirty = true; + let mods = Mods::of(key.modifiers); + let (ctrl, alt, shift) = (mods.ctrl, mods.alt, mods.shift); + + // Copy / paste chords: Super+C (or Cmd+C) and Ctrl+Shift+C copy, + // Super+V and Ctrl+Shift+V paste. Some terminals turn Super+C into a + // plain Ctrl+C, so a Ctrl+C while text is selected copies it too + // instead of interrupting or quitting. + if let KeyCode::Char(ch) = key.code { + let ch = ch.to_ascii_lowercase(); + let has_selection = self.selection.as_ref().is_some_and(|s| !s.is_empty()); + if ch == 'c' && (mods.cmd || (ctrl && shift) || (ctrl && has_selection)) { + if has_selection { + self.copy_selection = true; + self.clear_after_copy = true; + } else if mods.cmd || shift { + self.toast("没有选中的文字(鼠标拖动选中,/copy 复制最后一条回复)"); + } + if mods.cmd || shift || has_selection { + return; + } + } + if ch == 'v' && (mods.cmd || (ctrl && shift)) && self.popup.is_none() { + self.selection = None; + self.paste_clipboard(); + return; + } + } if !self.selecting { self.selection = None; } - let ctrl = key.modifiers.contains(KeyModifiers::CONTROL); - let alt = key.modifiers.contains(KeyModifiers::ALT); - let shift = key.modifiers.contains(KeyModifiers::SHIFT); + if mods.cmd { + // Other Super/Cmd chords belong to the desktop or the terminal, + // never to Limbo's Ctrl shortcuts or the prompt. + return; + } if self.popup.is_some() { self.popup_key(key); @@ -2174,3 +2207,48 @@ pub fn fmt_tokens(n: u64) -> String { n.to_string() } } + +/// Modifier state of a key event, with Super/Meta/Hyper ("cmd") kept apart +/// from Ctrl so Super+C never reads as Ctrl+C. +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +struct Mods { + ctrl: bool, + alt: bool, + shift: bool, + cmd: bool, +} + +impl Mods { + fn of(m: KeyModifiers) -> Self { + let cmd = m.intersects(KeyModifiers::SUPER | KeyModifiers::META | KeyModifiers::HYPER); + Mods { + ctrl: m.contains(KeyModifiers::CONTROL) && !cmd, + alt: m.contains(KeyModifiers::ALT), + shift: m.contains(KeyModifiers::SHIFT), + cmd, + } + } +} + +#[cfg(test)] +mod mods_tests { + use super::*; + + #[test] + fn super_is_not_ctrl() { + let m = Mods::of(KeyModifiers::SUPER); + assert!(m.cmd && !m.ctrl); + let m = Mods::of(KeyModifiers::SUPER | KeyModifiers::CONTROL); + assert!(m.cmd && !m.ctrl); + let m = Mods::of(KeyModifiers::META); + assert!(m.cmd && !m.ctrl); + } + + #[test] + fn plain_ctrl_stays_ctrl() { + let m = Mods::of(KeyModifiers::CONTROL); + assert!(m.ctrl && !m.cmd && !m.alt && !m.shift); + let m = Mods::of(KeyModifiers::CONTROL | KeyModifiers::SHIFT); + assert!(m.ctrl && m.shift && !m.cmd); + } +} diff --git a/src/tui/mod.rs b/src/tui/mod.rs index 775a7d9..0c17482 100644 --- a/src/tui/mod.rs +++ b/src/tui/mod.rs @@ -138,6 +138,10 @@ async fn event_loop( app.dirty = false; if let Some(text) = copied { app.copy_selected(text); + if std::mem::take(&mut app.clear_after_copy) { + app.selection = None; + app.dirty = true; + } } } if app.quit {