From f763e2f33953bad1352004e8bcdc8d8441a820da Mon Sep 17 00:00:00 2001 From: Kayshen-X Date: Sat, 20 Jun 2026 10:19:26 +0800 Subject: [PATCH] refactor(editor): split acp text helpers out to satisfy 800-line cap agent_settings_acp.rs was over the 800-line cap (817 after the Card sink; ~812 before); moved draw_text + ellipsize into agent_settings_acp_helpers.rs. File now 798 lines, op-editor-ui clean. --- .../src/widgets/agent_settings_acp.rs | 25 +++-------------- .../src/widgets/agent_settings_acp_helpers.rs | 27 +++++++++++++++++++ crates/op-editor-ui/src/widgets/mod.rs | 1 + 3 files changed, 31 insertions(+), 22 deletions(-) create mode 100644 crates/op-editor-ui/src/widgets/agent_settings_acp_helpers.rs diff --git a/crates/op-editor-ui/src/widgets/agent_settings_acp.rs b/crates/op-editor-ui/src/widgets/agent_settings_acp.rs index 9fef00c5f..098fd5218 100644 --- a/crates/op-editor-ui/src/widgets/agent_settings_acp.rs +++ b/crates/op-editor-ui/src/widgets/agent_settings_acp.rs @@ -1,6 +1,7 @@ //! ACP Agent section for the Agent settings panel. use crate::theme::Theme; +use crate::widgets::agent_settings_acp_helpers::{draw_text, ellipsize}; use crate::widgets::agent_settings_caret::{paint_settings_input_view, settings_input_text}; use crate::widgets::agent_settings_form_actions::{ cancel_button_rect, paint_form_actions, save_button_rect, @@ -12,7 +13,7 @@ use crate::widgets::agent_settings_i18n::t as t_settings; use crate::widgets::button::{paint_ghost_button_feedback, tokens_from_theme}; use crate::widgets::icons::{draw_icon, Icon}; use crate::widgets::PaintCx; -use crate::{Color, Point2D, Rect, TextLayout}; +use crate::{Color, Point2D, Rect}; use jian_widgets::components::button::{Button, ButtonVariant}; use jian_widgets::components::card::Card; use op_editor_core::agent_settings::{ @@ -794,24 +795,4 @@ fn field_input_rect(card: Rect, field: AcpAgentField) -> Rect { } } -fn draw_text(cx: &mut PaintCx<'_>, text: &str, size: f32, color: Color, x: f32, y: f32) { - let layout = TextLayout::single_run( - text, - "system-ui", - size, - (color).to_jian(), - Point2D::new(0.0, 0.0), - ); - cx.backend.draw_text(&layout, Point2D::new(x, y)); -} - -fn ellipsize(cx: &mut PaintCx<'_>, value: &str, max_w: f32, size: f32) -> String { - if cx.backend.measure_text(value, size) <= max_w { - return value.to_string(); - } - let mut out = value.to_string(); - while !out.is_empty() && cx.backend.measure_text(&format!("{out}..."), size) > max_w { - out.pop(); - } - format!("{out}...") -} +// `draw_text` + `ellipsize` moved to `agent_settings_acp_helpers` (800-line cap). diff --git a/crates/op-editor-ui/src/widgets/agent_settings_acp_helpers.rs b/crates/op-editor-ui/src/widgets/agent_settings_acp_helpers.rs new file mode 100644 index 000000000..f711f4abd --- /dev/null +++ b/crates/op-editor-ui/src/widgets/agent_settings_acp_helpers.rs @@ -0,0 +1,27 @@ +//! Small paint/text helpers for the ACP agent-settings section, split out of +//! `agent_settings_acp.rs` to keep that file under the 800-line cap. + +use crate::widgets::PaintCx; +use crate::{Color, Point2D, TextLayout}; + +pub(super) fn draw_text(cx: &mut PaintCx<'_>, text: &str, size: f32, color: Color, x: f32, y: f32) { + let layout = TextLayout::single_run( + text, + "system-ui", + size, + (color).to_jian(), + Point2D::new(0.0, 0.0), + ); + cx.backend.draw_text(&layout, Point2D::new(x, y)); +} + +pub(super) fn ellipsize(cx: &mut PaintCx<'_>, value: &str, max_w: f32, size: f32) -> String { + if cx.backend.measure_text(value, size) <= max_w { + return value.to_string(); + } + let mut out = value.to_string(); + while !out.is_empty() && cx.backend.measure_text(&format!("{out}..."), size) > max_w { + out.pop(); + } + format!("{out}...") +} diff --git a/crates/op-editor-ui/src/widgets/mod.rs b/crates/op-editor-ui/src/widgets/mod.rs index b3339d9f0..f5feb9d0b 100644 --- a/crates/op-editor-ui/src/widgets/mod.rs +++ b/crates/op-editor-ui/src/widgets/mod.rs @@ -132,6 +132,7 @@ pub mod brand_icons; // Step 4 — extra editor-chrome widgets (TS app parity). pub mod agent_settings_acp; +mod agent_settings_acp_helpers; pub mod agent_settings_builtin; mod agent_settings_builtin_layout; mod agent_settings_builtin_parts;