KEY-INFO: I toggled off brings back exactly what was there before, closed included (test notes 2026-10-24 note 21)

Every panel toggle (I, M, R, Q, the tool strip's buttons) remembers what the
right column showed when it opened the panel and puts exactly that back when
toggled off: Edit -> I -> I = Edit, Masks -> I -> I = Masks, closed -> I -> I =
closed. A tool opened from another tool goes back to that tool
(UiState::toggle_panel).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit d5ec632329a60d6526549b71ae2907c09a0d74d0)
This commit is contained in:
OneSlips
2026-10-25 06:46:02 +10:00
parent 29b5b3811d
commit 283d65852f
3 changed files with 90 additions and 7 deletions
+4 -6
View File
@@ -290,14 +290,12 @@ pub const UI_COMMANDS: &[UiCommand] = &[
];
fn panel(app: &mut LightcraftApp, ctx: &egui::Context, p: RightPanel, name: &str) {
app.ui.note_right();
if app.ui.right == p && crate::docking::exposed(app, crate::docking::Panel::Tools) {
// a tool closing puts back the panel shown before it (in the same frame: no flash, no
// jump), or leaves the panel hidden when it was
app.ui.right = if p.is_tool() { app.ui.leave_tool() } else { RightPanel::None };
// toggled off: back to exactly what the right column showed before (in the same frame: no flash, no jump),
// closed when it was closed (note 21)
let exposed = crate::docking::exposed(app, crate::docking::Panel::Tools);
if !app.ui.toggle_panel(p, exposed) {
app.toast(ctx, crate::i18n::tr_format!("{name} Off", name = crate::i18n::tr(name)));
} else {
app.ui.right = p;
app.toast(ctx, crate::i18n::tr_format!("{name} On", name = crate::i18n::tr(name)));
if p.is_edit_tool() && !matches!(app.ui.view, ViewMode::Detail) {
app.ui.view = ViewMode::Detail;
+46
View File
@@ -811,6 +811,11 @@ pub struct UiState {
/// when the tool closes ([`RightPanel::None`]: the panel was hidden, and stays hidden).
#[serde(skip)]
pub tool_return: Option<RightPanel>,
/// The panel a toggle (a panel key or button: I, M, R, Q…) opened, with what the right column showed before it
/// and that one's [`UiState::tool_return`]: toggling it off puts back exactly that, closed included (test notes
/// 2026-10-24 note 21). Forgotten once another panel is shown.
#[serde(skip)]
pub toggle_return: Option<(RightPanel, RightPanel, Option<RightPanel>)>,
/// The panel [`UiState::note_right`] last saw.
#[serde(skip)]
pub right_seen: RightPanel,
@@ -1497,6 +1502,9 @@ impl UiState {
if self.right == self.right_seen {
return;
}
if self.toggle_return.is_some_and(|(opened, ..)| opened != self.right) {
self.toggle_return = None;
}
if self.right.is_tool() {
if !self.right_seen.is_tool() {
self.tool_return = Some(self.right_seen);
@@ -1511,9 +1519,46 @@ impl UiState {
/// when the panel was hidden (Edit when nothing is known).
pub fn leave_tool(&mut self) -> RightPanel {
self.note_right();
if let Some(back) = self.untoggle() {
return back;
}
let back = self.tool_return.take().unwrap_or(RightPanel::Edit);
if back.is_tool() { RightPanel::Edit } else { back }
}
/// A panel toggle (`panel.info`, `panel.masking`…) for `p`: when `p` is on show (`exposed`: not hidden behind
/// another dock tab) it goes and the right column shows exactly what it showed before the toggle opened it, or
/// stays closed when it was (note 21); otherwise `p` comes up and what was there is remembered. Returns whether
/// `p` is now on.
pub fn toggle_panel(&mut self, p: RightPanel, exposed: bool) -> bool {
self.note_right();
if self.right == p && exposed {
self.right = match self.untoggle() {
Some(back) => back,
None if p.is_tool() => self.leave_tool(),
None => RightPanel::None,
};
self.note_right();
false
} else {
let saved = (p, if exposed || self.right != p { self.right } else { RightPanel::None }, self.tool_return);
self.right = p;
self.note_right();
self.toggle_return = Some(saved);
true
}
}
/// What the toggle that opened the panel on show replaced (see [`UiState::toggle_panel`]), with its own tool
/// memory put back, or `None` when that panel wasn't opened by a toggle.
fn untoggle(&mut self) -> Option<RightPanel> {
let (_, before, tool_return) = self.toggle_return.filter(|(opened, ..)| *opened == self.right)?;
self.toggle_return = None;
self.tool_return = tool_return;
// seen already: `note_right` must not take the panel being left for the one this came back from
self.right_seen = before;
Some(before)
}
}
impl Default for UiState {
@@ -1533,6 +1578,7 @@ impl Default for UiState {
right: RightPanel::Edit,
right_hidden: RightPanel::None,
tool_return: None,
toggle_return: None,
right_seen: RightPanel::Edit,
presets: false,
preset_thumbs: false,
+40 -1
View File
@@ -70,10 +70,12 @@ fn the_edit_panel_comes_back_after_masking_and_crop_where_it_was() {
assert_eq!(widget(&h, "canvas:image"), Some(photo), "{tool}: the photo didn't move");
assert_eq!(widget(&h, &slider), Some(at), "{tool}: Edit kept its scroll position");
}
// Masking, then Crop from it, then Crop closed: still Edit
// Masking, then Crop from it, then Crop closed: exactly what was there before, Masking (note 21); then Edit
exec(&mut h, "panel.masking");
exec(&mut h, "panel.crop");
exec(&mut h, "panel.crop");
assert_eq!(h.app.ui.right, RightPanel::Masking);
exec(&mut h, "panel.masking");
assert_eq!(h.app.ui.right, RightPanel::Edit);
// Return (Done) in a tool also goes back
exec(&mut h, "panel.masking");
@@ -104,3 +106,40 @@ fn a_hidden_panel_stays_hidden_after_a_tool() {
exec(&mut h, "panel.masking");
assert_eq!(h.app.ui.right, RightPanel::Info);
}
/// "I" toggles the Info panel; pressing it again brings back exactly what the right column showed before, closed
/// included (test notes 2026-10-24 note 21: the Edit sliders stayed gone).
#[test]
fn info_toggled_off_brings_back_exactly_what_was_there() {
let mut h = detail();
assert_eq!(h.app.ui.right, RightPanel::Edit);
// the key, as the user pressed it
let key = |h: &mut Headless| {
let r = h.request("ui.key", json!({"key": "I"}), T);
assert_eq!(r["ok"], true, "{r}");
h.step();
h.step();
};
key(&mut h);
assert_eq!(h.app.ui.right, RightPanel::Info);
key(&mut h);
assert_eq!(h.app.ui.right, RightPanel::Edit, "Edit → I → I = Edit");
exec(&mut h, "panel.masking");
key(&mut h);
assert_eq!(h.app.ui.right, RightPanel::Info);
key(&mut h);
assert_eq!(h.app.ui.right, RightPanel::Masking, "Masks → I → I = Masks");
// and Masks still closes back to Edit
exec(&mut h, "panel.masking");
assert_eq!(h.app.ui.right, RightPanel::Edit);
for panel in ["panel.keywords", "panel.versions", "panel.activity"] {
exec(&mut h, panel);
exec(&mut h, panel);
assert_eq!(h.app.ui.right, RightPanel::Edit, "{panel} toggled off: Edit again");
}
exec(&mut h, "panel.close");
key(&mut h);
assert_eq!(h.app.ui.right, RightPanel::Info);
key(&mut h);
assert_eq!(h.app.ui.right, RightPanel::None, "closed → I → I = closed");
}