Find Layers: keep the Name text on every run path; no focus for a hidden filter row (#11238)

CodeRabbit found three things after the last fix-up:
- `engine.execute` and action steps without `name` replied `selected: []`
  while the panel listed the layers its kept Name text matches. `run` now
  fills in the panel's Name text for every path, as the menu did.
- With Filter Options > Hide, Find Layers left a focus request that took
  the caret once the row was shown again. In the reference application the
  row stays hidden and showing it later does not focus the field, so the
  request is only made for a drawn row.
- The control protocol said the selection never changes; the Name filter
  deselects a selected layer it hides (#10879). The doc now says so and
  describes each entry point and the reply.

Tests for the first two fail without the fix.

Co-Authored-By: NaufalDzz <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
committed 2026-11-07 20:24:22 +01:00
1 parent 0f0e76c44b
commit 8bf381f2d9
5 files changed
+51 -5

No files matched your search

+1 -1
View File
@@ -106,7 +106,7 @@ pub fn specs() -> Vec<CommandSpec> {
"Find Layers",
&["Select"],
Some("Cmd+Alt+Shift+F"),
r##"{"name":str?} (filters the Layers panel by Name, a case-insensitive substring, without changing the selection; replies with the matching layers)"##,
r##"{"name":str?} (filters the Layers panel by Name, a case-insensitive substring, selecting none of the matches; without `name` the panel's Name text is kept; replies with the matching layers)"##,
has_doc,
find_layers
),
+1
View File
@@ -6,6 +6,7 @@ use super::{
impl PhotocraftApp {
/// Run an engine command, reporting errors in the status bar.
pub fn run(&mut self, id: &str, params: Value) -> Result<Value, String> {
let params = if id == "select.findLayers" { crate::layer_filter_ui::find::params_for_run(self, params) } else { params };
if let Some(result) = delete_layer_prompt::intercept(self, id, &params) {
return result;
}
@@ -18,8 +18,8 @@ fn focus_flag() -> egui::Id {
/// shown with the field focused.
pub fn invoke(app: &mut PhotocraftApp, ctx: &egui::Context, params: Value) -> Result<Value, String> {
let given = params.get("name").is_some_and(|n| !n.is_null());
let params = if given { params } else { json!({"name": app.ui.layer_filter_name}) };
// `run` applies the reply's Name filter ([`apply`]).
// `run` keeps the Name text when no `name` is given ([`params_for_run`]) and applies the
// reply's Name filter ([`apply`]).
let reply = app.run("select.findLayers", params)?;
if !given {
// The panel docking layout (when on) shows the Layers panel itself, else the dock group.
@@ -31,11 +31,27 @@ pub fn invoke(app: &mut PhotocraftApp, ctx: &egui::Context, params: Value) -> Re
*crate::dock::Group::Layers.tab_mut(&mut app.ui.dock_tabs) = 0;
crate::dock::reveal(app, crate::dock::Group::Layers);
}
ctx.data_mut(|d| d.insert_temp(focus_flag(), true));
// A hidden filter row (Filter Options › Hide) stays hidden, as in Photoshop, and showing it
// later doesn't put the caret in the field: only a drawn row takes the focus.
if app.ui.layers_panel_options.show_filters {
ctx.data_mut(|d| d.insert_temp(focus_flag(), true));
}
}
Ok(reply)
}
/// The params `select.findLayers` runs with: without a `name` the panel's Name text is kept, so the
/// reply lists the layers the panel lists however the command runs (the menu, the shortcut,
/// `engine.execute` or an action step).
pub(crate) fn params_for_run(app: &PhotocraftApp, params: Value) -> Value {
if params.get("name").is_some_and(|n| !n.is_null()) {
return params;
}
let mut params = if params.is_object() { params } else { json!({}) };
params["name"] = json!(app.ui.layer_filter_name);
params
}
/// Apply the Name filter in a `select.findLayers` reply to the Layers panel: switch to Name and set
/// the text when the reply has one. [`PhotocraftApp::run`] calls it after every Find Layers.
pub(crate) fn apply(app: &mut PhotocraftApp, reply: &Value) {
@@ -149,6 +149,35 @@ fn the_menu_item_shows_a_layers_panel_closed_in_the_docking_layout() {
assert_eq!(h.state().ui.layer_filter_name, "other", "the Name field has the focus with its text selected");
}
#[test]
fn a_hidden_filter_row_stays_hidden_and_does_not_take_the_focus_later() {
// Measured in Photoshop: with Filter Options › Hide, Find Layers switches to Name but leaves
// the row hidden, and showing the row afterwards does not put the caret in the field.
let mut h = harness();
h.state_mut().ui.layers_panel_options.show_filters = false;
h.state_mut().ui.layer_filter_name = "lin".into();
h.run_steps(4);
find(&mut h, json!({}));
assert_eq!(h.state().ui.layer_filter_by, FilterBy::Name);
assert!(!h.state().ui.layers_panel_options.show_filters, "the filter row stays hidden");
h.state_mut().ui.layers_panel_options.show_filters = true;
h.run_steps(4);
assert!(h.ctx.memory(|m| m.focused()).is_none(), "showing the row later does not focus the Name field");
assert_eq!(h.state().ui.layer_filter_name, "lin");
}
#[test]
fn engine_execute_without_a_name_lists_what_the_panel_lists() {
let mut h = harness();
h.state_mut().ui.layer_filter_name = "link".into();
let reply = h.state_mut().run("select.findLayers", json!({})).unwrap();
h.run_steps(4);
assert_eq!(h.state().ui.layer_filter_name, "link", "the Name text is kept");
assert_eq!(reply["selected"], json!([id(&h, "LinkA").0, id(&h, "LinkB").0]), "the reply lists the layers the kept text matches");
assert_eq!(reply["layerFilter"], json!({"by": "name", "name": "link"}));
assert_eq!(listed(&h), ["LinkB", "LinkA"]);
}
#[test]
fn engine_execute_sets_the_panel_filter_too() {
// `engine.execute` runs engine commands through `PhotocraftApp::run`, not `menus::invoke`.
+1 -1
View File
@@ -56,7 +56,7 @@ The transport is `apps/photocraft/src/control_server.rs`, and the handlers are i
- `ui.set` also accepts `tileGrid` (boolean), a developer overlay of the active layer's storage tiles: the tile grid over the document, every stored tile filled and labelled `tx,ty`, tiles with identical pixels in a shared colour and unique ones in blue. It has no menu item and View › Extras doesn't hide it. `ui.inspect` reports it as `view.tile_grid`.
- `ui.set` also accepts `strokeTrace` (`true`, `false`, `"stderr"` or `"off"`): turn the stroke latency trace on or off at runtime; each stroke's summary is in `ui.inspect` `perf.strokeTrace`. A CSV file of every frame is set only at launch (`PHOTOCRAFT_STROKE_TRACE=<file.csv>` / `--stroke-trace <file.csv>`): the control channel doesn't write files outside the automation write root
- `ui.set` also accepts `layerFilter` (#5048), the Layers panel filter row: `{by?, kinds?, name?, effect?, mode?, attribute?, color?, smart?}`, any subset. `by` is `kind`, `name`, `effect`, `mode`, `attribute`, `color`, `smartObject`, `artboard` or `group` (the filter-type dropdown); `kinds` lists the Kind toggles that are on (`pixel`, `adjustment`, `type`, `shape`, `smart`); `name` matches part of a layer name, ignoring case; `effect` (#10880) is `bevelEmboss`, `stroke`, `innerShadow`, `innerGlow`, `satin`, `overlay` (Color, Gradient or Pattern Overlay), `outerGlow` or `dropShadow`, and lists the layers with that effect turned on; `mode` is one of the 27 layer blend modes (`Multiply`, `Screen`), not Pass Through, which the Mode list doesn't offer (#10878); `attribute` (#10881) is `visible`, `locked`, `empty`, `linked`, `clipped`, `layerMask`, `vectorMask`, `layerEffects` or `advancedBlending`, or one of their opposites `notVisible`, `notLocked`, `notEmpty`, `notLinked`, `notClipped`, `noLayerMask`, `noVectorMask`, `noLayerEffects`, `noAdvancedBlending`; `color` is a layer colour label id (`none`, `red`, `orange`, `yellow`, `green`, `seafoam`, `blue`, `indigo`, `magenta`, `fuchsia`, `violet`, `gray`; #5898); `smart` lists the Smart Object toggles that are on (`linked`: linked to a file, `missing`: linked to a file that was not there when the app last looked, `embedded`). Kind, Name and Smart Object filter only once a toggle is on or text is typed; Effect, Mode, Attribute and Color always filter, by Bevel & Emboss, by Normal, by Visible and by no colour at first, as in Photoshop. Artboard has no field of its own: it lists the artboards that hold the selected layers, with everything inside them (closed groups stay closed), and does not filter when nothing is selected or a selected layer is in no artboard. Group (#10883) has no field of its own either and filters at once: it lists every group that is not an artboard with everything inside it (the groups inside an artboard too), and hides the layers that are in no group; each group stays open or closed as it is. Fields left out keep their value; a bad one is an error and changes nothing.
- `select.findLayers` (#10884, Select › Find Layers) filters the Layers panel by Name and does not change the layer selection. With `name` it sets the Name text; without it the text is kept, the Layers panel is shown and its Name field takes the keyboard focus with the text selected. The reply lists the matching layer ids in `selected` and the Name filter applied in `layerFilter` (`{by: "name", name?}`).
- `select.findLayers` (#10884, Select › Find Layers) filters the Layers panel by Name and selects none of the matches; as with any filter, a selected layer the filter hides is deselected (#10879). With `name` it sets the Name text; without it the text is kept. Through `engine.execute` or an action step that is all; through the menu, the shortcut or `ui.menu.invoke` without `name`, the Layers panel is also shown and its Name field takes the keyboard focus with the text selected (unless Filter Options › Hide hid the filter row, which stays hidden). The reply lists the ids of the layers the Name text matches in `selected` (trimmed, ignoring case: a blank text lists every layer, a text nothing matches none) and the Name filter applied in `layerFilter` (`{by: "name", name}`).
- `ui.set` also accepts the Histogram panel: `histogramPanel` `{view?, channel?, showChannelsInColor?, showStatistics?, source?}` (any subset, kept with the preferences): `view` is `compact`, `expanded` or `allChannels`; `channel` is `composite`, `red`, `green`, `blue`, `cyan`, `magenta`, `yellow`, `black`, `a`, `b`, `luminosity` or `colors` (one the document's mode lacks shows as its composite); `source` is `entireImage`, `selectedLayer` or `adjustmentComposite` (Entire Image is counted in Compact View, when the document has one layer, or when no adjustment layer is selected for Adjustment Composite). `histogramRange` is `[from, to]` (levels 0..255) or `null`: the dragged tonal range whose Count and Percentile the statistics show. `histogramRefresh: true` is Uncached Refresh: the current state is recounted at cache level 1. `ui.inspect` › `histogram` reports the options, the channel and source as they apply, the channels the document offers, whether the shown histogram is `current` (counted for the document's revision, source and cache level the panel wants now), its `cacheLevel`, `maxCacheLevel` (Preferences › Performance › Cache Levels), `preview` (an adjustment's preview is counted) and `stats` (`mean`, `stdDev`, `median`, `pixels`, `level`, `count`, `percentile`, `clipped` percent at 0 and 255). Histograms are counted while the panel is shown.
- Each painting tool keeps its own brush, as in Photoshop: `tools.setBrush` and `ui.set {brushSize}` change the active tool's brush, and switching tools swaps in that tool's own (size, hardness, mode, opacity, flow, dynamics, smoothing). A tool used for the first time starts from the brush in hand. The colours, the erase flag and the stroke seed stay shared. So `ui.set {tool: "eraser", brushSize: 12}` sets the Eraser's size, and `ui.set {tool: "brush"}` afterwards brings the Brush's own size back.
- Brush Pose's `pose.overrideTiltX` and `pose.overrideTiltY` are independent booleans. For example, `engine.execute {"command":"tools.setBrush","params":{"pose":{"enabled":true,"tiltX":45,"overrideTiltX":true,"overrideTiltY":false}}}` fixes X at 45° while Y follows the stylus. Pose tilts are degrees (±90); the Brush Settings panel displays percentages (±100). Old stored `overrideTilt` values migrate to both axes. In command patches, `overrideTilt` sets both axes unless an explicit axis field in the same patch overrides it. `brush.get` includes both axis flags and the legacy combined readback (`overrideTilt` is true only when both flags are true). Axis-only journals omit that derived combined key so replay retains the other axis. Present flag values must be booleans; null and other types return an error.