-
-
Notifications
You must be signed in to change notification settings - Fork 141
Closed
Labels
Description
Feature
Bidirectional selection sync between the XAML Designer canvas and the code editor (VS-like).
Commits: 73bca10e, 6e553bc9 on branch DebugNewFeatures
What was implemented
Canvas → Code
- Clicking an element on the canvas navigates the code editor caret to the element's opening tag line.
- Uses
XamlSourceLocationService.FindElementStartLine(XDocument +IXmlLineInfo).
Code → Canvas
- Moving the caret in the code editor (no active text selection) selects the matching element on the canvas.
- Debounced at 150ms via
_codeToCanvasSyncTimer; fires on bothCaretMoved(line changes) andSelectionChanged(same-line clicks). - Uses
XamlSourceLocationService.FindUidAtLine(XmlReader + IXmlLineInfo, pre-order UID traversal).
Quality fixes (commit 6e553bc9)
- Post-render preserve selection: canvas no longer loses selection after every 500ms debounce re-render.
- Silent selection API:
SelectElement(suppressEvent:true)/SelectElementByUid(suppressEvent:true)for programmatic restores. - ApplyXamlToCode guard:
_isSyncingSelection=truepreventsLoadFromStringcaret-reset from triggering spurious root-element sync. - Caret theft prevention: skip
NavigateTowhen code editor is already on the correct line.
Test scenarios to validate
- Click Button on canvas → code editor caret jumps to
<Buttonline - Press Escape on canvas (select parent) → code editor moves to parent's line
- Click on
<Buttonin code editor → Button gets selection adorner on canvas - Click same line multiple times → canvas still re-syncs correctly
- Edit
Width="100"→ canvas re-renders → element stays selected (not deselected) - Drag resize handle, release → code updates → canvas re-renders → element stays selected, code caret not stolen
- Click Button on canvas twice → code editor does NOT move on 2nd click (already on line)
- Rapid keyboard navigation (10 lines) → canvas syncs once after 150ms idle
- Switch to Code-Only mode → no canvas sync fires
- Switch back to Split mode → sync resumes on next caret move
- Undo/Redo after design operation → selection preserved, no feedback loop
Known limitations / risk areas
- UID numbering uses raw XAML (not sanitized). If
SanitizeForPreviewever removes entire elements (currently only strips attributes), UIDs would desync. - Single-line compact XAML (
<Grid><Button/></Grid>) always syncs to the last (deepest) element on the line — acceptable behavior. SelectionChangedsubscription may fire during text drag-select; guarded bySelection.IsEmptycheck.
Reactions are currently unavailable