mirror of
https://github.com/storytold/wordcraft.git
synced 2026-10-28 20:37:10 -06:00
This commit is contained in:
@@ -244,6 +244,7 @@ fn clipboard(app: &mut WordApp, ui: &mut Ui) {
|
||||
}
|
||||
if ui.add_enabled(!items.is_empty(), egui::Button::new(tl!("Clear All"))).clicked() {
|
||||
let _ = app.run("edit.clearClipboard", json!({}));
|
||||
app.canvas.want_focus = true;
|
||||
}
|
||||
});
|
||||
ui.add_space(4.0);
|
||||
@@ -267,6 +268,7 @@ fn clipboard(app: &mut WordApp, ui: &mut Ui) {
|
||||
ui.with_layout(egui::Layout::right_to_left(egui::Align::Min), |ui| {
|
||||
if ui.small_button(tl!("Delete")).clicked() {
|
||||
let _ = app.run("edit.deleteClipboardItem", json!({"index": i}));
|
||||
app.canvas.want_focus = true;
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -336,10 +338,12 @@ fn styles(app: &mut WordApp, ui: &mut Ui) {
|
||||
}
|
||||
if ui.button(tl!("Update to Match Selection")).clicked() {
|
||||
let _ = app.run("styles.updateToMatch", json!({"style": id}));
|
||||
app.canvas.want_focus = true;
|
||||
ui.close();
|
||||
}
|
||||
if ui.button(tl!("Delete")).clicked() {
|
||||
let _ = app.run("styles.delete", json!({"style": id}));
|
||||
app.canvas.want_focus = true;
|
||||
ui.close();
|
||||
}
|
||||
});
|
||||
@@ -739,6 +743,37 @@ mod tests {
|
||||
assert_eq!(comment_stamp("2026-10-12"), "2026-10-12");
|
||||
assert_eq!(comment_stamp(""), "");
|
||||
}
|
||||
|
||||
/// #1902: Clipboard Delete returns focus to the document like paste does.
|
||||
#[test]
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
fn clipboard_delete_returns_focus_to_the_document() {
|
||||
use egui_kittest::kittest::Queryable;
|
||||
|
||||
let mut app = crate::WordApp::new(wordcraft_engine::Session::new(wordcraft_doc::Document::from_text("Hello")), crate::Services::default());
|
||||
app.run("select.all", serde_json::json!({})).unwrap();
|
||||
app.run("edit.copy", serde_json::json!({})).unwrap();
|
||||
assert_eq!(app.session.clip_history.items().len(), 1);
|
||||
app.run("edit.clipboardPane", serde_json::json!({"value": true})).unwrap();
|
||||
let mut h = egui_kittest::Harness::builder().with_size(egui::vec2(1440.0, 900.0)).build_ui_state(
|
||||
|ui, app: &mut crate::WordApp| {
|
||||
let ctx = ui.ctx().clone();
|
||||
app.logic(&ctx);
|
||||
app.ui(ui);
|
||||
},
|
||||
app,
|
||||
);
|
||||
h.run_steps(4);
|
||||
// Focus the button for real: a bare accesskit click leaves egui focus empty, and an
|
||||
// unrelated chrome-click helper would hand focus to the canvas on its own.
|
||||
h.get_by_label("Delete").focus();
|
||||
h.run_steps(2);
|
||||
h.state_mut().canvas.want_focus = false;
|
||||
h.get_by_label("Delete").click();
|
||||
h.run_steps(4);
|
||||
assert!(h.state().canvas.focused, "Delete returns focus to the document");
|
||||
assert!(h.state().session.clip_history.items().is_empty(), "the item was deleted");
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
Reference in New Issue
Block a user