Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down
3 changes: 2 additions & 1 deletion docs/learning-rust.md
Original file line number Diff line number Diff line change
Expand Up @@ -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+↑/↓ | 滚动对话 |
Expand Down
84 changes: 81 additions & 3 deletions src/tui/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Skill>,
/// Workdir and daily flag the skills were discovered for (the agent is
Expand Down Expand Up @@ -390,6 +393,7 @@ impl App {
selection: None,
selecting: false,
copy_selection: false,
clear_after_copy: false,
toast: None,
skills,
skills_scope,
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
}
4 changes: 4 additions & 0 deletions src/tui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading