From ce02e70f0e0f71cc95deb3d342e462a5e9105f8f Mon Sep 17 00:00:00 2001 From: Kit Langton Date: Sat, 5 Dec 2026 21:46:23 -0800 Subject: [PATCH 1/2] fix(ui): unify find bars, settings spacing, viewer toolbars, and focus rings --- apps/desktop/src/plugin_host/ui/inspector.rs | 59 +++-- .../src/surfaces/browser/prompts/view.rs | 49 ++-- apps/desktop/src/surfaces/browser/view.rs | 78 ++---- crates/opencode-code-view/src/find_bar.rs | 222 ++++++++++++------ .../annotations/src/line_comments/view.rs | 29 ++- features/files/src/view.rs | 5 +- features/files/src/viewer/toolbar.rs | 27 ++- features/find/src/view.rs | 26 +- features/projects/src/remote_picker/view.rs | 70 +++--- features/review/src/mobile.rs | 33 ++- features/settings/src/mode_card.rs | 3 +- features/settings/src/pages/servers.rs | 21 +- features/settings/src/rows.rs | 13 +- features/settings/src/shell.rs | 23 +- features/terminal-surface/src/find.rs | 115 +++++++-- features/terminal-surface/src/osc8.rs | 54 +++-- features/terminal-surface/src/paste.rs | 74 +++--- 17 files changed, 562 insertions(+), 339 deletions(-) diff --git a/apps/desktop/src/plugin_host/ui/inspector.rs b/apps/desktop/src/plugin_host/ui/inspector.rs index 67c981b47..643379ae2 100644 --- a/apps/desktop/src/plugin_host/ui/inspector.rs +++ b/apps/desktop/src/plugin_host/ui/inspector.rs @@ -6,7 +6,9 @@ use opencode_i18n::t; use opencode_ui::dialog::DialogSize; +use opencode_ui::focus::FocusExt; use opencode_ui::palette::{Elevate as _, Pal, kit}; +use opencode_ui::style::UI_SMALL; use opencode_ui::widgets::{BODY, DIALOG_CLOSE, Fit, button, dialog_window, sized_modal, status_dot}; use rune::{Cx, El, Key, KeyEvent, TextEdit, TextStyle, Tx, col, el, icon, row, rule, spacer, text}; use rune_kit::{ButtonVariant, TextInput}; @@ -22,13 +24,13 @@ pub const OVERLAY_ID: &str = "plugin.inspector"; const REPL_INPUT_KEY: &str = "plugin-inspector-repl-input"; const CLOSE_BTN_KEY: &str = "plugin-inspector-close"; -const TITLE: TextStyle = TextStyle::new(15.0, 560.0).lh(20.0).tracking(-0.13); -const VERSION: TextStyle = TextStyle::new(12.0, 440.0).lh(16.0).mono(); -const BADGE_TXT: TextStyle = TextStyle::new(11.0, 520.0).lh(14.0); -const METRIC_LABEL: TextStyle = TextStyle::new(11.0, 500.0).lh(14.0); +const TITLE: TextStyle = TextStyle::new(15.0, 530.0).lh(20.0).tracking(-0.13); +const VERSION: TextStyle = UI_SMALL.mono(); +const BADGE_TXT: TextStyle = TextStyle::new(11.0, 530.0).lh(14.0); +const METRIC_LABEL: TextStyle = TextStyle::new(11.0, 440.0).lh(14.0); const METRIC_VAL: TextStyle = TextStyle::new(12.0, 530.0).lh(16.0).mono().features("'tnum' 1"); -const MONO: TextStyle = TextStyle::new(12.0, 440.0).lh(17.0).mono(); -const MONO_SMALL: TextStyle = TextStyle::new(11.0, 500.0).lh(15.0).mono().features("'tnum' 1"); +const MONO: TextStyle = UI_SMALL.mono().lh(18.0); +const MONO_SMALL: TextStyle = TextStyle::new(11.0, 530.0).lh(16.0).mono().features("'tnum' 1"); const SECTION_TITLE: TextStyle = TextStyle::new(12.0, 530.0).lh(16.0); pub(crate) static PLUGIN_INSPECTOR: opencode_kernel::Slot = opencode_kernel::Slot::new(); @@ -362,7 +364,7 @@ fn dialog_shell(p: &Pal, label: String, inner: El) -> El { .label(label) .w_full() .h_full() - .radius(6.0) + .radius(12.0) .fill(p.layer1) .elevate(p.overlay) .modal_tx(true, |s: &mut App, tx: &mut Tx| dismiss(s, tx)) @@ -376,14 +378,14 @@ fn inspector_card(p: &Pal, lp: &Plugin, session: &InspectorSession) -> El { .key("plugin-inspector-inner") .w_full() .h_full() - .clip_rounded(6.0) + .clip_rounded(12.0) .child(header(p, lp)) - .child(rule(1.0, p.border)) + .child(rule(0.5, p.border)) .child(metrics_strip(p, lp)) - .child(rule(1.0, p.border)) + .child(rule(0.5, p.border)) .children(last_error.as_deref().map(|err| error_banner(p, err))) .child(logs_pane(p, &lp.manifest.id, &lines, last_error.is_some())) - .child(rule(1.0, p.border)) + .child(rule(0.5, p.border)) .child(repl_bar(p, lp, session)); dialog_shell(p, format!("{} — {}", t!("rune.plugins.inspector.title"), lp.manifest.name), inner) } @@ -405,7 +407,7 @@ fn missing_card(p: &Pal, plugin_id: &str) -> El { .center() .padding(24.0) .child(text(t!("rune.plugins.inspector.missing")).font(BODY).color(p.muted)); - let inner = col().w_full().h_full().clip_rounded(6.0).child(head).child(rule(1.0, p.border)).child(body); + let inner = col().w_full().h_full().clip_rounded(12.0).child(head).child(rule(0.5, p.border)).child(body); dialog_shell(p, t!("rune.plugins.inspector.title").to_owned(), inner) } @@ -415,14 +417,14 @@ fn header(p: &Pal, lp: &Plugin) -> El { let (status_key, status_label, status_color) = status_meta(p, &lp.life); let status_pill = row() .key("plugin-inspector-status") - .h(22.0) - .pl(4.0) - .pr(8.0) + .h(20.0) + .pl(3.0) + .pr(7.0) .gap(2.0) .center_y() - .radius(11.0) + .radius(4.0) .fill(p.layer2) - .border(0.5, p.border) + .box_shadow(Pal::ring_in(p.border)) .child(status_dot(p, status_key)) .child(text(status_label).font(BADGE_TXT).color(status_color)); let can_reload = matches!(lp.life, Life::Running(_) | Life::Errored { .. } | Life::Dormant); @@ -456,12 +458,16 @@ fn header(p: &Pal, lp: &Plugin) -> El { } fn close_button(p: &Pal) -> El { + let close_label = t!("rune.plugins.inspector.close"); el().key(CLOSE_BTN_KEY) .role("button") - .label_static(t!("rune.plugins.inspector.close")) + .label_static(close_label) + .help(close_label) + .help_keys([t!("common.key.esc")]) .size(28.0, 28.0) .radius(6.0) .center() + .focus_default(p) .hover(p.hover) .press(p.pressed) .on_press_tx(|s: &mut App, tx: &mut Tx| dismiss(s, tx)) @@ -523,9 +529,9 @@ fn metric_cell(p: &Pal, id: &str, label: &'static str, value: String, grow: f32) .px(8.0) .py(6.0) .gap(2.0) - .radius(5.0) + .radius(6.0) .fill(p.layer1) - .border(0.5, p.border_muted) + .box_shadow(Pal::ring_in(p.border_muted)) .child(text(label).font(METRIC_LABEL).color(p.faint).truncate()) .child(text(value).font(METRIC_VAL).color(p.text).truncate()) } @@ -575,7 +581,7 @@ fn error_banner(p: &Pal, err: &str) -> El { // A long stack trace stays in the banner instead of crushing the logs and REPL below it. let body = col().w_full().max_h(160.0).fill(p.layer2); let body = session_view::scroller::scroller("plugin-inspector-error-scroll").build::(p, body, content); - col().key("plugin-inspector-error-banner").w_full().child(body).child(rule(1.0, p.danger)) + col().key("plugin-inspector-error-banner").w_full().child(body).child(rule(0.5, p.danger)) } fn logs_pane(p: &Pal, plugin_id: &str, lines: &[console::Line], has_error: bool) -> El { @@ -601,10 +607,11 @@ fn logs_pane(p: &Pal, plugin_id: &str, lines: &[console::Line], has_error: bool) let count_pill = row() .key("plugin-inspector-logs-count") .h(18.0) - .px(6.0) + .px(5.0) .center() - .radius(9.0) + .radius(4.0) .fill(p.layer2) + .box_shadow(Pal::ring_in(p.border_muted)) .child(text(lines.len().to_string()).font(MONO_SMALL).color(p.muted)); let bar = row() .key("plugin-inspector-logs-bar") @@ -641,7 +648,7 @@ fn logs_pane(p: &Pal, plugin_id: &str, lines: &[console::Line], has_error: bool) .grow(1.0) .min_h(0.0) .child(bar) - .child(rule(1.0, p.border_muted)) + .child(rule(0.5, p.border_muted)) .child(scroll) } @@ -667,9 +674,9 @@ fn log_row(p: &Pal, idx: usize, line: &console::Line) -> El { .px(10.0) .py(6.0) .gap(2.0) - .radius(5.0) + .radius(6.0) .fill(p.bg_base) - .border(0.5, border_color) + .box_shadow(Pal::ring_in(border_color)) .child(meta) .child(text(line.message.clone()).font(MONO).color(body_color).wrap().w_full()) } diff --git a/apps/desktop/src/surfaces/browser/prompts/view.rs b/apps/desktop/src/surfaces/browser/prompts/view.rs index 49cc3236b..c8249216b 100644 --- a/apps/desktop/src/surfaces/browser/prompts/view.rs +++ b/apps/desktop/src/surfaces/browser/prompts/view.rs @@ -5,7 +5,8 @@ use browser_pane::prompts::DialogGate; use browser_pane::{DialogKind, PermissionDecision, PermissionKind}; use opencode_i18n::t; -use rune::{El, KeyEvent, Tx, col, el, icon, row, text}; +use opencode_ui::focus::FocusExt; +use rune::{Anim, El, KeyEvent, Tx, col, el, icon, row, text}; use rune_kit::{ButtonVariant, TextInput}; use rune_theme_opencode::icons as ic; use session_view::palette::Elevate; @@ -153,7 +154,7 @@ pub fn view_bars(s: &App, p: &Pal, tab_id: u64) -> Vec { .child(text(notice).font(UI_SMALL).color(p.text).grow(1.0).shrink().min_w(0.0).wrap()) .child(actions), ) - .child(el().w_full().h(1.0).fill(p.border_muted)), + .child(el().w_full().h(0.5).fill(p.border_muted)), ); } @@ -189,7 +190,7 @@ pub fn view_bars(s: &App, p: &Pal, tab_id: u64) -> Vec { }) .build(k) .key("browser-popup-open"); - let close_btn = sized_dismiss_btn(p, "browser-popup-dismiss", t!("common.close"), 20.0, 4.0, move |app: &mut App| { + let close_btn = dismiss_icon_btn(p, "browser-popup-dismiss", t!("common.close"), move |app: &mut App| { app.workspace_panes.browser.host.dismiss_blocked_popup(tab_id); }); let lines = col() @@ -212,7 +213,7 @@ pub fn view_bars(s: &App, p: &Pal, tab_id: u64) -> Vec { .child(row().w_full().gap(12.0).center_y().child(lines).child(open_btn).child(close_btn)) .children(target), ) - .child(el().w_full().h(1.0).fill(p.border_muted)), + .child(el().w_full().h(0.5).fill(p.border_muted)), ); } @@ -279,8 +280,7 @@ pub fn view_bars(s: &App, p: &Pal, tab_id: u64) -> Vec { .child(perm_btn(k, t!("rune.browser.prompt.block"), ButtonVariant::Ghost, "browser-perm-block", tab_id, req_id, PermissionDecision::BlockOnce)) .child(perm_btn(k, t!("rune.browser.prompt.allowOnce"), ButtonVariant::Contrast, "browser-perm-allow-once", tab_id, req_id, PermissionDecision::AllowOnce)); } - // Official's dismiss is `IconButton size="large"` (28 pt, `prompts.tsx:557-563`) and keeps nothing. - let close_btn = sized_dismiss_btn(p, "browser-perm-dismiss", t!("rune.browser.prompt.dismiss"), 28.0, 6.0, move |app: &mut App| { + let close_btn = dismiss_icon_btn(p, "browser-perm-dismiss", t!("rune.browser.prompt.dismiss"), move |app: &mut App| { app.workspace_panes.browser.host.answer_permission(tab_id, req_id, PermissionDecision::Dismiss); }); actions = actions.child(close_btn); @@ -304,7 +304,7 @@ pub fn view_bars(s: &App, p: &Pal, tab_id: u64) -> Vec { .child(msg_col) .child(actions), ) - .child(el().w_full().h(1.0).fill(p.border_muted)), + .child(el().w_full().h(0.5).fill(p.border_muted)), ); } @@ -381,6 +381,8 @@ pub fn view_modal(s: &App, p: &Pal, tab_id: u64) -> Option { .key(PROMPT_STOP_KEY) .role("checkbox") .focusable(true) + .focus_default(p) + .radius(4.0) .label_static(t!("rune.browser.prompt.stop")) .gap(8.0) .center_y() @@ -395,7 +397,7 @@ pub fn view_modal(s: &App, p: &Pal, tab_id: u64) -> Option { .border(1.0, if checked { p.q.submit } else { p.border }) .fill(if checked { p.q.submit } else { p.bg_base }) .center() - .children(checked.then(|| icon(&ic::CHECK, 10.0).color(p.q.submit_text))), + .children(checked.then(|| icon(&ic::CHECK_SMALL, 12.0).color(p.q.submit_text))), ) .child(text(t!("rune.browser.prompt.stop")).font(UI_SMALL).color(p.muted).wrap().grow(1.0).shrink().min_w(0.0)); start = start.child(toggle); @@ -579,35 +581,16 @@ fn dismiss_icon_btn(p: &Pal, key: &'static str, label: &'static str, on_press: i .role("button") .focusable(true) .label_static(label) - .w(24.0) - .h(24.0) + .help(label) + .size(24.0, 24.0) .radius(4.0) .center() + .focus_default(p) .hover(p.hover) + .press(p.pressed) + .hover_motion(Anim::INSTANT, Anim::INSTANT) .on_press(on_press) - .child(icon(&ic::CLOSE, 12.0).color(p.icon_muted)) -} - -/// Official's ghost-muted `IconButton` with its 16 pt `close` icon: `side` 20 (small) or 28 (large). -fn sized_dismiss_btn( - p: &Pal, - key: &'static str, - label: &'static str, - side: f32, - radius: f32, - on_press: impl Fn(&mut App) + 'static, -) -> El { - el().key(key) - .role("button") - .focusable(true) - .label_static(label) - .w(side) - .h(side) - .radius(radius) - .center() - .hover(p.hover) - .on_press(on_press) - .child(icon(&ic::CLOSE, 16.0).color(p.icon_muted)) + .child(icon(&ic::XMARK_SMALL, 16.0).color(p.icon_muted)) } /// The blocked pop-up's destination row: a web address's host whole, then the rest cut short diff --git a/apps/desktop/src/surfaces/browser/view.rs b/apps/desktop/src/surfaces/browser/view.rs index a622909bb..d7394405c 100644 --- a/apps/desktop/src/surfaces/browser/view.rs +++ b/apps/desktop/src/surfaces/browser/view.rs @@ -3,36 +3,28 @@ //! that this build has none). use browser_pane::{Distrust, ENGINE_DOWNLOAD_MB, EngineStatus, Fault, Net}; -use rune::{Anim, El, Spring, Tx, col, el, icon, row, text}; +use opencode_ui::focus::FocusExt; +use opencode_ui::popover::{MENU, surface as popover_surface}; +use rune::{El, Spring, Tx, col, el, icon, row, text}; +use rune_kit::ButtonVariant; use rune_theme_opencode::icons as ic; -use session_view::palette::Elevate; use crate::App; use crate::odometer::odometer_end; -use crate::palette::Pal; +use crate::palette::{Pal, kit}; use crate::view::{UI_MED, UI_SMALL}; -const INSTANT: Anim = Anim::INSTANT; - /// Neutral button opening `tab_id`'s requested web URL in the OS default browser when one exists /// and passes `external_url_allowed_for_tab`. fn open_external_btn(s: &App, p: &Pal, tab_id: u64) -> Option { s.browser_tab_external_url(tab_id)?; let label = opencode_i18n::t!("plugin.browser.external.open"); Some( - el().key("browser-open-external-btn") - .role("button") - .label_static(label) - .h(30.0) - .px(14.0) - .radius(6.0) - .center() - .fill(p.q.neutral) - .box_shadow(Pal::ring_out(p.q.neutral_ring)) - .hover(p.hover) - .hover_motion(INSTANT, INSTANT) + crate::widgets::button(label, ButtonVariant::Neutral) .on_press_tx(move |s: &mut App, tx: &mut Tx| s.open_browser_tab_externally(tab_id, tx)) - .child(text(label).font(UI_MED).color(p.text)), + .build(kit(p)) + .key("browser-open-external-btn") + .focus_default(p), ) } @@ -57,19 +49,12 @@ pub fn surface(s: &App, p: &Pal, tab_id: u64, scale: f32) -> Option { EngineStatus::Verifying => progress(p, opencode_i18n::t!("rune.browser.engine.verifying"), None, 1.0, ext_btn), EngineStatus::Paused(reason) => progress(p, reason.describe(), None, 0.25, ext_btn), EngineStatus::NotInstalled => { - let dl_btn = el() + let dl_btn = crate::widgets::button(opencode_i18n::t!("plugin.file.view.download"), ButtonVariant::Contrast) + .on_press(|s: &mut App| s.start_browser_install()) + .build(kit(p)) .key("browser-download-btn") - .role("button") .label_static(opencode_i18n::t!("rune.browser.engine.download")) - .h(30.0) - .px(14.0) - .radius(6.0) - .center() - .fill(p.q.submit) - .box_shadow(Pal::ring_out(p.q.submit_ring)) - .hover_motion(INSTANT, INSTANT) - .on_press(|s: &mut App| s.start_browser_install()) - .child(text(opencode_i18n::t!("plugin.file.view.download")).font(UI_MED).color(p.q.submit_text)); + .focus_default(p); col() .key("browser-download-prompt") .grow(1.0) @@ -77,25 +62,18 @@ pub fn surface(s: &App, p: &Pal, tab_id: u64, scale: f32) -> Option { .center() .padding(28.0) .gap(14.0) - .child(icon(&ic::GLOBE, 22.0).color(p.icon_muted)) + .child(icon(&ic::GLOBE, 20.0).color(p.icon_muted)) .child(text(opencode_i18n::t!("rune.browser.engine.needsDownload", size = ENGINE_DOWNLOAD_MB)).font(UI_MED).color(p.text).truncate_fade()) .child(row().gap(8.0).center_y().child(dl_btn).children(ext_btn)) } EngineStatus::Failed(failure) => { let retry_btn = failure.fault.retryable().then(|| { - el().key("browser-retry-btn") - .role("button") - .label_static(opencode_i18n::t!("rune.browser.engine.retryDownload")) - .h(30.0) - .px(14.0) - .radius(6.0) - .center() - .fill(p.q.neutral) - .box_shadow(Pal::ring_out(p.q.neutral_ring)) - .hover(p.hover) - .hover_motion(INSTANT, INSTANT) + crate::widgets::button(opencode_i18n::t!("rune.home.noServer.retryShort"), ButtonVariant::Neutral) .on_press(|s: &mut App| s.start_browser_install()) - .child(text(opencode_i18n::t!("rune.home.noServer.retryShort")).font(UI_MED).color(p.text)) + .build(kit(p)) + .key("browser-retry-btn") + .label_static(opencode_i18n::t!("rune.browser.engine.retryDownload")) + .focus_default(p) }); let actions = (retry_btn.is_some() || ext_btn.is_some()) .then(|| row().gap(8.0).center_y().children(retry_btn).children(ext_btn)); @@ -128,18 +106,12 @@ pub fn surface(s: &App, p: &Pal, tab_id: u64, scale: f32) -> Option { |app: &mut App| &mut app.workspace_panes.browser.host, ) .map(|surface| { - // The clip goes on a child: on the card it would clip the card's own shadow too. - // `border_layout` keeps the child from painting over the 1 pt border. - let card = el() - .key("browser-ext-popup-card") + // Canonical concentric `popover::MENU` floating surface (`inset 2 + row 4 = 6 pt`); + // the clip goes on the inner column so the outer floating shadow is never clipped. + let card = popover_surface::(p, MENU, "browser-ext-popup-card", opencode_i18n::t!("settings.tab.extensions")) .pin(Some(4.0), Some(8.0), None, None) - .radius(8.0) - .fill(p.bg_base) - .border(1.0, p.border) - .border_layout() - .elevate(p.overlay) - .on_press(|_: &mut App| {}) - .child(col().clip_rounded((8.0 - session_view::scroller::border_width(1.0)).max(0.0)).child(surface)); + .padding(MENU.inset) + .child(col().clip_rounded(MENU.row_radius).child(surface)); el().key("browser-ext-popup-backdrop") .pin(Some(0.0), Some(0.0), Some(0.0), Some(0.0)) .on_press(|app: &mut App| { @@ -289,7 +261,7 @@ fn unsupported(p: &Pal, url: Option, ext_btn: Option) -> El { .center() .padding(28.0) .gap(8.0) - .child(icon(&ic::GLOBE, 22.0).color(p.icon_muted)) + .child(icon(&ic::GLOBE, 20.0).color(p.icon_muted)) .child(text(opencode_i18n::t!("rune.browser.unsupported.title")).font(UI_MED).color(p.text).truncate_fade()) .child(text(opencode_i18n::t!("rune.browser.unsupported.description")).font(UI_SMALL).color(p.muted).wrap().align(rune::Align::Center).max_w(320.0)) .children(url.map(|u| u.mt(6.0))) diff --git a/crates/opencode-code-view/src/find_bar.rs b/crates/opencode-code-view/src/find_bar.rs index e1800cd98..eb675d810 100644 --- a/crates/opencode-code-view/src/find_bar.rs +++ b/crates/opencode-code-view/src/find_bar.rs @@ -1,21 +1,20 @@ -//! The find bar over a file or a diff: Pierre's `FileSearchBar` -//! (`session-ui/src/components/file-search.tsx`), a 32 tall panel floating at the viewer's top -//! right (`file-find.ts` `positionBar`: 4 over the scroll view's top, 8 in from its right). +//! The find bar over a file or a diff (`240 × 28 pt`, `r6` surface, `13 pt` UI input, `11 pt` +//! tabular count hidden while empty, and `20 × 20 r4` step/close buttons), unified with the +//! session timeline and terminal Find bars. -use rune::{El, Shadow, TextEdit, TextStyle, Transition, Tx, col, icon, row, text}; -use rune_theme_opencode::icons as ic; +use opencode_ui::focus::FocusExt; +use opencode_ui::keymap::Bind; use opencode_ui::palette::{Elevate, Pal}; -use opencode_ui::style::INSTANT; +use opencode_ui::style::{INSTANT, UI}; +use rune::{El, Key, Shadow, TextEdit, TextStyle, Transition, Tx, col, icon, row, text}; +use rune_theme_opencode::icons as ic; -/// `text-14-regular`. -const FIELD: TextStyle = TextStyle::new(14.0, 440.0).lh(25.2); -/// `text-12-regular tabular-nums`. -const COUNT: TextStyle = TextStyle::new(12.0, 440.0).lh(18.0).features("\"tnum\""); +const COUNT: TextStyle = TextStyle::new(11.0, 440.0).lh(16.0).features("\"tnum\""); /// What the bar does to the view it searches. pub struct FindBar { pub key: &'static str, - /// Where its top sits in the view: 4 over the scroll view's top, under a sticky header's. + /// Where its top sits in the view: 8 pt inside a plain scroll view, or under a sticky header. pub top: f32, pub edit: for<'a, 'b> fn(&'a mut S, &'b str) -> &'a mut TextEdit, /// The field's text changed: find it now, in the keystroke's own frame. @@ -26,38 +25,59 @@ pub struct FindBar { pub target: String, } -/// `--shadow-md`. -fn shadow_md(dark: bool) -> [Shadow; 4] { - let black = |light: f32, dark_a: f32| rune::Color::BLACK.alpha(if dark { dark_a } else { light }); - [ - Shadow { y: 6.0, blur: 12.0, spread: -2.0, color: black(0.075, 0.1), ..Shadow::default() }, - Shadow { y: 4.0, blur: 8.0, spread: -2.0, color: black(0.075, 0.15), ..Shadow::default() }, - Shadow { y: 1.0, blur: 2.0, color: black(0.1, 0.15), ..Shadow::default() }, - Shadow::default(), - ] -} - -fn find_button_shell(p: &Pal, key: &'static str, label: &'static str, glyph: El, enabled: bool) -> El { - // `size-6 grid place-items-center rounded`, `disabled:opacity-40`. - let b = row().key(key).size(24.0, 24.0).center().radius(4.0).role("button").label_static(label).child(glyph); +fn step_button_shell(p: &Pal, up: bool, enabled: bool) -> El { + let (key, label, bind) = if up { + ("find-prev", opencode_i18n::t!("ui.fileSearch.previousMatch"), Bind::FindPrev) + } else { + ("find-next", opencode_i18n::t!("ui.fileSearch.nextMatch"), Bind::FindNext) + }; + let glyph = icon(&ic::CHEVRON_DOWN, 16.0).color(p.icon_muted); + let glyph = if up { glyph.rotate(std::f32::consts::PI) } else { glyph }; + let b = row() + .key(key) + .role("button") + .label_static(label) + .help(label) + .help_keys(bind.keycaps()) + .size(20.0, 20.0) + .center() + .radius(4.0) + .preserve_focus_on_press(true) + .child(glyph); if enabled { - b.hover(p.hover).hover_motion(INSTANT, INSTANT) + b.focus_inset(p).hover(p.hover).press(p.pressed).hover_motion(INSTANT, INSTANT) } else { - b.opacity(0.4).disabled(true) + b.opacity(0.4).disabled(true).focusable(false) } } -fn find_chevron(p: &Pal, up: bool) -> El { - let i = icon(&ic::CHEVRON_DOWN, 14.0).color(p.icon_muted); - if up { i.rotate(std::f32::consts::PI) } else { i } +fn close_button_shell(p: &Pal) -> El { + let close_label = opencode_i18n::t!("ui.common.close"); + row() + .key("find-close") + .role("button") + .label_static(close_label) + .help(close_label) + .help_keys([opencode_i18n::t!("common.key.esc")]) + .size(20.0, 20.0) + .center() + .radius(4.0) + .focus_inset(p) + .hover(p.hover) + .press(p.pressed) + .hover_motion(INSTANT, INSTANT) + .child(icon(&ic::XMARK_SMALL, 16.0).color(p.icon_muted)) } fn find_input_base(p: &Pal, input: &TextEdit, spellcheck: bool) -> El { - opencode_ui::style::field(input, FIELD) + opencode_ui::style::field(input, UI.lh(20.0)) .key("find-input") .single_line() + .truncate_fade() .spellcheck(spellcheck) - .w(160.0) + .grow(1.0) + .shrink() + .min_w(0.0) .color(p.text) .placeholder(opencode_i18n::t!("ui.fileSearch.placeholder"), p.faint) .caret(p.text, p.selection) @@ -66,54 +86,96 @@ fn find_input_base(p: &Pal, input: &TextEdit, spellcheck: bool) -> El { } #[allow(clippy::too_many_arguments)] -fn find_bar_chrome(p: &Pal, key: &'static str, top: f32, count: usize, index: usize, field: El, prev: El, next: El, close: El) -> El { - let shown = if count > 0 { format!("{}/{count}", index + 1) } else { "0/0".to_owned() }; - row() - .key(key) - .pin(None, Some(top), Some(8.0), None) - .h(32.0) - // px-3 inside the 1 pt border, which takes no room of its own here. - .px(13.0) +fn find_bar_chrome( + p: &Pal, + key: &'static str, + top: f32, + focused: bool, + has_query: bool, + count: usize, + index: usize, + field: El, + prev: El, + next: El, + close: El, +) -> El { + let count_el = has_query.then(|| { + let shown = if count > 0 { index + 1 } else { 0 }; + text(format!("{shown}/{count}")).key("find-count").font(COUNT).color(p.muted) + }); + let top_inset = if top < 0.0 { 8.0 } else { top }; + let bar = row().key(key); + let bar = match opencode_ui::palette::kit(p).forced { + Some(highlight) => { + let bar = bar.box_shadow(Shadow { spread: 1.0, color: p.text, ..Shadow::default() }); + if focused { bar.outline(2.0, 2.0, highlight) } else { bar } + } + None if focused => bar + .elevate(p.floating) + .box_shadow(Shadow { spread: 1.0, color: p.v2.border_focus, ..Shadow::default() }), + None => bar.elevate(p.floating), + }; + bar.transition(Transition::none()) + .pin(None, Some(top_inset), Some(8.0), None) + .h(28.0) + .w(240.0) + .pl(8.0) + .pr(4.0) .gap(8.0) .center_y() .radius(6.0) - .border(1.0, p.border) - // bg-background-base: v1's --background-base (theme.css), which the v2 palette lacks. - .fill(rune::color::hex(if p.dark { "#121212" } else { "#f8f8f8" }).unwrap_or(p.bg_base)) - .elevate(shadow_md(p.dark)) - .transition(Transition::none()) - .child(icon(&ic::MAGNIFYING_GLASS, 14.0).color(p.icon_muted)) - .child(field) - // `width: 10ch`, right-aligned. - .child(row().key("find-count").w(82.77).justify_end().child(text(shown).font(COUNT).color(p.faint))) - .child(row().key("find-steps").child(prev).child(next)) - .child(close) + .fill(p.bg_base) + .child( + row() + .key("find-value") + .grow(1.0) + .shrink() + .min_w(0.0) + .gap(6.0) + .center_y() + .child(icon(&ic::MAGNIFYING_GLASS, 16.0).color(p.icon_muted)) + .child(field), + ) + .children(count_el) + .child(row().key("find-actions").center_y().child(prev).child(next).child(close)) } /// The bar, pinned in the view it searches: `count` matches with `index` lit. pub fn find_bar(p: &Pal, input: &TextEdit, count: usize, index: usize, spellcheck: bool, bar: FindBar) -> El { - type PressFn = Box; let FindBar { key, top, edit, changed, step, close, target } = bar; - let button = |key: &'static str, label: &'static str, glyph: El, enabled: bool, press: PressFn| { - let b = find_button_shell(p, key, label, glyph, enabled); - if enabled { - b.on_press_tx(move |s: &mut S, tx: &mut Tx| press(s, tx)) - } else { - b - } - }; - let (t_edit, t_prev, t_next, t_close, t_submit, t_changed) = (target.clone(), target.clone(), target.clone(), target.clone(), target.clone(), target); + let enabled = count > 0; + let focused = input.focused; + let has_query = !input.text.is_empty(); + let (t_edit, t_prev, t_next, t_close, t_submit, t_changed) = ( + target.clone(), + target.clone(), + target.clone(), + target.clone(), + target.clone(), + target, + ); let t_key = t_close.clone(); let field = find_input_base(p, input, spellcheck) .on_edit(move |s: &mut S| edit(s, &t_edit)) .on_input_change(move |s: &mut S, tx: &mut Tx| changed(s, &t_changed, tx)) - // The editor receives Escape before a pane shortcut. Unless an IME is using - // it, dismiss the owning bar instead of merely blurring its inner field. + // The editor receives Escape and ⌘G/⇧⌘G before a pane shortcut. Unless an IME is using + // it, dismiss or step the owning bar directly. .on_input_key(move |s: &mut S, ev, tx| { - if !matches!(ev.key, rune::Key::Enter | rune::Key::Escape) || edit(s, &t_key).is_composing() { + if edit(s, &t_key).is_composing() { + return false; + } + if Bind::FindNext.matches_tx(ev, tx) { + step(s, &t_key, true, tx); + return true; + } + if Bind::FindPrev.matches_tx(ev, tx) { + step(s, &t_key, false, tx); + return true; + } + if !matches!(ev.key, Key::Enter | Key::Escape) { return false; } - if ev.key == rune::Key::Escape { + if ev.key == Key::Escape { close(s, &t_key, tx); } else { step(s, &t_key, !ev.mods.shift, tx); @@ -121,10 +183,32 @@ pub fn find_bar(p: &Pal, input: &TextEdit, count: usize, index: usiz true }) .on_submit(move |s: &mut S, tx: &mut Tx| step(s, &t_submit, true, tx)); - let prev = button("find-prev", opencode_i18n::t!("ui.fileSearch.previousMatch"), find_chevron(p, true), count > 0, Box::new(move |s, tx| step(s, &t_prev, false, tx))); - let next = button("find-next", opencode_i18n::t!("ui.fileSearch.nextMatch"), find_chevron(p, false), count > 0, Box::new(move |s, tx| step(s, &t_next, true, tx))); - let close_btn = button("find-close", opencode_i18n::t!("ui.fileSearch.close"), icon(&ic::XMARK_SMALL, 14.0).color(p.icon_muted), true, Box::new(move |s, tx| close(s, &t_close, tx))); - find_bar_chrome(p, key, top, count, index, field, prev, next, close_btn) + let prev = { + let b = step_button_shell(p, true, enabled); + if enabled { + b.on_press_tx(move |s: &mut S, tx: &mut Tx| { + edit(s, &t_prev).focused = true; + tx.focus("find-input", false); + step(s, &t_prev, false, tx); + }) + } else { + b + } + }; + let next = { + let b = step_button_shell(p, false, enabled); + if enabled { + b.on_press_tx(move |s: &mut S, tx: &mut Tx| { + edit(s, &t_next).focused = true; + tx.focus("find-input", false); + step(s, &t_next, true, tx); + }) + } else { + b + } + }; + let close_btn = close_button_shell(p).on_press_tx(move |s: &mut S, tx: &mut Tx| close(s, &t_close, tx)); + find_bar_chrome(p, key, top, focused, has_query, count, index, field, prev, next, close_btn) } /// `content` with the find bar over its top right. diff --git a/features/annotations/src/line_comments/view.rs b/features/annotations/src/line_comments/view.rs index ebe86f8bd..64adf9bff 100644 --- a/features/annotations/src/line_comments/view.rs +++ b/features/annotations/src/line_comments/view.rs @@ -16,6 +16,7 @@ use std::rc::Rc; +use opencode_ui::focus::{self, FocusExt}; use opencode_ui::popup::{Item, Menu, PopupHost, menu_button as ui_menu_button, open as ui_popup_open}; use rune::{Color, Cursor, Drag, El, Icon, KeyEvent, Phase, TextEdit, TextStyle, Tx, col, el, icon, row, text}; use session_view::dock::{Variant, button}; @@ -323,6 +324,7 @@ fn card_v2_shell(host: &dyn LineCommentsHost, p: &Pal, spot: &Spot, c: &LineComm .radius(6.0) .fill(p.layer1) .elevate(p.raised) + .focus_default(p) .hover(p.hover) .hover_motion(INSTANT, INSTANT) .child( @@ -364,6 +366,7 @@ fn menu_button(host: &dyn LineCommentsHost, p: &Pal, spot: &Spot, c: &LineCommen let trigger = b .role("button") .label(label) + .focus_default(p) .hover(p.hover) .press(p.pressed) .hover_motion(INSTANT, INSTANT); @@ -395,12 +398,17 @@ fn card_v1_shell(host: &dyn LineCommentsHost, p: &Pal, spot: &Spot, c: &LineComm ); col() .key(format!("line-comment-{}", c.id)) + .role("button") + .label(c.comment.clone()) .w_full() .padding(12.0) .gap(6.0) .radius(8.0) .fill(face) .box_shadow(Pal::ring_out(ring)) + .focus_default(p) + .hover(p.hover) + .hover_motion(INSTANT, INSTANT) .child( row() .key("head") @@ -436,7 +444,16 @@ fn v1_action_shell(p: &Pal, border: Color, key: &str, label: &str, primary: bool .fill(fill) .box_shadow(Pal::ring_in(edge)) .child(text(label.to_owned()).font(V1_ACTION).color(fg)); - if live { b } else { b.opacity(0.5) } + if live { + let (hover_fill, press_fill) = if primary { + (p.v2.contrast_hover, p.v2.contrast_pressed) + } else { + (p.hover, p.pressed) + }; + b.focus_default(p).hover(hover_fill).press(press_fill).hover_motion(INSTANT, INSTANT) + } else { + b.opacity(0.5).disabled(true).focusable(false) + } } /// The inline `LineCommentEditor`: a bordered field on `surface-base`, ringed in the focus blue @@ -469,13 +486,15 @@ fn editor_v1( .padding(8.0) .radius(6.0) .fill(field_bg) - // Focused, the border turns `border-focus` with a 1 px outline of it just outside: an - // outline, not a shadow, still marks focus in a contrast theme (opencode#65100). - .box_shadow(rune::Shadow { spread: 1.0, color: if focused { p.v2.border_focus } else { border }, inset: true, ..rune::Shadow::default() }) + // Focused, the border turns `focus::color(p)` with a forced-color-aware outer focus ring. + .box_shadow(rune::Shadow { spread: 1.0, color: if focused { focus::color(p) } else { border }, inset: true, ..rune::Shadow::default() }) .child(scroll) .child(grip::(p, spot, height)); if focused { - input = input.outline(1.0, 0.0, p.v2.border_focus); + input = match opencode_ui::palette::kit(p).forced { + Some(highlight) => input.outline(focus::WIDTH, focus::OFFSET, highlight), + None => input.box_shadow(Pal::ring_out(focus::color(p))), + }; } let can = !draft.text.text.trim().is_empty(); let alt = draft.field.alternate; diff --git a/features/files/src/view.rs b/features/files/src/view.rs index f4b165981..678a79290 100644 --- a/features/files/src/view.rs +++ b/features/files/src/view.rs @@ -21,9 +21,8 @@ use crate::{FilesHost, SessionFiles, ops}; const INSTANT: Anim = Anim::INSTANT; const TREE_ROW_H: f32 = chrome::ROW_H; const LIST_ROW_H: f32 = 28.0; -// `.text-12-medium` (`utilities.css:30-37` + `theme.css:8,16`): `--font-size-small: 13px`, -// `--font-weight-medium: 500`, `--line-height-large: 150%` (19.5px). -const LIST_LABEL: rune::TextStyle = rune::TextStyle::new(13.0, 500.0).lh(19.5); +// Calibrated Inter 530 medium on an even 20 pt line height. +const LIST_LABEL: rune::TextStyle = UI_MED.lh(20.0); /// A hash of `tree`'s visible row ids in order (only `rows` of them, when given), as a virtual /// list's version (`El::virtual_rows_version`): it changes whenever a row's key can, as folders diff --git a/features/files/src/viewer/toolbar.rs b/features/files/src/viewer/toolbar.rs index 6052940b5..1f9905262 100644 --- a/features/files/src/viewer/toolbar.rs +++ b/features/files/src/viewer/toolbar.rs @@ -1,10 +1,12 @@ //! File viewer toolbars, picture metadata badges, Open-in split button, and the artifact `...` menu. +use opencode_ui::focus::FocusExt; +use opencode_ui::palette::{Pal, kit}; use opencode_ui::popup::{Item, Menu, MenuButton as _, PopupHost}; +use opencode_ui::style::{UI_MED, UI_SMALL}; use rune::{Align, Anim, Color, El, Icon, Shadow, TextStyle, Tx, el, icon, row, text}; use rune_kit::Loader; use rune_theme_opencode::icons as ic; -use opencode_ui::palette::{Pal, kit}; use crate::{FilesHost, markdown, view}; @@ -15,16 +17,18 @@ pub(super) const META_MIN_W: f32 = 600.0; fn tool_shell(p: &Pal, key: &'static str, glyph: &'static Icon, on: bool, label: &'static str, help: &str) -> El { el().key(key) - .size(25.0, 25.0) - .radius(5.0) + .size(28.0, 28.0) + .radius(6.0) .center() + .focus_default(p) .fill(if on { p.row_active } else { Color::TRANSPARENT }) - .hover(p.hover) + .hover(if on { p.row_active } else { p.hover }) + .press(p.pressed) .hover_motion(INSTANT, INSTANT) .role("button") .label(label) .help(help.to_owned()) - .child(icon(glyph, 13.0).color(if on { p.icon } else { p.icon_muted })) + .child(icon(glyph, 16.0).color(if on { p.icon } else { p.icon_muted })) } /// A toolbar button: `glyph`, filled while `on`, saying `help` on hover. @@ -40,19 +44,17 @@ pub(super) fn tool( tool_shell(p, key, glyph, on, label, help).on_press_tx(press) } -/// A picture's details in the toolbar (`artifact-metadata`): 13 px `text-faint` tabular figures, -/// 6 apart with a `·` between, 12 before the actions; shown while the pointer is on the toolbar -/// or focus is in it, and not at all in a view `META_MIN_W` wide or narrower. +/// A picture's details in the toolbar (`artifact-metadata`): 12 pt `text-faint` tabular figures, +/// 6 apart with a `·` between, legible at rest whenever the view is wider than `META_MIN_W`. pub(super) fn picture_meta(p: &Pal, items: Vec) -> El { - const META: TextStyle = TextStyle::new(13.0, 440.0).lh(16.0).features("'tnum' 1"); + const META: TextStyle = UI_SMALL.features("'tnum' 1"); let mut out = row() .key("files-meta") .gap(6.0) .mr(6.0) .center_y() .shrink() - .min_w(0.0) - .group_opacity(0.0, 1.0); + .min_w(0.0); for (i, item) in items.into_iter().enumerate() { if i > 0 { out = out.child(text("·").font(META).color(p.faint)); @@ -264,7 +266,7 @@ pub(super) fn artifact_toolbar( menu_open: bool, meta: Option>, ) -> El { - const NAME: TextStyle = TextStyle::new(13.0, 530.0).lh(16.0); + const NAME: TextStyle = UI_MED; let name = opencode_kit::path::basename(path).to_owned(); let dir = artifact_directory(root, path).map(str::to_owned); let mode_label = if rendered { @@ -426,6 +428,7 @@ fn action_face(p: &Pal, key: &'static str, glyph: &'static Icon, label: &'static .size(28.0, 28.0) .radius(6.0) .center() + .focus_default(p) .hover(p.hover) .press(p.pressed) .hover_motion(INSTANT, INSTANT) diff --git a/features/find/src/view.rs b/features/find/src/view.rs index 6734cb8c0..a438f18d9 100644 --- a/features/find/src/view.rs +++ b/features/find/src/view.rs @@ -5,7 +5,7 @@ use opencode_ui::focus::FocusExt; use opencode_ui::keymap::Bind; -use rune::{El, MenuItem, TextStyle, Transition, Tx, icon, row, text}; +use rune::{El, MenuItem, Shadow, TextStyle, Transition, Tx, icon, row, text}; use rune_theme_opencode::icons as ic; use session_view::palette::Pal; use session_view::style::{INSTANT, UI}; @@ -30,11 +30,13 @@ fn input_shell(s: &dyn FindHost, p: &Pal) -> El { } fn close_button_shell(p: &Pal) -> El { + let close_label = opencode_i18n::t!("ui.common.close"); row() .key("find-close") .role("button") - // Desktop names it after the field and gives it no tooltip (`search-bar.tsx`). - .label_static(opencode_i18n::t!("session.search.placeholder")) + .label_static(close_label) + .help(close_label) + .help_keys([opencode_i18n::t!("common.key.esc")]) .size(20.0, 20.0) .center() .radius(4.0) @@ -49,10 +51,10 @@ fn close_button_shell(p: &Pal) -> El { /// Close, its chevron rotated 180 deg for Previous, at 40% and disabled while nothing matches, /// keeping focus in the search field when clicked (`onMouseDown -> preventDefault`). fn step_button_shell(p: &Pal, up: bool, enabled: bool) -> El { - let (key, label) = if up { - ("find-prev", opencode_i18n::t!("ui.fileSearch.previousMatch")) + let (key, label, bind) = if up { + ("find-prev", opencode_i18n::t!("ui.fileSearch.previousMatch"), Bind::FindPrev) } else { - ("find-next", opencode_i18n::t!("ui.fileSearch.nextMatch")) + ("find-next", opencode_i18n::t!("ui.fileSearch.nextMatch"), Bind::FindNext) }; let glyph = icon(&ic::CHEVRON_DOWN, 16.0).color(p.icon_muted); let glyph = if up { glyph.rotate(std::f32::consts::PI) } else { glyph }; @@ -60,13 +62,15 @@ fn step_button_shell(p: &Pal, up: bool, enabled: bool) -> El { .key(key) .role("button") .label_static(label) + .help(label) + .help_keys(bind.keycaps()) .size(20.0, 20.0) .center() .radius(4.0) .preserve_focus_on_press(true) .child(glyph); if enabled { - b.hover(p.hover).press(p.pressed).hover_motion(INSTANT, INSTANT) + b.focus_inset(p).hover(p.hover).press(p.pressed).hover_motion(INSTANT, INSTANT) } else { b.opacity(0.4).disabled(true).focusable(false) } @@ -82,16 +86,18 @@ fn build_bar(s: &dyn FindHost, p: &Pal, input: El, steps: [El; 2], close_btn: El let total = if find.counting() { "…".to_owned() } else { total.to_string() }; text(format!("{shown}/{total}")).key("find-count").font(COUNT).color(p.muted) }); - // `text-input-v2`: its input elevation at rest, the focus outline (and no shadow) while focused. + // `text-input-v2`: outer box-shadow ring at rest and when focused so inner layout never shifts. let bar = row().key("find-bar"); let bar = match opencode_ui::palette::kit(p).forced { // A contrast theme draws the edge in its text colour and focus as the field's own ring // (`search-bar.css`, opencode#65100). Some(highlight) => { - let bar = bar.border(1.0, p.text); + let bar = bar.box_shadow(Shadow { spread: 1.0, color: p.text, ..Shadow::default() }); if find.input.focused { bar.outline(2.0, 2.0, highlight) } else { bar } } - None if find.input.focused => bar.border(1.0, p.v2.border_focus), + None if find.input.focused => { + bar.box_shadow(Shadow { spread: 1.0, color: p.v2.border_focus, ..Shadow::default() }) + } None => bar.box_shadow(Pal::ring_out(p.border)), }; bar.transition(Transition::none()) diff --git a/features/projects/src/remote_picker/view.rs b/features/projects/src/remote_picker/view.rs index da784dd4a..df90ec628 100644 --- a/features/projects/src/remote_picker/view.rs +++ b/features/projects/src/remote_picker/view.rs @@ -6,6 +6,8 @@ use std::collections::{BTreeMap, BTreeSet}; use opencode_i18n::t; +use opencode_ui::focus::FocusExt; +use opencode_ui::popover::MENU; use opencode_ui::widgets::{DialogSize, Fit, button, dialog_window, sized_modal}; use rune::{Color, Cx, Direction, El, TextStyle, Tx, col, icon, row, text}; use rune_kit::{ButtonVariant, TextInput}; @@ -79,7 +81,8 @@ pub fn view(s: &H, p: &Pal, cx: &Cx) -> Vec { .help(full) .on_press_tx(move |s: &mut H, tx: &mut Tx| super::navigate(s, to.clone(), tx)) .build(k) - .key(format!("recent-{}", proj.id)); + .key(format!("recent-{}", proj.id)) + .focus_default(p); chips = chips.child(chip); } if o.recent.len() > 3 { @@ -91,7 +94,8 @@ pub fn view(s: &H, p: &Pal, cx: &Cx) -> Vec { .build(k) .key("directory-picker-more-projects") .label_static(t!("dialog.directory.moreProjects")) - .expanded(expanded), + .expanded(expanded) + .focus_default(p), ); } body = body.child(chips); @@ -100,10 +104,10 @@ pub fn view(s: &H, p: &Pal, cx: &Cx) -> Vec { .key("directory-picker-more-menu") .role("menu") .label_static(t!("dialog.directory.moreProjects")) - .padding(4.0) - .radius(8.0) - .fill(p.bg_base) - .elevate(p.overlay); + .padding(MENU.inset) + .radius(MENU.radius()) + .fill(p.layer1) + .elevate(p.floating); for (i, project) in o.recent.iter().skip(3).enumerate() { let dir = project.directory.clone(); let lit = i == active; @@ -115,14 +119,14 @@ pub fn view(s: &H, p: &Pal, cx: &Cx) -> Vec { .help(dir.clone()) .focusable(true) .w_full() - .h(28.0) + .h(MENU.row_h) .px(8.0) .center_y() - .radius(4.0) - .fill(if lit { p.hover } else { Color::TRANSPARENT }) - .hover(p.hover) + .radius(MENU.row_radius) + .fill(if lit { p.row_active } else { Color::TRANSPARENT }) + .hover(p.row_active) .press(p.pressed) - .focus_ring(2.0, -2.0, p.v2.border_focus) + .focus_inset(p) .on_press_tx(move |s: &mut H, tx: &mut Tx| super::navigate(s, dir.clone(), tx)) .child(text(project.name.clone()).font(UI).color(p.text).truncate()), ); @@ -142,7 +146,8 @@ pub fn view(s: &H, p: &Pal, cx: &Cx) -> Vec { button(label, ButtonVariant::Ghost) .help(path.clone()) .on_press_tx(move |s: &mut H, tx: &mut Tx| super::navigate(s, path.clone(), tx)) - .build(k), + .build(k) + .focus_default(p), ); } body = body.child(nav); @@ -153,12 +158,17 @@ pub fn view(s: &H, p: &Pal, cx: &Cx) -> Vec { let cancel = button(t!("common.cancel"), ButtonVariant::Neutral) .on_press_tx(|s: &mut H, tx: &mut Tx| super::close(s, tx)) .build(k) - .key("directory-picker-cancel"); - let select = opencode_ui::widgets::not_allowed(button(t!("dialog.directory.action.selectFolder"), ButtonVariant::Contrast) - .disabled(!picked) - .on_press_tx(|s: &mut H, tx: &mut Tx| super::resolve_pick(s, tx)) - .build(k) - .key("directory-picker-select"), !picked); + .key("directory-picker-cancel") + .focus_default(p); + let select = opencode_ui::widgets::not_allowed( + button(t!("dialog.directory.action.selectFolder"), ButtonVariant::Contrast) + .disabled(!picked) + .on_press_tx(|s: &mut H, tx: &mut Tx| super::resolve_pick(s, tx)) + .build(k) + .key("directory-picker-select") + .focus_default(p), + !picked, + ); let footer = row() .key("directory-picker-footer") .w_full() @@ -214,16 +224,21 @@ fn header_titles(o: &Open, p: &Pal) -> El { } fn close_button_shell(p: &Pal) -> El { + let close_label = t!("common.close"); row() .key("directory-picker-close") .role("button") - .label_static(t!("common.close")) + .label_static(close_label) + .help(close_label) + .help_keys([t!("common.key.esc")]) .size(20.0, 20.0) .mt(-2.0) .mr(-2.0) .radius(4.0) .center() + .focus_default(p) .hover(p.hover) + .press(p.pressed) .child(icon(&ic::CLOSE, 20.0).color(p.icon_muted)) } @@ -232,11 +247,10 @@ fn suggestions_shell(p: &Pal) -> El { .key("directory-picker-suggestions") .role("listbox") .pin(Some(0.0), Some(34.0), Some(0.0), None) - .padding(4.0) - .radius(6.0) - .fill(p.layer2) - .box_shadow(Pal::ring_in(p.border)) - .elevate(p.overlay) + .padding(MENU.inset) + .radius(MENU.radius()) + .fill(p.layer1) + .elevate(p.floating) } fn suggestion_row_shell(p: &Pal, i: usize, item: &str, home: &str, lit: bool) -> El { @@ -246,9 +260,10 @@ fn suggestion_row_shell(p: &Pal, i: usize, item: &str, home: &str, lit: bool) -> .w_full() .px(8.0) .py(6.0) - .radius(4.0) - .fill(if lit { p.hover } else { Color::TRANSPARENT }) - .hover(p.hover) + .radius(MENU.row_radius) + .fill(if lit { p.row_active } else { Color::TRANSPARENT }) + .hover(p.row_active) + .focus_inset(p) .child( text(format!("{}/", super::display(item, home))) .font(UI) @@ -366,6 +381,7 @@ fn tree_row_shell(p: &Pal, d: &Dir, depth: usize, open: bool, lit: bool, failed: .gap(6.0) .center_y() .radius(4.0) + .focus_inset(p) .hover(p.hover) .child( icon(&ic::CHEVRON_DOWN, 14.0) diff --git a/features/review/src/mobile.rs b/features/review/src/mobile.rs index 3d9456560..a3cd09173 100644 --- a/features/review/src/mobile.rs +++ b/features/review/src/mobile.rs @@ -12,8 +12,9 @@ use rune::{Color, Direction, El, Icon, ScrollSpec, Shadow, TextStyle, Tx, col, e use rune_kit::ScrollBar; use rune_kit::diff::{FileDiff, FileStatus}; use rune_theme_opencode::icons as ic; +use opencode_ui::focus::FocusExt; use opencode_ui::palette::{Elevate as _, Pal}; -use opencode_ui::style::{HOVER_FADE, INSTANT, UI}; +use opencode_ui::style::{HOVER_FADE, INSTANT, UI, UI_MED, UI_SMALL}; use crate::data::{ReviewFileMeta, prepare_narrow_paths}; use crate::{ReviewHost, SessionReview}; @@ -113,8 +114,7 @@ impl NarrowReview { } /// Expands all changed files or collapses all open files in session `sid`'s narrow view. -pub fn toggle_all(host: &mut dyn ReviewHost, sid: &str, tx: &mut Tx) { - tx.instant(); +pub fn toggle_all(host: &mut dyn ReviewHost, sid: &str, _tx: &mut Tx) { let wrap = host.wrap_lines(); let changed = if let Some(sr) = host.review_mut().sessions.get_mut(sid) { sr.narrow.toggle_all(sr.diffs.files(), &sr.meta); @@ -129,8 +129,7 @@ pub fn toggle_all(host: &mut dyn ReviewHost, sid: &str, tx: &mut Tx) { } /// Expands or collapses file `path` in session `sid`'s narrow Changes accordion. -pub fn toggle_file(host: &mut dyn ReviewHost, sid: &str, path: &str, tx: &mut Tx) { - tx.instant(); +pub fn toggle_file(host: &mut dyn ReviewHost, sid: &str, path: &str, _tx: &mut Tx) { let wrap = host.wrap_lines(); let changed = if let Some(sr) = host.review_mut().sessions.get_mut(sid) { sr.narrow.toggle(sr.diffs.files(), path); @@ -153,9 +152,9 @@ pub fn open_file(host: &mut dyn ReviewHost, path: &str, tx: &mut Tx) { /// `DiffChanges` standard: the mono face at 14 / 21, regular. const COUNT: TextStyle = TextStyle::new(14.0, 440.0).mono().lh(21.0); /// `button-v2` small: 13 / 20 at 530. -const BUTTON: TextStyle = TextStyle::new(13.0, 530.0).lh(20.0); +const BUTTON: TextStyle = UI_MED.lh(20.0); /// An accordion trigger: `font-size-small` at 440 on `line-height-large`. -const ROW: TextStyle = TextStyle::new(13.0, 440.0).lh(19.5); +const ROW: TextStyle = UI.lh(20.0); /// `chevron-grabber-vertical`. static GRABBER: Icon = Icon { @@ -213,6 +212,10 @@ fn toggle_all_button_shell(p: &Pal, empty_open: bool) -> El { .radius(4.0) .fill(p.q.neutral) .elevate(neutral_ring(p)) + .focus_default(p) + .hover(p.hover) + .press(p.pressed) + .hover_motion(INSTANT, INSTANT) .child(icon(&GRABBER, 16.0).color(p.icon)) .child(text(label).font(BUTTON).color(p.text).truncate().shrink().min_w(0.0)) } @@ -322,8 +325,6 @@ fn trigger_shell(p: &Pal, m: &ReviewFileMeta, open: bool, last: bool) -> El { // (`accordion.css`'s `transition: background-color 0.15s ease`). Desktop's selected file // (`session-review.css:53-57`) never fills: Kobalte's item overwrites the // `session-review-accordion-item` slot that rule needs. - .hover(p.hover) - .hover_motion(HOVER_FADE, HOVER_FADE) .child( row() .key("file") @@ -345,11 +346,15 @@ fn trigger_shell(p: &Pal, m: &ReviewFileMeta, open: bool, last: bool) -> El { ), ); if !can { - return r; + return r.disabled(true).focusable(false); } // `session-review-diff-chevron`: chevron-down at small (14) in icon-weaker, turned - // -90deg while shut (`session-review.css:163-172`); the press lands at once. - r.child( + // -90deg while shut (`session-review.css:163-172`). + r.focus_inset(p) + .hover(p.hover) + .press(p.pressed) + .hover_motion(HOVER_FADE, HOVER_FADE) + .child( icon(&ic::CHEVRON_DOWN, 14.0) .key("chevron") .color(p.icon_faint) @@ -378,14 +383,16 @@ fn open_file_button_shell(p: &Pal) -> El { .gap(6.0) .center_y() .radius(4.0) + .focus_default(p) .hover(p.hover) + .press(p.pressed) .hover_motion(INSTANT, INSTANT) .child(icon(&ic::OPEN_FILE, 16.0).color(p.icon)) .child(text(t!("ui.sessionReview.openFile")).font(BUTTON).color(p.text)) } fn summary_shell(p: &Pal, m: &ReviewFileMeta, open: El) -> El { - const CHANGE: TextStyle = TextStyle::new(12.0, 440.0).lh(16.0); + const CHANGE: TextStyle = UI_SMALL; let lead = match m.status { FileStatus::Added => row().gap(12.0).center_y().child(text(t!("ui.sessionReview.change.added")).font(CHANGE).color(p.success)).child(counts(p, m.additions, m.deletions)), FileStatus::Deleted => row().gap(12.0).center_y().child(text(t!("ui.sessionReview.change.removed")).font(CHANGE).color(p.danger)).child(counts(p, m.additions, m.deletions)), diff --git a/features/settings/src/mode_card.rs b/features/settings/src/mode_card.rs index 00ab76b4b..ed5727624 100644 --- a/features/settings/src/mode_card.rs +++ b/features/settings/src/mode_card.rs @@ -2,6 +2,7 @@ //! `ModeSketch` and `ModeCheck`, `interface-mode.css`; one style for both since opencode#65800): //! a 120 pt card whose window shows only its navigation and fades into the card's name. +use opencode_ui::focus::FocusExt; use opencode_ui::palette::{Pal, kit}; use rune::{Color, Direction, El, col, el, row, text}; @@ -79,7 +80,7 @@ pub(crate) fn card(p: &Pal, key: &'static str, label: &'static str, sketch: Sket .focusable(true) .focus_selected(checked) // `:has(input:focus-visible)`: a 2pt `border-focus` outline 2pt out. - .focus_ring(2.0, 2.0, c.border_focus) + .focus_default(p) .w(120.0) .shrink() .min_w(0.0) diff --git a/features/settings/src/pages/servers.rs b/features/settings/src/pages/servers.rs index 32eb6416f..b2f7db782 100644 --- a/features/settings/src/pages/servers.rs +++ b/features/settings/src/pages/servers.rs @@ -29,7 +29,8 @@ use crate::jobs::{SettingsJob, SettingsRequest}; use crate::{list, setting}; use inventory::{Kind, Server}; -const META: rune::TextStyle = rune::TextStyle::new(11.0, 440.0).lh(11.0); +const META: rune::TextStyle = rune::TextStyle::new(11.0, 440.0).lh(14.0); +const HIDDEN_BADGE: rune::TextStyle = rune::TextStyle::new(11.0, 530.0).lh(14.0); /// What the page read: each server's shells and its global config's choice. #[derive(Default)] @@ -190,7 +191,7 @@ pub fn view(s: &H, p: &Pal) -> El { let row = connection_row(s, p, server, ready); let row = if ready { let target = if server.key == *selected { "settings-shell".to_owned() } else { format!("settings-shell:{}", server.key) }; - super::revealable(s, p, &target, 16.0, row) + super::revealable(s, p, &target, 20.0, row) } else { row }; @@ -242,21 +243,21 @@ fn select_for( fn card(p: &Pal, rows: Vec) -> El { let n = rows.len(); rows.into_iter().enumerate().fold( - col().key("settings-server-list").w_full().px(16.0).radius(8.0).fill(p.layer1).box_shadow(Pal::ring_in(p.border_muted)), + col().key("settings-server-list").w_full().px(20.0).radius(8.0).fill(p.layer1).box_shadow(Pal::ring_in(p.border_muted)), |l, (at, r)| if at + 1 < n { l.child(r.pb(16.0)).child(rule(0.5, p.border)).child(el().h(16.0)) } else { l.child(r) }, ) } fn hidden_badge(p: &Pal) -> El { - // `packages/app/src/settings/servers/servers.tsx:140-143` (`opencode#67520`): - // `rounded-[3px] border border-v2-border-border-base px-1 py-0.5 text-[9px] leading-none text-v2-text-text-muted`. row() .key("settings-server-hidden-badge") - .px(4.0) - .py(2.0) - .radius(3.0) - .border(1.0, p.border) - .child(text(t!("settings.servers.hidden")).font(rune::TextStyle::new(9.0, 440.0).lh(9.0)).color(p.muted)) + .h(18.0) + .px(5.0) + .center() + .radius(4.0) + .fill(p.layer2) + .box_shadow(Pal::ring_in(p.border)) + .child(text(t!("settings.servers.hidden")).font(HIDDEN_BADGE).color(p.muted)) } fn connection_row(s: &H, p: &Pal, server: &Server, shell_menu: bool) -> El { diff --git a/features/settings/src/rows.rs b/features/settings/src/rows.rs index dbeffce78..be286f539 100644 --- a/features/settings/src/rows.rs +++ b/features/settings/src/rows.rs @@ -8,11 +8,11 @@ use rune_kit::Switch; use crate::host::SettingsHost; use crate::shell; /// `.settings-section-title`: 13 on 16 at 530. -const SECTION: TextStyle = TextStyle::new(13.0, 530.0).lh(16.0); -/// `settings-row-description`: 13 on 20 at 440. -const BODY: TextStyle = TextStyle::new(13.0, 440.0).lh(20.0); +const SECTION: TextStyle = opencode_ui::style::UI_MED; +/// `settings-row-description`: 13 on 18 at 440 so multi-line descriptions wrap cleanly without negative margin pull. +const BODY: TextStyle = TextStyle::new(13.0, 440.0).lh(18.0).tracking(-0.04); /// `settings-row-title`: 13 on 16 at 530, -0.04 tracking. -const ROW_TITLE: TextStyle = TextStyle::new(13.0, 530.0).lh(16.0).tracking(-0.04); +const ROW_TITLE: TextStyle = opencode_ui::style::UI_MED; /// The Settings screen in a panel `size` points large (0 when not measured yet). pub fn page(s: &H, p: &Pal, size: (f32, f32)) -> El { @@ -86,10 +86,9 @@ fn setting_row(p: &Pal, key: &str, title: &str, about: Option, control: El, .grow(1.0) .shrink() .min_w(0.0) - .gap(8.0) + .gap(4.0) .child(text(title.to_owned()).key("title").font(ROW_TITLE).color(p.text).wrap()) - // `margin-block: -3.5px` keeps its 20 pt lines on the title's 16 pt rhythm. - .children(about.map(|a| a.key("about").my(-3.5))); + .children(about.map(|a| a.key("about"))); if ROWS_WRAP.get() { return col() .key(format!("setting-{key}")) diff --git a/features/settings/src/shell.rs b/features/settings/src/shell.rs index e2050ed67..6e175c0fe 100644 --- a/features/settings/src/shell.rs +++ b/features/settings/src/shell.rs @@ -16,8 +16,8 @@ use crate::pages::{self, Page}; use crate::search; /// `tabs-v2-trigger`: 13 on 16 at 440, -0.04 tracking. -const TAB: rune::TextStyle = rune::TextStyle::new(13.0, 440.0).lh(16.0).tracking(-0.04); -const BACK: rune::TextStyle = rune::TextStyle::new(13.0, 440.0).lh(16.0); +const TAB: rune::TextStyle = opencode_ui::style::UI; +const BACK: rune::TextStyle = opencode_ui::style::UI; /// A page row's hover (`settings-nav-groups` `tabs-v2-trigger-wrapper`: 120 ms ease-in-out). const NAV_FADE: rune::Anim = rune::Anim::new(rune::Curve::tween(0.12, rune::Easing::EASE_IN_OUT)); @@ -101,13 +101,15 @@ pub fn view(s: &H, p: &Pal, (width, heigh // keyboard focus while a layout switch or zoom moves the screen across 800. .child(screen(row().w_full().px(inset).child(row().w_full().child(col().key("settings-content").w_full().min_w(0.0).child(content))))); } - // `settings.css` (opencode#65998): Settings lines up with Home. The layout is Home's 1056 box - // centred with 24 of padding each side: the sidebar is Home's 256 projects column, and the - // content starts 28 past it and runs 4 into the end gutter, so its panels' 4 of shadow room - // sits in Home's 32 column gap and the cards span Home's 720 sessions column. From 800 to - // 1007 the sidebar is 240 and the content has no margins. - let wide = width <= 0.0 || width >= 1008.0; - let (rail_w, pad_start, pad_end, margin) = if wide { (256.0, 0.0, 12.0, (28.0, -4.0)) } else { (240.0, 16.0, 24.0, (0.0, 0.0)) }; + // `settings.css` (opencode#65998): at 1008+ Settings lines up with Home's 1056 box centred + // with 24 of padding each side (256 rail, content 28 past it and -4 into the end gutter so + // cards span Home's 720 sessions column). Across 800..1008 interpolate smoothly so resizing + // never snaps by 28 pt. + let t = if width <= 0.0 { 1.0 } else { ((width - 800.0) / (1008.0 - 800.0)).clamp(0.0, 1.0) }; + let rail_w = 240.0 + 16.0 * t; + let pad_start = 0.0; + let pad_end = 12.0; + let margin = (12.0 + 16.0 * t, -4.0 * t); let rail = col() .key("settings-sidebar") .w(rail_w) @@ -220,6 +222,7 @@ fn nav_item(s: &H, p: &Pal, page: &Page) -> El { .gap(8.0) .center_y() .radius(6.0) + .focus_inset(p) .fill(if on { p.layer3 } else { Color::TRANSPARENT }) // Under the pointer a row that isn't the open page takes `bg-layer-01` and the base ink, // over 120 ms (`transition: background-color, color 120ms ease-in-out`). @@ -321,7 +324,9 @@ fn narrow_bar(s: &H, p: &Pal, inset: f32) .radius(6.0) .fill(p.bg_base) .box_shadow(Pal::ring_out(p.ring)) + .focus_default(p) .hover(p.hover) + .press(p.pressed) .menu_button("settings-mobile-menu", |s: &mut H, tx: &mut Tx| { let menu = build_narrow_menu(s); popup::open(s, menu, "settings-mobile-menu", tx, |s: &mut H, picked, tx| pick_narrow_page(s, picked, tx)); diff --git a/features/terminal-surface/src/find.rs b/features/terminal-surface/src/find.rs index b88a3aa81..be395a334 100644 --- a/features/terminal-surface/src/find.rs +++ b/features/terminal-surface/src/find.rs @@ -1,13 +1,16 @@ //! Finding text in a terminal's screen and scrollback: Ctrl+F (⌘F), or Ctrl+Shift+F while a -//! program runs full screen (it keeps Ctrl+F: vim and less page with it). The bar looks like the -//! session's Find bar and sits at the pane's top right; the worker runs libghostty-vt's -//! own search (`crates/terminal/src/find.rs`), so it follows output as it arrives. Enter goes to -//! the next older match, Shift+Enter to the newer one, Escape closes. Desktop's terminal has none. +//! program runs full screen (it keeps Ctrl+F: vim and less page with it). The bar matches the +//! session's Find bar (`240 × 28 pt`, `r6` surface, `20 × 20 r4` step and close buttons) and sits +//! at the pane's top right; the worker runs libghostty-vt's own search (`crates/terminal/src/find.rs`), +//! so it follows output as it arrives. Enter / ⌘G goes to the next older match, Shift+Enter / ⇧⌘G +//! to the newer one, Escape closes. -use rune::{El, Key, KeyEvent, TextEdit, TextStyle, Transition, Tx, icon, row, text}; -use rune_theme_opencode::icons as ic; -use opencode_ui::palette::Pal; +use opencode_ui::focus::FocusExt; +use opencode_ui::keymap::Bind; +use opencode_ui::palette::{Elevate as _, Pal}; use opencode_ui::style::{INSTANT, UI}; +use rune::{El, Key, KeyEvent, Shadow, TextEdit, TextStyle, Transition, Tx, icon, row, text}; +use rune_theme_opencode::icons as ic; use terminal::TerminalSnapshot; use crate::{TerminalSurfaceHost, TerminalTab, ops}; @@ -36,6 +39,17 @@ fn close(host: &mut dyn TerminalSurfaceHost, wk: &str, tid: &str, tx: &mut Tx) { ops::focus_terminal_surface(host); } +fn step(host: &mut dyn TerminalSurfaceHost, wk: &str, tid: &str, older: bool, tx: &mut Tx) { + tx.instant(); + if let Some(t) = ops::terminal_tab_mut(host, wk, tid) { + if let Some(field) = t.find.as_mut() { + field.focused = true; + } + t.session.find_step(older); + } + tx.focus("terminal-find-input", false); +} + fn on_change(host: &mut dyn TerminalSurfaceHost, wk: &str, tid: &str, tx: &mut Tx) { tx.instant(); if let Some(t) = ops::terminal_tab_mut(host, wk, tid) { @@ -49,6 +63,16 @@ fn key(host: &mut dyn TerminalSurfaceHost, wk: &str, tid: &str, ev: &KeyEvent, t if t.find.as_ref().is_some_and(TextEdit::is_composing) { return false; } + if Bind::FindNext.matches_tx(ev, tx) { + tx.instant(); + t.session.find_step(true); + return true; + } + if Bind::FindPrev.matches_tx(ev, tx) { + tx.instant(); + t.session.find_step(false); + return true; + } let m = ev.mods; match ev.key { Key::Escape => { @@ -74,60 +98,117 @@ pub fn bar( ) -> Option { let field = tab.find.as_ref()?; let view = snap.find.as_ref(); + let total = view.map_or(0, |v| v.total); let count = (!field.text.is_empty()).then(|| { - let total = view.map_or(0, |v| v.total); let shown = view.and_then(|v| v.selected).map_or(0, |i| i + 1); text(format!("{shown}/{total}")).key("terminal-find-count").font(COUNT).color(p.muted) }); let (wk_edit, tid_edit) = (wk.to_owned(), tab.id.clone()); let (wk_change, tid_change) = (wk.to_owned(), tab.id.clone()); let (wk_key, tid_key) = (wk.to_owned(), tab.id.clone()); + let (wk_prev, tid_prev) = (wk.to_owned(), tab.id.clone()); + let (wk_next, tid_next) = (wk.to_owned(), tab.id.clone()); let (wk_close, tid_close) = (wk.to_owned(), tab.id.clone()); let input = field_shell(p, field) .on_edit(move |s: &mut H| s.terminal_mut().find_field_mut(&wk_edit, &tid_edit)) .on_input_change(move |s: &mut H, tx: &mut Tx| on_change(s, &wk_change, &tid_change, tx)) .on_input_key(move |s: &mut H, ev: &KeyEvent, tx: &mut Tx| key(s, &wk_key, &tid_key, ev, tx)); + let enabled = total > 0; + let prev_btn = { + let b = step_button_shell(p, true, enabled); + if enabled { + b.on_press_tx(move |s: &mut H, tx: &mut Tx| step(s, &wk_prev, &tid_prev, false, tx)) + } else { + b + } + }; + let next_btn = { + let b = step_button_shell(p, false, enabled); + if enabled { + b.on_press_tx(move |s: &mut H, tx: &mut Tx| step(s, &wk_next, &tid_next, true, tx)) + } else { + b + } + }; let close_btn = close_button_shell(p) .on_press_tx(move |s: &mut H, tx: &mut Tx| close(s, &wk_close, &tid_close, tx)); - Some(bar_shell(p, field.focused, input, count, close_btn)) + Some(bar_shell(p, field.focused, input, count, [prev_btn, next_btn], close_btn)) } fn field_shell(p: &Pal, field: &TextEdit) -> El { - opencode_ui::style::field(field, UI) + opencode_ui::style::field(field, UI.lh(20.0)) .key("terminal-find-input") .single_line() .truncate_fade() .grow(1.0) .shrink() .min_w(0.0) - .h(20.0) .color(p.text) .placeholder(opencode_i18n::t!("rune.terminal.find"), p.faint) .caret(p.text, p.selection) .selection_style(p.field_selection) } +fn step_button_shell(p: &Pal, up: bool, enabled: bool) -> El { + let (key, label, bind) = if up { + ("terminal-find-prev", opencode_i18n::t!("ui.fileSearch.previousMatch"), Bind::FindPrev) + } else { + ("terminal-find-next", opencode_i18n::t!("ui.fileSearch.nextMatch"), Bind::FindNext) + }; + let glyph = icon(&ic::CHEVRON_DOWN, 16.0).color(p.icon_muted); + let glyph = if up { glyph.rotate(std::f32::consts::PI) } else { glyph }; + let b = row() + .key(key) + .role("button") + .label_static(label) + .help(label) + .help_keys(bind.keycaps()) + .size(20.0, 20.0) + .center() + .radius(4.0) + .preserve_focus_on_press(true) + .child(glyph); + if enabled { + b.focus_inset(p).hover(p.hover).press(p.pressed).hover_motion(INSTANT, INSTANT) + } else { + b.opacity(0.4).disabled(true).focusable(false) + } +} + fn close_button_shell(p: &Pal) -> El { + let close_label = opencode_i18n::t!("ui.common.close"); row() .key("terminal-find-close") .role("button") - .label_static(opencode_i18n::t!("common.close")) + .label_static(close_label) + .help(close_label) + .help_keys([opencode_i18n::t!("common.key.esc")]) .size(20.0, 20.0) .center() - .radius(2.0) + .radius(4.0) + .focus_inset(p) .hover(p.hover) .press(p.pressed) .hover_motion(INSTANT, INSTANT) .child(icon(&ic::XMARK_SMALL, 16.0).color(p.icon_muted)) } -fn bar_shell(p: &Pal, focused: bool, input: El, count: Option, close_btn: El) -> El { +fn bar_shell(p: &Pal, focused: bool, input: El, count: Option, steps: [El; 2], close_btn: El) -> El { let bar = row().key("terminal-find"); - let bar = if focused { bar.border(1.0, p.v2.border_focus) } else { bar.box_shadow(Pal::ring_out(p.border)) }; + let bar = match opencode_ui::palette::kit(p).forced { + Some(highlight) => { + let bar = bar.box_shadow(Shadow { spread: 1.0, color: p.text, ..Shadow::default() }); + if focused { bar.outline(2.0, 2.0, highlight) } else { bar } + } + None if focused => bar + .elevate(p.floating) + .box_shadow(Shadow { spread: 1.0, color: p.v2.border_focus, ..Shadow::default() }), + None => bar.elevate(p.floating), + }; bar.transition(Transition::none()) .pin(None, Some(8.0), Some(8.0), None) .h(28.0) - .w(220.0) + .w(240.0) .pl(8.0) .pr(4.0) .gap(8.0) @@ -146,5 +227,5 @@ fn bar_shell(p: &Pal, focused: bool, input: El, count: Option, close_btn: El .child(input), ) .children(count) - .child(close_btn) + .child(row().key("terminal-find-actions").center_y().children(steps).child(close_btn)) } diff --git a/features/terminal-surface/src/osc8.rs b/features/terminal-surface/src/osc8.rs index 872b52509..e2755d351 100644 --- a/features/terminal-surface/src/osc8.rs +++ b/features/terminal-surface/src/osc8.rs @@ -4,10 +4,11 @@ //! opens — preventing ANSI hyperlink spoofing. use opencode_i18n::t; +use opencode_ui::focus::FocusExt; use opencode_ui::palette::{Elevate as _, Pal, kit}; -use opencode_ui::style::{CODE, UI}; +use opencode_ui::style::{UI, UI_SMALL}; use opencode_ui::widgets::{DialogSize, Fit, button, dialog_window, sized}; -use rune::{Cx, Direction, El, TextStyle, Tx, col, el, row, text}; +use rune::{Cx, Direction, El, Spring, SpringPair, TextStyle, Transition, Tx, col, el, row, text}; use rune_kit::ButtonVariant; use crate::{FocusClaimEvent, TerminalSurfaceHost}; @@ -15,8 +16,14 @@ use crate::{FocusClaimEvent, TerminalSurfaceHost}; /// Kernel overlay ID for the terminal OSC 8 hyperlink confirmation modal. pub const OSC8_OVERLAY_ID: &str = "terminal.osc8"; -const TITLE: TextStyle = TextStyle::new(15.0, 500.0).lh(20.0); +const TITLE: TextStyle = TextStyle::new(15.0, 530.0).lh(20.0).tracking(-0.13); const BODY: TextStyle = UI.lh(18.0); +const CODE_TARGET: TextStyle = UI_SMALL.mono().lh(18.0); +const CODE_DOMAIN: TextStyle = TextStyle::new(12.0, 530.0).mono().lh(18.0); + +fn modal_springs() -> SpringPair { + SpringPair::new(Spring::new(0.15, 0.0), Spring::new(0.12, 0.0)) +} /// An OSC 8 link click waiting on user confirmation. #[derive(Clone, Debug)] @@ -28,15 +35,13 @@ pub struct Pending { } /// Opens the confirmation modal for an OSC 8 terminal hyperlink. -pub fn ask(host: &mut dyn TerminalSurfaceHost, pending: Pending, tx: &mut Tx) { - tx.instant(); +pub fn ask(host: &mut dyn TerminalSurfaceHost, pending: Pending, _tx: &mut Tx) { host.terminal_mut().pending_osc8 = Some(pending); host.on_overlay_opened(OSC8_OVERLAY_ID, None); } /// Handles Cancel (`false`) or Open (`true`) on the OSC 8 confirmation modal. pub fn answer(host: &mut dyn TerminalSurfaceHost, open: bool, tx: &mut Tx) { - tx.instant(); let Some(p) = host.terminal_mut().pending_osc8.take() else { return }; host.on_overlay_closed(OSC8_OVERLAY_ID); if open { @@ -63,47 +68,51 @@ pub fn dialog(s: &H, p: &Pal, cx: &Cx) -> V .on_press_tx(|s: &mut H, tx: &mut Tx| answer(s, false, tx)) .build(k) .key("terminal-osc8-cancel") + .focus_default(p) .autofocus(); let confirm = button(t!("rune.terminal.link.open"), ButtonVariant::Contrast) .on_press_tx(|s: &mut H, tx: &mut Tx| answer(s, true, tx)) .build(k) - .key("terminal-osc8-confirm"); + .key("terminal-osc8-confirm") + .focus_default(p); let display = browser_policy::format_osc8_target(&pending.url); let mut target_box = col() .key("terminal-osc8-target") .w_full() - .padding(8.0) + .padding(10.0) .gap(4.0) - .radius(4.0) + .radius(6.0) .fill(p.layer2) + .box_shadow(Pal::ring_in(p.border_muted)) .clip_soft(0.0); let has_domain = !display.registrable.is_empty(); if has_domain { let mut host_row = row().key("terminal-osc8-host").dir(Direction::Ltr).w_full().min_w(0.0); if !display.host_prefix.is_empty() { - host_row = host_row.child(text(display.host_prefix).font(CODE).color(p.muted)); + host_row = host_row.child(text(display.host_prefix).font(CODE_TARGET).color(p.muted)); } host_row = host_row.child( text(display.registrable) .key("terminal-osc8-domain") - .font(TextStyle::new(CODE.size, 600.0).lh(18.0)) + .font(CODE_DOMAIN) .color(p.text), ); if !display.host_suffix.is_empty() { - host_row = host_row.child(text(display.host_suffix).font(CODE).color(p.muted)); + host_row = host_row.child(text(display.host_suffix).font(CODE_TARGET).color(p.muted)); } target_box = target_box.child(host_row); } target_box = target_box.child( text(display.url_display) .key("terminal-osc8-url") - .font(CODE) + .font(CODE_TARGET) .color(if has_domain { p.muted } else { p.text }) .dir(Direction::Ltr) .wrap(), ); + let springs = modal_springs(); let card = col() .key("terminal-osc8-dialog") .role("dialog") @@ -112,8 +121,9 @@ pub fn dialog(s: &H, p: &Pal, cx: &Cx) -> V .padding(20.0) .gap(12.0) .radius(12.0) - .fill(p.bg_base) + .fill(p.layer1) .elevate(p.overlay) + .transition(Transition::scale(0.96).combined(Transition::opacity()).springs(springs)) .child(text(t!("rune.terminal.link.confirm")).font(TITLE).color(p.text)) .child(text(t!("rune.terminal.link.description")).font(BODY).color(p.muted).wrap()) .child(target_box) @@ -121,7 +131,19 @@ pub fn dialog(s: &H, p: &Pal, cx: &Cx) -> V .modal_tx(true, |s: &mut H, tx: &mut Tx| answer(s, false, tx)); let card = sized(card, DialogSize::Normal, Fit::Content, win); vec![ - el().key("terminal-osc8-scrim").absolute(0.0, 0.0).w_full().h_full().fill(p.scrim), - el().key("terminal-osc8-modal").absolute(0.0, 0.0).w_full().h_full().center().child(card).raise(), + el().key("terminal-osc8-scrim") + .absolute(0.0, 0.0) + .w_full() + .h_full() + .fill(p.scrim) + .transition(Transition::opacity().springs(springs)), + el().key("terminal-osc8-modal") + .absolute(0.0, 0.0) + .w_full() + .h_full() + .center() + .transition(Transition::none()) + .child(card) + .raise(), ] } diff --git a/features/terminal-surface/src/paste.rs b/features/terminal-surface/src/paste.rs index 23cd000c4..73d272fe6 100644 --- a/features/terminal-surface/src/paste.rs +++ b/features/terminal-surface/src/paste.rs @@ -11,24 +11,31 @@ //! by line as it arrives; Ghostty's own `clipboard-paste-protection` asks in the same cases. use opencode_i18n::t; -use opencode_ui::widgets::{BODY, DialogSize, Fit, button, dialog_window, sized}; -use rune::{Cx, El, Family, TextStyle, Tx, col, el, row, spacer, text}; -use rune_kit::ButtonVariant; +use opencode_ui::focus::FocusExt; use opencode_ui::palette::{Elevate as _, Pal, kit}; +use opencode_ui::style::{UI, UI_SMALL}; +use opencode_ui::widgets::{DialogSize, Fit, button, dialog_window, sized}; +use rune::{Cx, El, Spring, SpringPair, TextStyle, Transition, Tx, col, el, row, spacer, text}; +use rune_kit::ButtonVariant; use crate::{FocusClaimEvent, TerminalSurfaceHost, ops}; pub const PASTE_OVERLAY_ID: &str = "dialog.terminal.paste"; -/// `dialog-title`: 15 on 20 at 530, as the session delete confirmation's. +/// `dialog-title`: 15 on 20 at 530, matching confirmation dialog titles. const TITLE: TextStyle = TextStyle::new(15.0, 530.0).lh(20.0).tracking(-0.13); +const BODY: TextStyle = UI.lh(18.0); /// The pasted lines, in the code font. -const CODE: TextStyle = TextStyle::new(12.0, 400.0).lh(18.0).family(Family::Mono); +const CODE: TextStyle = UI_SMALL.mono().lh(18.0); /// Lines of a paste the question shows. const SHOWN_LINES: usize = 8; /// Characters of each shown line. const SHOWN_CHARS: usize = 120; +fn modal_springs() -> SpringPair { + SpringPair::new(Spring::new(0.15, 0.0), Spring::new(0.12, 0.0)) +} + /// What a paste does: goes to the program as this text, or waits for the user. #[derive(Debug, PartialEq, Eq)] pub enum Paste { @@ -82,7 +89,7 @@ fn shown(text: &str) -> (Vec, usize) { } /// Pastes `text` into terminal `tab`, or asks first ([`judge`]). -pub fn paste_into_terminal(host: &mut dyn TerminalSurfaceHost, ws: &str, tab: &str, text: String, tx: &mut Tx) { +pub fn paste_into_terminal(host: &mut dyn TerminalSurfaceHost, ws: &str, tab: &str, text: String, _tx: &mut Tx) { let now = host.clock(); let Some(bracketed) = ops::terminal_tab_mut(host, ws, tab).map(|t| t.session.snapshot().bracketed_paste) else { return; @@ -98,7 +105,6 @@ pub fn paste_into_terminal(host: &mut dyn TerminalSurfaceHost, ws: &str, tab: &s host.terminal_mut().reset_blink(now); } Paste::Ask => { - tx.instant(); host.terminal_mut().pending_paste = Some(Pending { ws: ws.to_owned(), tab: tab.to_owned(), text }); host.on_overlay_opened(PASTE_OVERLAY_ID, None); } @@ -106,8 +112,7 @@ pub fn paste_into_terminal(host: &mut dyn TerminalSurfaceHost, ws: &str, tab: &s } /// The answer to the paste question: send it (without its last line break) or drop it. -pub fn answer_paste(host: &mut dyn TerminalSurfaceHost, send: bool, tx: &mut Tx) { - tx.instant(); +pub fn answer_paste(host: &mut dyn TerminalSurfaceHost, send: bool, _tx: &mut Tx) { let Some(p) = host.terminal_mut().pending_paste.take() else { return }; host.on_overlay_closed(PASTE_OVERLAY_ID); if send && let Some(t) = ops::terminal_tab_mut(host, &p.ws, &p.tab) { @@ -116,8 +121,8 @@ pub fn answer_paste(host: &mut dyn TerminalSurfaceHost, send: bool, tx: &mut Tx) drop(host.terminal_mut().focus_claim.step(FocusClaimEvent::Request)); } -/// The question a paste that would run commands asks, over the window (the session delete -/// confirmation's dialog: the normal size, title, description, footer with Cancel focused). +/// The question a paste that would run commands asks, over the window (`DialogSize::Normal`, +/// `Fit::Content`, `12 pt` confirmation surface with smooth scrim/scale transition). pub fn dialog(s: &H, p: &Pal, cx: &Cx) -> Vec { let Some(pending) = &s.terminal().pending_paste else { return Vec::new() }; let win = dialog_window(cx, s.zoom()); @@ -126,21 +131,37 @@ pub fn dialog(s: &H, p: &Pal, cx: &Cx) -> V fn dialog_for(pending: &Pending, p: &Pal, win: [f32; 2]) -> Vec { let k = kit(p); + let springs = modal_springs(); let cancel = button(t!("common.cancel"), ButtonVariant::Ghost) .on_press_tx(|s: &mut H, tx: &mut Tx| answer_paste(s, false, tx)) .build(k) .key("terminal-paste-cancel") + .focus_default(p) .autofocus(); let paste = button(t!("rune.terminal.paste.confirm"), ButtonVariant::Contrast) .on_press_tx(|s: &mut H, tx: &mut Tx| answer_paste(s, true, tx)) .build(k) - .key("terminal-paste-confirm"); + .key("terminal-paste-confirm") + .focus_default(p); let card = build_card_shell(pending, p, cancel, paste) + .transition(Transition::scale(0.96).combined(Transition::opacity()).springs(springs)) .modal_tx(true, |s: &mut H, tx: &mut Tx| answer_paste(s, false, tx)); let card = sized(card, DialogSize::Normal, Fit::Content, win); vec![ - el().key("terminal-paste-scrim").absolute(0.0, 0.0).w_full().h_full().fill(p.scrim), - el().key("terminal-paste-modal").absolute(0.0, 0.0).w_full().h_full().center().child(card).raise(), + el().key("terminal-paste-scrim") + .absolute(0.0, 0.0) + .w_full() + .h_full() + .fill(p.scrim) + .transition(Transition::opacity().springs(springs)), + el().key("terminal-paste-modal") + .absolute(0.0, 0.0) + .w_full() + .h_full() + .center() + .transition(Transition::none()) + .child(card) + .raise(), ] } @@ -154,9 +175,10 @@ fn build_card_shell(pending: &Pending, p: &Pal, cancel: El, paste: El) -> El { let mut preview = col() .key("terminal-paste-preview") .w_full() - .padding(8.0) - .radius(4.0) + .padding(10.0) + .radius(6.0) .fill(p.layer2) + .box_shadow(Pal::ring_in(p.border_muted)) .clip_soft(0.0); for (i, line) in lines.iter().enumerate() { preview = preview.child(text(line.clone()).key(format!("terminal-paste-line-{i}")).font(CODE).color(p.text).truncate()); @@ -172,19 +194,15 @@ fn build_card_shell(pending: &Pending, p: &Pal, cancel: El, paste: El) -> El { .key("terminal-paste-card") .role("alertdialog") .label(title.clone()) - .radius(6.0) + .w_full() + .padding(20.0) + .gap(12.0) + .radius(12.0) .fill(p.layer1) .elevate(p.overlay) .clip_soft(0.0) - .child( - col() - .key("terminal-paste-header") - .w_full() - .padding(16.0) - .gap(8.0) - .child(text(title).font(TITLE).color(p.text)) - .child(text(t!("rune.terminal.paste.description")).font(BODY).color(p.muted).wrap().w_full()) - .child(preview), - ) - .child(row().key("terminal-paste-footer").w_full().padding(16.0).gap(8.0).child(spacer()).child(cancel).child(paste)) + .child(text(title).font(TITLE).color(p.text)) + .child(text(t!("rune.terminal.paste.description")).font(BODY).color(p.muted).wrap().w_full()) + .child(preview) + .child(row().key("terminal-paste-footer").w_full().gap(8.0).pt(4.0).child(spacer()).child(cancel).child(paste)) } From 27302b9ae986c15c2ffb874fdaf40ec6a528cd07 Mon Sep 17 00:00:00 2001 From: Kit Langton Date: Sat, 5 Dec 2026 21:57:05 -0800 Subject: [PATCH 2/2] fix(terminal): animate modal wrapper exit for paste and osc8 dialogs --- features/terminal-surface/src/osc8.rs | 18 ++++++++++++++---- features/terminal-surface/src/paste.rs | 24 +++++++++++++++++------- 2 files changed, 31 insertions(+), 11 deletions(-) diff --git a/features/terminal-surface/src/osc8.rs b/features/terminal-surface/src/osc8.rs index e2755d351..81a9540e6 100644 --- a/features/terminal-surface/src/osc8.rs +++ b/features/terminal-surface/src/osc8.rs @@ -25,6 +25,15 @@ fn modal_springs() -> SpringPair { SpringPair::new(Spring::new(0.15, 0.0), Spring::new(0.12, 0.0)) } +fn modal_transition(reduced: bool) -> Transition { + let springs = modal_springs(); + if reduced { + Transition::opacity().springs(springs) + } else { + Transition::scale(0.96).combined(Transition::opacity()).springs(springs) + } +} + /// An OSC 8 link click waiting on user confirmation. #[derive(Clone, Debug)] pub struct Pending { @@ -43,6 +52,7 @@ pub fn ask(host: &mut dyn TerminalSurfaceHost, pending: Pending, _tx: &mut Tx) { /// Handles Cancel (`false`) or Open (`true`) on the OSC 8 confirmation modal. pub fn answer(host: &mut dyn TerminalSurfaceHost, open: bool, tx: &mut Tx) { let Some(p) = host.terminal_mut().pending_osc8.take() else { return }; + tx.animated(); host.on_overlay_closed(OSC8_OVERLAY_ID); if open { if browser_policy::is_http_with_credentials(&p.url) { @@ -112,7 +122,7 @@ pub fn dialog(s: &H, p: &Pal, cx: &Cx) -> V .wrap(), ); - let springs = modal_springs(); + let reduced = s.reduced_motion() || cx.system_reduced_motion(); let card = col() .key("terminal-osc8-dialog") .role("dialog") @@ -123,7 +133,7 @@ pub fn dialog(s: &H, p: &Pal, cx: &Cx) -> V .radius(12.0) .fill(p.layer1) .elevate(p.overlay) - .transition(Transition::scale(0.96).combined(Transition::opacity()).springs(springs)) + .transition(Transition::none()) .child(text(t!("rune.terminal.link.confirm")).font(TITLE).color(p.text)) .child(text(t!("rune.terminal.link.description")).font(BODY).color(p.muted).wrap()) .child(target_box) @@ -136,13 +146,13 @@ pub fn dialog(s: &H, p: &Pal, cx: &Cx) -> V .w_full() .h_full() .fill(p.scrim) - .transition(Transition::opacity().springs(springs)), + .transition(Transition::opacity().springs(modal_springs())), el().key("terminal-osc8-modal") .absolute(0.0, 0.0) .w_full() .h_full() .center() - .transition(Transition::none()) + .transition(modal_transition(reduced)) .child(card) .raise(), ] diff --git a/features/terminal-surface/src/paste.rs b/features/terminal-surface/src/paste.rs index 73d272fe6..5307897b2 100644 --- a/features/terminal-surface/src/paste.rs +++ b/features/terminal-surface/src/paste.rs @@ -36,6 +36,15 @@ fn modal_springs() -> SpringPair { SpringPair::new(Spring::new(0.15, 0.0), Spring::new(0.12, 0.0)) } +fn modal_transition(reduced: bool) -> Transition { + let springs = modal_springs(); + if reduced { + Transition::opacity().springs(springs) + } else { + Transition::scale(0.96).combined(Transition::opacity()).springs(springs) + } +} + /// What a paste does: goes to the program as this text, or waits for the user. #[derive(Debug, PartialEq, Eq)] pub enum Paste { @@ -112,8 +121,9 @@ pub fn paste_into_terminal(host: &mut dyn TerminalSurfaceHost, ws: &str, tab: &s } /// The answer to the paste question: send it (without its last line break) or drop it. -pub fn answer_paste(host: &mut dyn TerminalSurfaceHost, send: bool, _tx: &mut Tx) { +pub fn answer_paste(host: &mut dyn TerminalSurfaceHost, send: bool, tx: &mut Tx) { let Some(p) = host.terminal_mut().pending_paste.take() else { return }; + tx.animated(); host.on_overlay_closed(PASTE_OVERLAY_ID); if send && let Some(t) = ops::terminal_tab_mut(host, &p.ws, &p.tab) { t.session.paste(without_last_break(&p.text).to_owned()); @@ -126,12 +136,12 @@ pub fn answer_paste(host: &mut dyn TerminalSurfaceHost, send: bool, _tx: &mut Tx pub fn dialog(s: &H, p: &Pal, cx: &Cx) -> Vec { let Some(pending) = &s.terminal().pending_paste else { return Vec::new() }; let win = dialog_window(cx, s.zoom()); - dialog_for::(pending, p, win) + let reduced = s.reduced_motion() || cx.system_reduced_motion(); + dialog_for::(pending, p, win, reduced) } -fn dialog_for(pending: &Pending, p: &Pal, win: [f32; 2]) -> Vec { +fn dialog_for(pending: &Pending, p: &Pal, win: [f32; 2], reduced: bool) -> Vec { let k = kit(p); - let springs = modal_springs(); let cancel = button(t!("common.cancel"), ButtonVariant::Ghost) .on_press_tx(|s: &mut H, tx: &mut Tx| answer_paste(s, false, tx)) .build(k) @@ -144,7 +154,7 @@ fn dialog_for(pending: &Pending, p: &Pal, win: .key("terminal-paste-confirm") .focus_default(p); let card = build_card_shell(pending, p, cancel, paste) - .transition(Transition::scale(0.96).combined(Transition::opacity()).springs(springs)) + .transition(Transition::none()) .modal_tx(true, |s: &mut H, tx: &mut Tx| answer_paste(s, false, tx)); let card = sized(card, DialogSize::Normal, Fit::Content, win); vec![ @@ -153,13 +163,13 @@ fn dialog_for(pending: &Pending, p: &Pal, win: .w_full() .h_full() .fill(p.scrim) - .transition(Transition::opacity().springs(springs)), + .transition(Transition::opacity().springs(modal_springs())), el().key("terminal-paste-modal") .absolute(0.0, 0.0) .w_full() .h_full() .center() - .transition(Transition::none()) + .transition(modal_transition(reduced)) .child(card) .raise(), ]