Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions crates/app/src/ui/shortcuts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -642,16 +642,31 @@ pub(super) fn handle_delete_shortcut(app: &mut PlotiumApp, ctx: &egui::Context)
}
return;
}
if ctx.egui_wants_keyboard_input() {
// Clicking a sidebar row focuses it, which egui reports as wanting the
// keyboard; only a focused text editor should keep the key for itself.
if ctx.egui_wants_keyboard_input() && !super::primary_sidebar::selection::list_row_focused(ctx)
{
return;
}
delete_selection(app, ctx);
}

/// What Delete/Backspace removes, most specific first: page-space authoring
/// objects, a selected panel letter, then (outside analysis tools, which own the
/// key for their own marks) the selected panel or the selected board pages.
/// What Delete/Backspace removes. A page selection (board or sidebar) removes
/// the pages, since object selections left on the page behind it are not what
/// the user last picked. Otherwise most specific first: page-space authoring
/// objects, a selected panel letter, then the selected panel. Analysis tools
/// own the key for their own marks, so they never remove panels or pages.
fn delete_selection(app: &mut PlotiumApp, ctx: &egui::Context) {
use plotium_core::state::SelectionScope;
if matches!(
app.session.ui.selection_scope,
SelectionScope::Board | SelectionScope::CanvasList
) {
if app.session.tool.axis() != plotium_core::state::ToolAxis::Analyze {
delete_selected_panel_or_pages(app, ctx);
}
return;
}
if super::plot_annotations::delete_selected(app) {
return;
}
Expand Down
54 changes: 54 additions & 0 deletions crates/app/src/ui/shortcuts_delete_tests.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
use super::*;
use plotium_core::state::{
BoardFrameId, CanvasObject, CanvasObjectKind, ObjectFrame, SelectionScope, TextBox,
};

/// Select the second of three pages from the sidebar list, as a click does.
fn select_sidebar_page(app: &mut PlotiumApp) {
app.session.ui.frame_selection = vec![BoardFrameId::Page(app.doc.canvases[1].resource_id)];
app.session.ui.selection_scope = SelectionScope::CanvasList;
}

#[test]
fn delete_on_a_focused_page_row_deletes_the_selected_page() {
let (mut app, _) = app_with_pages(3);
let removed = app.doc.canvases[1].resource_id;
select_sidebar_page(&mut app);
let ctx = egui::Context::default();
let _ = ctx.run_ui(egui::RawInput::default(), |ui| {
let row = ui.selectable_label(true, "Page");
super::super::primary_sidebar::selection::claim_list_keyboard_focus(ui, &row);
});
let _ = ctx.run_ui(backspace(), |ui| {
let _ = ui.selectable_label(true, "Page");
handle_delete_shortcut(&mut app, ui.ctx());
});

assert_eq!(app.doc.canvases.len(), 2, "{}", app.session.status);
assert!(app.doc.canvases.iter().all(|c| c.resource_id != removed));
}

#[test]
fn a_page_selection_deletes_the_page_not_a_remembered_object() {
let (mut app, _) = app_with_pages(3);
let id = app.doc.canvases[0].allocate_object_id();
app.execute_action(Action::insert_object(
0,
CanvasObject {
id,
name: "Note".into(),
frame: ObjectFrame::new(10., 10., 50., 20.),
locked: false,
visible: true,
kind: CanvasObjectKind::Text(TextBox::label("note".into())),
},
Selection::None,
));
app.session.ui.selection = Selection::Objects(vec![id]);
select_sidebar_page(&mut app);

delete_selection(&mut app, &egui::Context::default());

assert_eq!(app.doc.canvases.len(), 2, "{}", app.session.status);
assert!(app.doc.canvases[0].object(id).is_some());
}
3 changes: 3 additions & 0 deletions crates/app/src/ui/shortcuts_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -750,3 +750,6 @@ fn tab_from_the_cell_editor_keeps_typing_in_the_sheet() {
assert!(command.is_none());
assert!(sheet.app.session.ui.table_cell_edit.is_some());
}

#[path = "shortcuts_delete_tests.rs"]
mod delete;
Loading