Skip to content

DevTools: save unsaved edits to the right element and make Restore reliable - #1162

Open
Zach Teutsch (zateutsch) wants to merge 6 commits into
mainfrom
zateutsch-devtools-edit-restore-bugs
Open

Zach Teutsch (zateutsch) wants to merge 6 commits into
mainfrom
zateutsch-devtools-edit-restore-bugs

Conversation

@zateutsch

Copy link
Copy Markdown
Contributor

What and why

Three problems in the DevTools properties pane:

  • An unsaved edit landed on the wrong element. If you typed in a property box and then clicked another element in the tree, the typed value was written to the new element. Now the box is saved to the element you were editing before the selection changes.
  • "Restore original" was unreliable. After you clicked away and came back, Restore was gone or put back the wrong value. Now DevTools keeps, for the whole session, the value each property had before your first edit on that element, and Restore puts that value back. Clearing a property counts as an edit too. If the original came from a resource, Restore re-links the resource. If the original was not set on the element (for example, it came from a style), Restore clears the property.
  • Restore could undo the app's own change. If the app changes the value after your edit, Restore is removed for that property and the row says the app changed it. A theme switch doesn't count as an app change. If you edit the property again, Restore puts back the app's value.

In the multiline editor, Enter adds a new line. A hint under the box shows how to save.

Fixes #1142

Before / after

Before: select a TextBlock, type Hello in Text, then click a Button in the tree without pressing Enter. The Button's Text becomes Hello, and the TextBlock's Restore is gone when you come back to it.

After: the TextBlock gets Hello, the Button is unchanged, and the TextBlock's Text row still offers Restore when you come back to it.

No screenshot or recording yet; see below.

Not tested / risks

  • No screenshot or recording yet. The window tests drive the pane logic with fake app reads and writes, not a real app.
  • The DevTools engine and window test were built on arm64 Debug only. All native test suites passed (window tests: 119/119).
  • If the app changes a property while you are typing in it, and DevTools hasn't recorded an edit for that property yet, the app's change isn't detected.

Checklist

  • Tests added or updated
  • Tested locally on Windows
Notes for reviewers
  • Edit records are per element and property for the session, not per selection. Each record also keeps the value DevTools last read back for that property, called the baseline. DevTools reads the property values right before each write, to catch app changes, and right after it, so its own side effects (changing Padding.Left also changes Padding) don't look like app changes.
  • The element's theme is saved with the baseline. A different theme means a new baseline, not an app change.
  • When you leave an element, its editors stay live instead of being retired. That way a focus-out that arrives late still saves to its own element and records Restore there.

- Save the focused editor before the selection changes or the pane is
  rebuilt, and ignore late focus-out events from removed editors, so an
  unsaved edit is written to the element it was made on.
- Keep one edit record per element and property for the session, holding
  the value from before the first edit. Restore puts that back: a value is
  written, a value that came from a style or default is cleared, and a
  resource reference is re-linked. Clear counts as an edit.
- Drop the record when the app changes the value after the edit, and say
  so in the row, instead of offering a Restore that would undo the app.
- Show a hint in the multi-line editor that Enter adds a new line.

Fixes #1142

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 78fc45e1-7d89-4a89-bb28-898e906b0a15
… resource restore recovery

- Record the element theme with each baseline, so a theme switch takes a new baseline instead of hiding or faking app changes.
- Read values before and right after each write, so app changes to other properties are caught and DevTools' own side effects are not.
- Re-editing after an app change records the app's value as the original.
- A failed resource Restore puts back the previous value and keeps the record.
- Leaving an element keeps its editors live so a late focus-out still saves.
- Remove dead g_editRows code.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 78fc45e1-7d89-4a89-bb28-898e906b0a15
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 78fc45e1-7d89-4a89-bb28-898e906b0a15
Copilot AI balanced review requested due to automatic review settings October 22, 2026 02:06
@zateutsch Zach Teutsch (zateutsch) added the agent-preparing Agent is addressing feedback or completing required validation and CI label Oct 22, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Restore can still overwrite newer app values or restore the wrong property source because original-state capture and read-back handling remain incomplete.

5 open issues
What changed in this PR

This PR addresses #1142 in the native DevTools properties pane by saving edits before selection changes and keeping Restore records per element across the session.

Changes:

  • Tracks original values, property sources, and app changes to guide Restore.
  • Adds editor flushing and stale-callback guards around pane rebuilds and selection changes.
  • Adds regression tests and a multiline-editor hint explaining Enter-to-apply and Shift+Enter-to-insert.
File Description
src/​winapp-devtools/​test/​window-runtime-tests.cpp Tests edit records, Restore, app changes, and editor lifetime.
src/​winapp-devtools/​test/​binding-editor-semantics-tests.cpp Tests rejection of Apply from another element’s editor.
src/​winapp-devtools/​native/​WinApp.DevTools.Native/​xaml-window/​window-shell.xaml Adds the multiline keyboard hint.
src/​winapp-devtools/​native/​WinApp.DevTools.Native/​DevToolsWindow.State.inc Defines session-wide edit and app-change records.
src/​winapp-devtools/​native/​WinApp.DevTools.Native/​DevToolsWindow.SourceAndResources.inc Updates an ownership comment only.
src/​winapp-devtools/​native/​WinApp.DevTools.Native/​DevToolsWindow.PropsPane.inc Flushes editors and preserves records across selections.
src/​winapp-devtools/​native/​WinApp.DevTools.Native/​DevToolsWindow.PaneSinks.inc Tracks editors, commit outcomes, and late saves.
src/​winapp-devtools/​native/​WinApp.DevTools.Native/​DevToolsWindow.LiveProps.inc Checks edited properties against live values and themes.
src/​winapp-devtools/​native/​WinApp.DevTools.Native/​DevToolsWindow.KindModel.inc Implements original-state capture, reconciliation, Clear, and Restore.
src/​winapp-devtools/​native/​WinApp.DevTools.Native/​DevToolsWindow.Expansion.inc Displays Restore state and app-change messages.
src/​winapp-devtools/​native/​WinApp.DevTools.Native/​DevToolsWindow.Editors.inc Registers editors, guards callbacks, and adds keyboard help.
src/​winapp-devtools/​native/​WinApp.DevTools.Native/​DevToolsWindow.cpp Imports automation peers for save notifications.

Review effort: Balanced

Comment thread src/winapp-devtools/native/WinApp.DevTools.Native/DevToolsWindow.KindModel.inc Outdated
Comment thread src/winapp-devtools/native/WinApp.DevTools.Native/DevToolsWindow.LiveProps.inc Outdated
Comment thread src/winapp-devtools/native/WinApp.DevTools.Native/DevToolsWindow.LiveProps.inc Outdated
Comment thread src/winapp-devtools/native/WinApp.DevTools.Native/DevToolsWindow.PaneSinks.inc Outdated
@github-actions

github-actions Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Build Metrics Report

Validation passed. All required build and validation jobs succeeded.

Binary Sizes

Artifact Baseline Current Delta
CLI (ARM64) 65.05 MB 65.10 MB 📈 +54.5 KB (+0.08%)
CLI (x64) 64.97 MB 65.02 MB 📈 +49.5 KB (+0.07%)
MSIX (ARM64) 26.93 MB 26.95 MB 📈 +23.4 KB (+0.08%)
MSIX (x64) 28.55 MB 28.58 MB 📈 +27.9 KB (+0.10%)
NPM Package 56.12 MB 56.16 MB 📈 +42.3 KB (+0.07%)
NuGet Package 56.27 MB 56.31 MB 📈 +42.1 KB (+0.07%)

.NET Test Results (TRX reports)

Other suites are reflected in the overall validation status above.

✅ 10669 passed, 43 skipped out of 10712 tests in 1880.8s (+5 tests, -703.5s vs. baseline)

Test Coverage

✅ 87.4% line coverage, 81.5% branch coverage · ✅ no change vs. baseline

CLI Startup Time

77ms median (x64, winapp --version) · ⚠️ +17ms vs. baseline

Try This Build

Installs the MSIX for your architecture, replacing any previously installed build. Needs the GitHub CLI — the command offers to install it and sign you in if it is missing.

& ([scriptblock]::Create((irm https://raw.githubusercontent.com/microsoft/winappCli/main/scripts/winapp-pr.ps1))) 1162
Switching between builds often?

Put the tool on your PATH once:

& ([scriptblock]::Create((irm https://raw.githubusercontent.com/microsoft/winappCli/main/scripts/winapp-pr.ps1))) -AddToPath

Then this build is just:

winapp-pr 1162

Run winapp-pr with no arguments to pick from a list of open PRs.


Updated 2026-10-22 23:12:26 UTC · commit 26e2118 · workflow run

Restore now uses the app's latest value after an app change, keeps whether
a late-saved original was set on the element, reads a late-saved element back
right away, and asks for attached properties by their full name.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 78fc45e1-7d89-4a89-bb28-898e906b0a15
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 78fc45e1-7d89-4a89-bb28-898e906b0a15
…the pane

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 78fc45e1-7d89-4a89-bb28-898e906b0a15
@zateutsch Zach Teutsch (zateutsch) added ready-for-review Agent work and technical checks complete; awaiting review or re-review, not approval or merge and removed agent-preparing Agent is addressing feedback or completing required validation and CI labels Oct 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-review Agent work and technical checks complete; awaiting review or re-review, not approval or merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: DevTools applies an unsaved edit to the wrong element, and "Restore original" is unreliable

2 participants