Keytips: Alt, F shows the Backstage pages' letters; Alt, F, P and Alt, F, V print (#4960) (#4981)

* Keytips: Alt, F shows the Backstage pages' letters; Alt, F, P and Alt, F, V print (#4960)

Keytips ended as soon as File opened the Backstage, so Alt, F, P and
Word's older Alt, F, V (Print Preview) did nothing. Alt, F now badges the
side menu with Word's letters (Home H, New N, Open O, Info I, Save S,
Save As A, Print P, Export E, Close C, Options T), and V opens the Print
page too, as it does in Word. A page picked this way acts as a click on
it does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Keytips: closing the Backstage ends its page letters (#4960)

The Backstage closed by its back chevron or a mouse Save while Alt, F's
badges showed left keytips waiting for a page letter. The next key was
eaten instead of typed, and picked a page with the Backstage gone: C
closed the document and S saved it. Keytips now end with the Backstage.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Keytips: keep the doc comment on works_without_document; ui-parity and ROADMAP rows (#4960)

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Brandon Thomas <echelon@gmail.com>
This commit is contained in:
Zinadin Zidan
2026-10-31 10:32:05 -04:00
committed by GitHub
co-authored by Claude Opus 5.5 Brandon Thomas
parent a2f387567d
commit c934977157
5 changed files with 175 additions and 36 deletions
+3 -1
View File
File diff suppressed because one or more lines are too long
+67 -26
View File
@@ -21,6 +21,32 @@ const PAGES: [(&str, &str, &str); 11] = [
("options", "Options", "options"),
];
/// The Backstage pages' keytips, as Word's (#4960): Alt, F, then a letter. V is Word's older
/// Print Preview key, which opens the Print page too.
const KEYTIPS: [(&str, &str); 11] = [
("home", "H"),
("new", "N"),
("open", "O"),
("info", "I"),
("save", "S"),
("saveAs", "A"),
("print", "P"),
("print", "V"),
("export", "E"),
("close", "C"),
("options", "T"),
];
/// The page a Backstage keytip letter opens.
pub(crate) fn keytip_page(letter: &str) -> Option<&'static str> {
KEYTIPS.iter().find(|(_, l)| *l == letter).map(|(page, _)| *page)
}
/// The badge a Backstage page shows while its keytips do (the first letter listed).
fn keytip_letter(page: &str) -> Option<&'static str> {
KEYTIPS.iter().find(|(p, _)| *p == page).map(|(_, l)| *l)
}
/// The Backstage back chevron's centre on macOS (#1873): beside the traffic lights in a
/// window (the title bar's content edge), at the plain control inset in full screen, where the
/// lights aren't docked top-left and the reserved offset would leave dead space.
@@ -94,33 +120,14 @@ pub fn show(app: &mut WordApp, ui: &mut Ui) {
if active { semibold(14.0) } else { medium(14.0) },
ink,
);
if on
&& app.ui.keytips == crate::keytips::Phase::Backstage
&& let Some(letter) = keytip_letter(id)
{
crate::keytips::badge(ui, Rect::from_min_size(pos2(r.min.x + 16.0, r.min.y), vec2(20.0, 16.0)), letter);
}
if resp.clicked() {
match id {
// A document without a file goes to the Save As page (as in Word) instead
// of `file.save`, which would also open the native Save As dialog.
// In the browser a save is a download, so it saves right away.
"save" if app.session.path.is_none() && app.services.download.is_none() => {
app.ui.backstage_page = "saveAs".into();
}
"save" => {
let r = app.run("file.save", json!({}));
if r.is_ok_and(|v| v.get("saved").and_then(serde_json::Value::as_bool) == Some(true) || v.get("downloaded").is_some()) {
app.ui.backstage = false;
app.canvas.want_focus = true;
} else {
app.ui.backstage_page = "saveAs".into();
}
}
"saveAs" => {
app.ui.backstage_page = "saveAs".into();
}
// Not a page: `file.close` asks Save / Don't Save / Cancel first when there
// are unsaved changes, and Cancel leaves the Backstage where it was.
"close" => {
let _ = app.run("file.close", json!({}));
}
_ => app.ui.backstage_page = id.into(),
}
go_to_page(app, id);
}
}
ui.with_layout(egui::Layout::bottom_up(egui::Align::Min), |ui| {
@@ -214,6 +221,40 @@ fn recovery_page(app: &mut WordApp, ui: &mut Ui) {
});
}
/// Opens a side-menu page, as a click on it (or its keytip) does. Without a document only the
/// pages that work without one open.
pub(crate) fn go_to_page(app: &mut WordApp, id: &str) {
if !app.has_document() && !works_without_document(id) {
return;
}
match id {
// A document without a file goes to the Save As page (as in Word) instead
// of `file.save`, which would also open the native Save As dialog.
// In the browser a save is a download, so it saves right away.
"save" if app.session.path.is_none() && app.services.download.is_none() => {
app.ui.backstage_page = "saveAs".into();
}
"save" => {
let r = app.run("file.save", json!({}));
if r.is_ok_and(|v| v.get("saved").and_then(serde_json::Value::as_bool) == Some(true) || v.get("downloaded").is_some()) {
app.ui.backstage = false;
app.canvas.want_focus = true;
} else {
app.ui.backstage_page = "saveAs".into();
}
}
"saveAs" => {
app.ui.backstage_page = "saveAs".into();
}
// Not a page: `file.close` asks Save / Don't Save / Cancel first when there
// are unsaved changes, and Cancel leaves the Backstage where it was.
"close" => {
let _ = app.run("file.close", json!({}));
}
_ => app.ui.backstage_page = id.into(),
}
}
/// The Backstage pages that work while no document is open (#1129).
fn works_without_document(page: &str) -> bool {
matches!(page, "home" | "new" | "open" | "options")
+18 -5
View File
@@ -42,6 +42,8 @@ pub enum Phase {
/// Partway through a legacy menu key sequence (#1697); the letters so far are in
/// `keytip_prefix`, and a hint stands in for the badges.
Legacy,
/// Badges over the Backstage side menu, after Alt, F (#4960).
Backstage,
}
/// Which ribbon item a letter is bound to, and what pressing it does.
@@ -602,8 +604,8 @@ pub fn handle_key(app: &mut WordApp, key: egui::Key) -> bool {
match hit {
Some(tab) => {
let _ = app.run("ui.tab", serde_json::json!({ "tab": tab }));
// File opens the Backstage: no ribbon commands to badge.
app.ui.keytips = if tab == "File" { Phase::Off } else { Phase::Commands };
// File opens the Backstage: its pages get the badges (Alt, F, P prints).
app.ui.keytips = if tab == "File" && app.ui.backstage { Phase::Backstage } else { Phase::Commands };
}
// Q is the title bar's Search box, as in Word (#819).
None if name == SEARCH_LETTER => {
@@ -622,6 +624,12 @@ pub fn handle_key(app: &mut WordApp, key: egui::Key) -> bool {
legacy_key(app, &name);
return true;
}
Phase::Backstage => {
app.ui.keytips = Phase::Off;
if let Some(page) = crate::backstage::keytip_page(&name) {
crate::backstage::go_to_page(app, page);
}
}
Phase::Commands => {
let tab = app.ui.tab.clone();
let ls = letters_for(app, &tab);
@@ -694,11 +702,16 @@ pub fn activate(app: &mut WordApp) {
use crate::keys;
/// Keytips are suppressed while the Backstage or a modal dialog is open, or while a text field
/// Keytips are suppressed while the Backstage (except for its own badges, Alt, F) or a modal dialog is open, or while a text field
/// (not the canvas) has focus; the canvas lets Alt open keytips and `canvas_events` swallows
/// typing while they show.
/// typing while they show. The Backstage's badges end with it (its back chevron, a mouse Save),
/// so the next letter is typed and never picks a page that is no longer there.
pub fn suppressed(app: &WordApp, ctx: &egui::Context) -> bool {
!app.ui.keytips_enabled || app.ui.backstage || app.dialog.is_some() || (ctx.egui_wants_keyboard_input() && !app.canvas.focused)
!app.ui.keytips_enabled
|| (app.ui.backstage && app.ui.keytips != Phase::Backstage)
|| (!app.ui.backstage && app.ui.keytips == Phase::Backstage)
|| app.dialog.is_some()
|| (ctx.egui_wants_keyboard_input() && !app.canvas.focused)
}
/// Native backends report Alt through both key and modifier events, in either order. Track
+84 -2
View File
@@ -300,12 +300,13 @@ fn keytip_state_machine() {
assert_eq!(a.ui.keytips, Phase::Commands);
assert!(handle_key(&mut a, egui::Key::F));
assert_eq!(a.ui.keytips, Phase::Off);
// Alt, F: the Backstage, and keytips end.
// Alt, F: the Backstage, with its pages' keytips (#4960).
a.ui.backstage = false;
activate(&mut a);
assert!(handle_key(&mut a, egui::Key::F));
assert!(a.ui.backstage, "Alt, F opens File");
assert_eq!(a.ui.keytips, Phase::Off);
assert_eq!(a.ui.keytips, Phase::Backstage);
a.ui.keytips = Phase::Off;
// Alt, W: View; Alt, R: Review (Word's letters, not V and S).
a.ui.backstage = false;
activate(&mut a);
@@ -541,3 +542,84 @@ fn alt_then_q_opens_search() {
assert_eq!(a.ui.keytips, Phase::Off);
assert!(matches!(a.dialog, Some(crate::dialogs::Dialog::Commands { .. })), "{:?}", a.dialog.as_ref().map(|d| d.name()));
}
/// #4960: Alt, F opens the Backstage with badges on its pages, as in Word; Alt, F, P and Word's
/// older Alt, F, V open the Print page (Print Preview). Typed through `logic`, the path real
/// keys take, which keytips used to leave as soon as the Backstage opened.
#[test]
fn file_keytips_reach_the_backstage_pages() {
let ctx = egui::Context::default();
let tap = |ctx: &egui::Context, a: &mut WordApp| {
input_frame(ctx, a, vec![key_event(egui::Key::AltLeft, true, egui::Modifiers::ALT)]);
input_frame(ctx, a, vec![key_event(egui::Key::AltLeft, false, egui::Modifiers::NONE)]);
};
let letter = |ctx: &egui::Context, a: &mut WordApp, k: egui::Key| {
input_frame(ctx, a, vec![key_event(k, true, egui::Modifiers::NONE), key_event(k, false, egui::Modifiers::NONE)]);
};
for (second, page) in [(egui::Key::P, "print"), (egui::Key::V, "print"), (egui::Key::A, "saveAs"), (egui::Key::T, "options")] {
let mut a = app();
if cfg!(target_os = "macos") {
activate(&mut a);
} else {
tap(&ctx, &mut a);
}
assert_eq!(a.ui.keytips, Phase::Tabs);
letter(&ctx, &mut a, egui::Key::F);
assert!(a.ui.backstage, "F opens the Backstage");
assert_eq!(a.ui.keytips, Phase::Backstage, "and its pages show badges");
input_frame(&ctx, &mut a, vec![]);
assert_eq!(a.ui.keytips, Phase::Backstage, "the badges stay while it waits");
letter(&ctx, &mut a, second);
assert_eq!((a.ui.backstage, a.ui.backstage_page.as_str()), (true, page), "{second:?}");
assert_eq!(a.ui.keytips, Phase::Off);
}
// A letter with no page ends the badges and leaves the Backstage open; Esc too.
for k in [egui::Key::Q, egui::Key::Escape] {
let mut a = app();
activate(&mut a);
letter(&ctx, &mut a, egui::Key::F);
let page = a.ui.backstage_page.clone();
letter(&ctx, &mut a, k);
assert_eq!((a.ui.keytips, a.ui.backstage, a.ui.backstage_page.clone()), (Phase::Off, true, page), "{k:?}");
}
assert_eq!(crate::backstage::keytip_page("P"), Some("print"));
assert_eq!(crate::backstage::keytip_page("V"), Some("print"));
assert_eq!(crate::backstage::keytip_page("R"), None);
}
/// #4981 review: the Backstage closed while its badges show (the back chevron, a mouse Save)
/// ends them. The next letter is typed, and never picks a page with the Backstage gone: C used
/// to close the document and S to save it.
#[test]
fn closing_the_backstage_ends_its_keytips() {
let mut a = app();
a.canvas.focused = true;
a.canvas.want_focus = true;
let mut h = egui_kittest::Harness::builder().with_size(egui::vec2(1440.0, 900.0)).build_ui_state(
|ui, app: &mut WordApp| {
let ctx = ui.ctx().clone();
app.logic(&ctx);
app.ui(ui);
},
a,
);
h.run_steps(4);
let key = |key| key_event(key, true, egui::Modifiers::NONE);
h.input_mut().events.push(key(egui::Key::F10));
h.step();
assert_eq!(h.state().ui.keytips, Phase::Tabs);
h.input_mut().events.extend([key(egui::Key::F), egui::Event::Text("f".into())]);
h.step();
assert_eq!((h.state().ui.backstage, h.state().ui.keytips), (true, Phase::Backstage));
// What the back chevron does.
h.state_mut().ui.backstage = false;
h.state_mut().canvas.want_focus = true;
h.run_steps(2);
assert_eq!(h.state().ui.keytips, Phase::Off, "the badges end with the Backstage");
h.input_mut().events.extend([key(egui::Key::C), egui::Event::Text("c".into())]);
h.run_steps(2);
assert_eq!(h.state().ui.keytips, Phase::Off);
assert!(h.state().has_document(), "C does not close the document");
assert!(!h.state().ui.backstage);
assert_eq!(h.state().session.doc.plain_text(wordcraft_doc::StoryRef::Body).trim(), "c", "C is typed");
}
+3 -2
View File
File diff suppressed because one or more lines are too long