mirror of
https://github.com/storytold/figcraft.git
synced 2026-10-28 20:36:55 -06:00
refactor(pages): remember which file the Pages list focus belongs to
This commit is contained in:
@@ -544,7 +544,7 @@ fn input(app: &mut FigApp, ui: &mut Ui, resp: &egui::Response) -> bool {
|
||||
// A press on the canvas gives the keyboard back to it (arrows nudge again).
|
||||
if resp.hovered() && ctx.input(|i| i.pointer.any_pressed()) {
|
||||
app.ui.layers_focus = false;
|
||||
app.ui.pages_focus = false;
|
||||
app.ui.pages_focus = None;
|
||||
app.ui.key_box = None;
|
||||
}
|
||||
// Zoom (pinch, Cmd/Ctrl+scroll) about the pointer; plain scroll pans.
|
||||
|
||||
@@ -199,7 +199,7 @@ fn pages(app: &mut FigApp, ui: &mut Ui) {
|
||||
}
|
||||
icons::paint(ui.painter(), ar.shrink(5.0), Icon::Plus, t.icon);
|
||||
if aresp.clicked() {
|
||||
app.ui.pages_focus = true;
|
||||
app.ui.pages_focus = app.session.ds().ok().map(|d| d.uid);
|
||||
app.run("page.add", json!({}));
|
||||
}
|
||||
if !app.ui.pages_open {
|
||||
@@ -209,6 +209,7 @@ fn pages(app: &mut FigApp, ui: &mut Ui) {
|
||||
let pages: Vec<(NodeId, String, bool)> =
|
||||
ds.doc.pages.iter().filter_map(|p| ds.doc.node(*p).map(|n| (*p, n.name.clone(), ds.doc.is_divider(*p)))).collect();
|
||||
let cur = ds.page;
|
||||
let uid = ds.uid;
|
||||
let sel = ds.selection.clone();
|
||||
let mut select = None;
|
||||
let mut rename_done: Option<(NodeId, String)> = None;
|
||||
@@ -258,7 +259,7 @@ fn pages(app: &mut FigApp, ui: &mut Ui) {
|
||||
}
|
||||
if resp.clicked() && !divider {
|
||||
select = Some(id);
|
||||
app.ui.pages_focus = true;
|
||||
app.ui.pages_focus = Some(uid);
|
||||
app.ui.layers_focus = false;
|
||||
}
|
||||
if resp.double_clicked() {
|
||||
@@ -1074,7 +1075,7 @@ fn layers(app: &mut FigApp, ui: &mut Ui) {
|
||||
}
|
||||
if let Some((id, m)) = clicked {
|
||||
app.ui.layers_focus = true;
|
||||
app.ui.pages_focus = false;
|
||||
app.ui.pages_focus = None;
|
||||
let order: Vec<NodeId> = rows.iter().map(|r| r.id).collect();
|
||||
let pos = |x: NodeId| order.iter().position(|o| *o == x);
|
||||
let anchor = app.ui.layer_anchor.filter(|a| sel.contains(a)).and_then(pos);
|
||||
|
||||
@@ -169,7 +169,7 @@ fn selected_layers_or_a_canvas_press_take_delete_back_from_the_pages_list() {
|
||||
u.button(row, true);
|
||||
u.button(row, false);
|
||||
assert_eq!(u.app.session.page().unwrap(), first);
|
||||
assert!(u.app.ui.pages_focus);
|
||||
assert!(u.app.ui.pages_focus.is_some());
|
||||
// Layers selected after the click (Select all, say): Delete deletes them, not the page.
|
||||
u.app.run("select.set", json!({"ids": [a]}));
|
||||
key(&mut u, Key::Delete, false);
|
||||
@@ -179,7 +179,7 @@ fn selected_layers_or_a_canvas_press_take_delete_back_from_the_pages_list() {
|
||||
let p = pos2(900.0, 700.0);
|
||||
u.button(p, true);
|
||||
u.button(p, false);
|
||||
assert!(!u.app.ui.pages_focus);
|
||||
assert!(u.app.ui.pages_focus.is_none());
|
||||
u.app.run("select.none", json!({}));
|
||||
key(&mut u, Key::Delete, false);
|
||||
assert_eq!(pages(&u), 2, "Delete with nothing selected on the canvas deletes no page");
|
||||
|
||||
@@ -500,10 +500,10 @@ pub struct UiState {
|
||||
/// The layers panel has the keyboard: arrow keys move through its rows instead of nudging
|
||||
/// (set by a click on a row, cleared by a press on the canvas).
|
||||
pub layers_focus: bool,
|
||||
/// The pages list has the keyboard: Delete with no layers selected deletes the current page (set
|
||||
/// by a click on a page row or the add-page button, cleared by a click on a layer row or a press
|
||||
/// on the canvas).
|
||||
pub pages_focus: bool,
|
||||
/// The file (its `uid`) whose pages list has the keyboard: Delete with no layers selected deletes
|
||||
/// its current page (set by a click on a page row or the add-page button, cleared by a click on a
|
||||
/// layer row or a press on the canvas).
|
||||
pub pages_focus: Option<u64>,
|
||||
pub layers_seen_sel: Vec<NodeId>,
|
||||
pub dark: bool,
|
||||
pub follow_system: bool,
|
||||
@@ -638,7 +638,7 @@ impl Default for UiState {
|
||||
layer_filter: String::new(),
|
||||
layer_anchor: None,
|
||||
layers_focus: false,
|
||||
pages_focus: false,
|
||||
pages_focus: None,
|
||||
layers_seen_sel: Vec::new(),
|
||||
dark: false,
|
||||
follow_system: false,
|
||||
|
||||
@@ -118,7 +118,7 @@ pub fn invoke(app: &mut FigApp, id: &str) {
|
||||
// removes that interaction, not the layer (#767).
|
||||
"edit.delete" if app.ui_context.clone().is_some_and(|ctx| crate::proto_panel::delete_selected_interaction(app, &ctx)) => {}
|
||||
// After a click in the Pages list, with no layers selected, it deletes the current page (#859).
|
||||
"edit.delete" if app.ui.pages_focus && app.session.selection().is_empty() => {
|
||||
"edit.delete" if app.ui.pages_focus.is_some() && app.session.selection().is_empty() => {
|
||||
if let Ok(page) = app.session.page() {
|
||||
crate::layers::delete_page(app, page);
|
||||
}
|
||||
|
||||
@@ -217,7 +217,7 @@ pub fn input(app: &mut FigApp, ctx: &egui::Context, pos: Option<Pos2>, hovered:
|
||||
let drag =
|
||||
Drag { ids, axis: axis.clone(), start: p, value: h.value, uid: ds.uid, page: ds.page, moved: false, last_value: axis.value };
|
||||
app.ui.layers_focus = false;
|
||||
app.ui.pages_focus = false;
|
||||
app.ui.pages_focus = None;
|
||||
app.ui.key_box = None;
|
||||
ctx.memory_mut(|m| {
|
||||
if let Some(f) = m.focused() {
|
||||
|
||||
Reference in New Issue
Block a user