mirror of
https://github.com/storytold/wordcraft.git
synced 2026-11-25 21:19:50 +00:00
This commit is contained in:
@@ -81,6 +81,7 @@ impl WordApp {
|
||||
let mode = self.screen_mode();
|
||||
let dropped = self.ribbon_dropped;
|
||||
let key = self.windows.window_key();
|
||||
let ribbon_out = std::cell::RefCell::new(None);
|
||||
let shell = AppShell::new(key)
|
||||
.mode_set(ScreenModeSet::Document)
|
||||
.screen_mode(Bind::given(mode))
|
||||
@@ -94,12 +95,12 @@ impl WordApp {
|
||||
// tabs and collapsed every one of them.
|
||||
.top(Slot::new("ribbonDrop").drops().size(SlotSize::Content), |ui, _cx, app: &mut WordApp| {
|
||||
if !stale(app) {
|
||||
ribbon_slot(app, ui);
|
||||
*ribbon_out.borrow_mut() = Some(ribbon::show(app, ui));
|
||||
}
|
||||
})
|
||||
.top(Slot::new("ribbon").size(SlotSize::Content), |ui, _cx, app: &mut WordApp| {
|
||||
if !stale(app) {
|
||||
ribbon_slot(app, ui);
|
||||
*ribbon_out.borrow_mut() = Some(ribbon::show(app, ui));
|
||||
}
|
||||
})
|
||||
// As tall as the bar: a failure's line under the message puts Install below the first line, and a slot of
|
||||
@@ -132,6 +133,11 @@ impl WordApp {
|
||||
self.follow_screen_mode(out.screen_mode);
|
||||
}
|
||||
self.ribbon_dropped = out.dropped;
|
||||
// Keytips run outside the ribbon slots so legacy sequences and their hint still work when
|
||||
// no ribbon shows (Focus, Full Screen View) and anchor under the slim screen bar.
|
||||
let ribbon = ribbon_out.into_inner().unwrap_or_else(ribbon::no_ribbon);
|
||||
let screen_bar = out.regions.slots.iter().find(|(slot, _)| *slot == "screenBar").map(|(_, rect)| *rect);
|
||||
crate::keytips::show(ui, self, &ribbon, screen_bar);
|
||||
out.regions
|
||||
}
|
||||
|
||||
@@ -156,9 +162,3 @@ impl WordApp {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The ribbon, then its keytips, in a top slot: the keytips read what the ribbon recorded this pass.
|
||||
fn ribbon_slot(app: &mut WordApp, ui: &mut egui::Ui) {
|
||||
let out = ribbon::show(app, ui);
|
||||
crate::keytips::show(ui, app, &out);
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
use craft::behavior::IconId;
|
||||
use craft::ui::buttons::IconButton;
|
||||
use craft::ui::contract::{BodyCx, Props as _, Show as _, TooltipSpec};
|
||||
use craft::ui::runtime::inspect;
|
||||
use egui::Ui;
|
||||
use serde_json::json;
|
||||
|
||||
@@ -11,9 +10,9 @@ use super::Screen;
|
||||
use crate::WordApp;
|
||||
|
||||
/// Fills the screen-bar slot. Focus: a `more` button that drops the ribbon down over the page. Immersive: the
|
||||
/// command search field. The bar is an inspected region, where the keytips hang their hint while no ribbon shows.
|
||||
/// command search field.
|
||||
pub(crate) fn show(ui: &mut Ui, _cx: &mut BodyCx<'_>, app: &mut WordApp) {
|
||||
inspect::record(ui, crate::keytips::screen_bar_region(), |ui| match Screen::of(&app.session.view) {
|
||||
match Screen::of(&app.session.view) {
|
||||
Screen::Focus => {
|
||||
let out = IconButton::new(IconId::new("wordcraft.more"))
|
||||
.label(tl!("Show the ribbon").to_string())
|
||||
@@ -27,5 +26,5 @@ pub(crate) fn show(ui: &mut Ui, _cx: &mut BodyCx<'_>, app: &mut WordApp) {
|
||||
_ => {
|
||||
super::search::show(app, ui, false);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
use craft::behavior::overlay::MinWidth;
|
||||
use craft::keymap::CommandRef;
|
||||
use craft::menu::{KeytipControl, Keytips, RibbonOutput};
|
||||
use craft::ui::contract::Bind;
|
||||
@@ -33,12 +34,6 @@ pub(crate) fn backstage_region() -> egui::Id {
|
||||
egui::Id::unique("wc_keytips_backstage_region")
|
||||
}
|
||||
|
||||
/// The key of the inspected region the screen bar (Focus, Full Screen View) records; the legacy hint hangs from
|
||||
/// its first element when no ribbon shows.
|
||||
pub(crate) fn screen_bar_region() -> egui::Id {
|
||||
egui::Id::unique("wc_keytips_screen_bar_region")
|
||||
}
|
||||
|
||||
/// Word's tab letters, as Word for Windows shows them after Alt (File F, Design G, References S,
|
||||
/// Review R, View W, Help Y). File opens the Backstage.
|
||||
const TAB_LETTERS: [(&str, &str); 11] = [
|
||||
@@ -417,8 +412,8 @@ fn backstage_rows() -> Vec<Row> {
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// Shows the keytips after the ribbon and the regions they place badges on, and acts on what the keys chose.
|
||||
pub(crate) fn show(ui: &mut Ui, app: &mut WordApp, ribbon: &RibbonOutput<String>) {
|
||||
/// Shows the keytips after the shell and the regions they place badges on, and acts on what the keys chose.
|
||||
pub(crate) fn show(ui: &mut Ui, app: &mut WordApp, ribbon: &RibbonOutput<String>, screen_bar: Option<Rect>) {
|
||||
let ctx = ui.ctx().clone();
|
||||
// Alt during an object drag is part of the drag (Alt moves an object freely), not a keytip tap.
|
||||
// PLAN: `CanvasState::object_gesture` is canvas-w9's (cv.A10).
|
||||
@@ -471,7 +466,6 @@ pub(crate) fn show(ui: &mut Ui, app: &mut WordApp, ribbon: &RibbonOutput<String>
|
||||
}
|
||||
if let Some(pending) = &out.pending {
|
||||
// With no ribbon showing (Focus, Full Screen View) the hint hangs under the screen bar.
|
||||
let screen_bar = inspect::recorded(&ctx, screen_bar_region()).and_then(|r| r.rect_in(&ctx, 0, ui.layer_id()));
|
||||
if let Some(anchor) = ribbon.tabs.or(screen_bar) {
|
||||
legacy_hint(ui, pending, anchor);
|
||||
}
|
||||
@@ -483,9 +477,11 @@ fn legacy_hint(ui: &mut Ui, pending: &str, anchor: Rect) {
|
||||
let keys: Vec<String> = pending.chars().map(String::from).collect();
|
||||
let text = crate::i18n::fmt(tl!("Old menu keys: Alt, {keys}. Keep typing, or press Esc to cancel."), &[("keys", &keys.join(", "))]);
|
||||
let mut open = true;
|
||||
Popover::new(tl!("Old menu keys"), Bind::bound(&mut open)).overlay(|overlay| overlay.anchor(Anchor::Rect(anchor))).show(ui, |ui, _| {
|
||||
Text::new(text.clone()).show(ui);
|
||||
});
|
||||
Popover::new(tl!("Old menu keys"), Bind::bound(&mut open))
|
||||
.overlay(|overlay| overlay.anchor(Anchor::Rect(anchor)).min_width(MinWidth::None))
|
||||
.show(ui, |ui, _| {
|
||||
Text::new(text.clone()).show(ui);
|
||||
});
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
@@ -96,6 +96,88 @@ fn legacy_menu_keys_stay_off_the_ribbon_letters_and_all_resolve() {
|
||||
}
|
||||
}
|
||||
|
||||
/// #1697 review: with no ribbon showing (Focus, Full Screen View) no tab rects are recorded,
|
||||
/// so the legacy hint hangs under the slim screen bar at the top of the window instead of not
|
||||
/// showing; with the ribbon showing (normal window or dropped ribbon in Focus) it hangs under
|
||||
/// the tab row.
|
||||
#[test]
|
||||
fn the_legacy_hint_hangs_under_the_slim_bar_without_a_ribbon() {
|
||||
use egui::accesskit::Role;
|
||||
use egui_kittest::kittest::Queryable as _;
|
||||
if cfg!(target_os = "macos") {
|
||||
return;
|
||||
}
|
||||
let trigger_legacy_v = |h: &mut egui_kittest::Harness<'static, WordApp>| {
|
||||
h.input_mut().events.push(key_event(egui::Key::F10, true, egui::Modifiers::NONE));
|
||||
crate::test_harness::frame(h);
|
||||
h.input_mut().events.extend([key_event(egui::Key::V, true, egui::Modifiers::NONE), egui::Event::Text("v".into())]);
|
||||
crate::test_harness::frames(h, 2);
|
||||
};
|
||||
let cancel = |h: &mut egui_kittest::Harness<'static, WordApp>| {
|
||||
h.input_mut().events.push(key_event(egui::Key::Escape, true, egui::Modifiers::NONE));
|
||||
crate::test_harness::frames(h, 2);
|
||||
};
|
||||
|
||||
let mut h = harness(app());
|
||||
let home_tab = h.get_by_label("Home").rect();
|
||||
trigger_legacy_v(&mut h);
|
||||
assert!(h.state().keytips_active, "F10, V enters legacy keytip wait with the ribbon showing");
|
||||
assert!(h.query_by_label("Old menu keys: Alt, V. Keep typing, or press Esc to cancel.").is_some(), "hint displays pending Alt, V sequence");
|
||||
let ribbon_hint = h.get_by_role_and_label(Role::Dialog, "Old menu keys").rect();
|
||||
assert!(ribbon_hint.top() >= home_tab.bottom() - 1.0, "legacy hint {ribbon_hint:?} hangs under the ribbon tab row {home_tab:?}");
|
||||
cancel(&mut h);
|
||||
assert!(!h.state().keytips_active, "Escape ends legacy keytips");
|
||||
assert!(h.query_by_role_and_label(Role::Dialog, "Old menu keys").is_none(), "hint closes on Escape");
|
||||
|
||||
// Focus hides the ribbon and shows the slim screen bar at the top.
|
||||
h.state_mut().run("view.focus", serde_json::json!({})).unwrap();
|
||||
crate::test_harness::frames(&mut h, 3);
|
||||
assert!(h.query_by_label("Insert").is_none(), "Focus hides the ribbon");
|
||||
let focus_bar = h.get_by_label("Show the ribbon").rect();
|
||||
trigger_legacy_v(&mut h);
|
||||
assert!(h.state().keytips_active, "F10, V activates legacy keytips in Focus mode");
|
||||
let focus_hint = h.get_by_role_and_label(Role::Dialog, "Old menu keys").rect();
|
||||
assert!(
|
||||
focus_hint.top() >= focus_bar.bottom() - 1.0 && focus_hint.top() < ribbon_hint.top(),
|
||||
"Focus legacy hint {focus_hint:?} hangs under the slim screen bar {focus_bar:?} (above ribbon hint {ribbon_hint:?})"
|
||||
);
|
||||
assert!(focus_hint.width() < 720.0, "Focus hint {focus_hint:?} sizes to its content rather than stretching across the screen bar");
|
||||
cancel(&mut h);
|
||||
assert!(!h.state().keytips_active, "Escape ends legacy keytips in Focus");
|
||||
assert!(h.state().session.view.focus_mode, "Escape cancelling legacy keytips keeps Focus active");
|
||||
|
||||
// When Focus drops the ribbon down, the tab row wins over the screen bar.
|
||||
h.state_mut().run("ui.focusRibbon", serde_json::json!({"value": true})).unwrap();
|
||||
crate::test_harness::frames(&mut h, 3);
|
||||
let dropped_tab = h.get_by_label("Home").rect();
|
||||
trigger_legacy_v(&mut h);
|
||||
let dropped_hint = h.get_by_role_and_label(Role::Dialog, "Old menu keys").rect();
|
||||
assert!(
|
||||
dropped_hint.top() >= dropped_tab.bottom() - 1.0 && dropped_hint.top() > focus_hint.top(),
|
||||
"dropped-ribbon hint {dropped_hint:?} hangs under the dropped tab row {dropped_tab:?}"
|
||||
);
|
||||
cancel(&mut h);
|
||||
|
||||
// Full Screen View hides the ribbon and shows the slim screen bar with Search.
|
||||
h.state_mut().run("view.focus", serde_json::json!({})).unwrap();
|
||||
h.state_mut().run("view.fullScreenView", serde_json::json!({})).unwrap();
|
||||
crate::test_harness::frames(&mut h, 3);
|
||||
assert!(h.query_by_label("Insert").is_none(), "Full Screen View hides the ribbon");
|
||||
let search_bar = h.get_by_label("Search commands and help").rect();
|
||||
trigger_legacy_v(&mut h);
|
||||
assert!(h.state().keytips_active, "F10, V activates legacy keytips in Full Screen View");
|
||||
let fs_hint = h.get_by_role_and_label(Role::Dialog, "Old menu keys").rect();
|
||||
assert!(
|
||||
fs_hint.top() >= search_bar.bottom() - 1.0 && fs_hint.top() < ribbon_hint.top(),
|
||||
"Full Screen View legacy hint {fs_hint:?} hangs under the slim screen bar {search_bar:?} (above ribbon hint {ribbon_hint:?})"
|
||||
);
|
||||
assert!(fs_hint.width() < 720.0, "Full Screen View hint {fs_hint:?} sizes to its content rather than stretching across the screen bar");
|
||||
h.input_mut().events.extend([key_event(egui::Key::U, true, egui::Modifiers::NONE), egui::Event::Text("u".into())]);
|
||||
crate::test_harness::frames(&mut h, 3);
|
||||
assert!(!h.state().session.view.full_screen_view, "Alt/F10, V, U leaves Full Screen View");
|
||||
assert!(h.state().session.doc.plain_text(wordcraft_doc::StoryRef::Body).is_empty(), "no letter typed into the document");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn qat_keytips_follow_custom_order_and_skip_disabled_commands() {
|
||||
let mut a = app();
|
||||
|
||||
@@ -68,7 +68,7 @@ pub use tabs::{
|
||||
use view::{outlining, view};
|
||||
|
||||
/// What a pass with no ribbon reports.
|
||||
fn no_ribbon() -> RibbonOutput<String> {
|
||||
pub(crate) fn no_ribbon() -> RibbonOutput<String> {
|
||||
// PLAN: assumed `RibbonOutput::tab_ids` (S-L361) has a `Default` value; the field replaces `menu`.
|
||||
RibbonOutput { shown: None, picked: None, controls: None, tabs: None, tab_ids: Default::default() }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user