feat: add setting switch for terminal keyword highlighting under copy/paste option

This commit is contained in:
TomZz
2026-06-23 10:44:13 +08:00
parent 56fe508122
commit 7653c66a6f
5 changed files with 39 additions and 2 deletions
+1
View File
@@ -111,6 +111,7 @@ zombie_reason: "This transfer was interrupted because the application exited. Th
software_builtin: "Built-in"
retry: "Retry"
right_click_copy_paste: "Right-click Copy/Paste"
keyword_highlight: "Terminal Keyword Highlighting"
copy_paste_hint: "Regardless of this switch, you can always use %{key} + C/V to copy/paste."
edit_file: "Edit File"
edit_file_tooltip: "Download to temporary directory, open in default editor, and auto upload on save."
+1
View File
@@ -112,6 +112,7 @@ zombie_reason: "此传输任务因程序退出而中断,传输进程已不存
software_builtin: "软件内置"
retry: "重试"
right_click_copy_paste: "右键复制/粘贴"
keyword_highlight: "终端关键词高亮"
copy_paste_hint: "不管是否开启此开关,都可以使用 %{key} + C/V 快捷键进行复制和粘贴。"
edit_file: "编辑文件"
edit_file_tooltip: "下载到临时目录,使用默认编辑器打开,并在保存后自动上传。"
+19
View File
@@ -1544,6 +1544,25 @@ impl Ashell {
})
).description(t!("copy_paste_hint", key = if cfg!(target_os = "macos") { "Command" } else { "Ctrl" }).to_string())
)
.item(
SettingItem::new(
t!("keyword_highlight").to_string(),
SettingField::render({
let view = view_clone_for_general.clone();
move |_, window, cx| {
Switch::new("keyword-highlight")
.small()
.checked(view.read(cx).config.keyword_highlight())
.on_click(window.listener_for(&view, |this, checked, _, cx| {
this.config.set_keyword_highlight(*checked);
let _ = this.config.save();
cx.notify();
}))
.into_any_element()
}
})
)
)
.item(
SettingItem::new(
t!("monitoring_position").to_string(),
+10
View File
@@ -146,6 +146,8 @@ pub struct ConfigFile {
pub ui_font_size: f32,
#[serde(default)]
pub right_click_copy_paste: bool,
#[serde(default)]
pub keyword_highlight: bool,
#[serde(default = "default_ui_font_family")]
pub ui_font_family: String,
#[serde(default = "default_terminal_font_family")]
@@ -534,6 +536,14 @@ impl ConfigStore {
self.cache.right_click_copy_paste = val;
}
pub fn keyword_highlight(&self) -> bool {
self.cache.keyword_highlight
}
pub fn set_keyword_highlight(&mut self, val: bool) {
self.cache.keyword_highlight = val;
}
pub fn terminal_font_family(&self) -> &str {
if self.cache.terminal_font_family.is_empty() {
"Maple Mono NF CN"
+8 -2
View File
@@ -332,8 +332,12 @@ impl TerminalTab {
});
}
// Get highlights from cache or recompute
let highlights = {
// Get highlights from cache or recompute, only if keyword_highlight is enabled.
let is_enabled = crate::session::config::ConfigStore::load()
.map(|c| c.keyword_highlight())
.unwrap_or(false);
let highlights = if is_enabled {
let mut cache = self.highlight_cache.borrow_mut();
let cache_valid = cache.as_ref().map_or(false, |(cached_cells, _)| {
cached_cells == &cells
@@ -345,6 +349,8 @@ impl TerminalTab {
*cache = Some((cells.clone(), computed.clone()));
computed
}
} else {
std::collections::HashMap::new()
};
RenderSnapshot {