From 8d2af4e046c2a95dfc54aafd6f88da12389d76e8 Mon Sep 17 00:00:00 2001 From: Ogulcan Celik Date: Fri, 17 Jul 2026 03:26:33 +0300 Subject: perf: adopt libghostty integration improvements refs #276 --- src/app/actions.rs | 9 ++++----- src/app/input/copy_mode.rs | 10 +++++++--- 2 files changed, 11 insertions(+), 8 deletions(-) (limited to 'src/app') diff --git a/src/app/actions.rs b/src/app/actions.rs index 68286952..3fedeeb3 100644 --- a/src/app/actions.rs +++ b/src/app/actions.rs @@ -11,7 +11,6 @@ use crate::layout::{find_in_direction, NavDirection}; use crate::selection::Selection; use crate::terminal::{EffectiveStateChange, TerminalStateMutation}; use crate::workspace::WorkspaceGitStatus; -use unicode_width::UnicodeWidthChar; use super::state::{ text_matches_query, AgentNotificationDelivery, AppState, Mode, NavigatorRow, @@ -2220,7 +2219,7 @@ pub(crate) fn visible_text_cells(text: &str, pane_width: u16) -> Vec Vec { let mut next_col = 0u16; row.chars() .map(|ch| { - let width = UnicodeWidthChar::width(ch).unwrap_or(0) as u16; + let width = u16::from(crate::ghostty::unicode_codepoint_width(ch as u32)); let start_col = if width == 0 { next_col.saturating_sub(1) } else { @@ -3190,7 +3189,7 @@ mod tests { let prefix = &row[..byte_idx]; prefix .chars() - .map(|ch| UnicodeWidthChar::width(ch).unwrap_or(0) as u16) + .map(|ch| u16::from(crate::ghostty::unicode_codepoint_width(ch as u32))) .sum() } diff --git a/src/app/input/copy_mode.rs b/src/app/input/copy_mode.rs index f6c322ea..e6c0d074 100644 --- a/src/app/input/copy_mode.rs +++ b/src/app/input/copy_mode.rs @@ -1,5 +1,4 @@ use crossterm::event::{KeyCode, KeyEventKind, KeyModifiers}; -use unicode_width::UnicodeWidthChar; use crate::{ app::{ @@ -941,7 +940,7 @@ fn last_character_col(text: &str) -> Option { let mut col = 0u16; let mut last_col = None; for ch in text.chars() { - let width = UnicodeWidthChar::width(ch).unwrap_or(1) as u16; + let width = u16::from(crate::ghostty::unicode_codepoint_width(ch as u32)); if width > 0 { last_col = Some(col); col = col.saturating_add(width); @@ -951,7 +950,7 @@ fn last_character_col(text: &str) -> Option { } fn char_cell_width(ch: char) -> u16 { - UnicodeWidthChar::width(ch).unwrap_or(1).max(1) as u16 + u16::from(crate::ghostty::unicode_codepoint_width(ch as u32)).max(1) } fn copy_mode_page_lines(height: u16, half_page: bool) -> usize { @@ -1703,6 +1702,11 @@ mod tests { submit_copy_search(&mut app, '?', "000000"); assert!(copy_mode_offset_from_bottom(&app, pane_id) > 0); + let copy_mode = app.state.copy_mode.as_ref().expect("copy mode"); + assert_eq!( + copy_mode_viewport_top_row(&app, pane_id) + usize::from(copy_mode.cursor_row), + 0 + ); let runtime = app .state .runtime_for_pane_in_workspace(&app.terminal_runtimes, 0, pane_id) -- cgit v1.2.3