Skip to content

fix(editor): preserve unsaved Monaco edits across tab switches - #36

Merged
04mg merged 2 commits into
developfrom
fix/editor-persist-unsaved-changes
Jul 21, 2026
Merged

fix(editor): preserve unsaved Monaco edits across tab switches#36
04mg merged 2 commits into
developfrom
fix/editor-persist-unsaved-changes

Conversation

@04mg

@04mg 04mg commented Jul 21, 2026

Copy link
Copy Markdown
Owner

Fixes #35

Summary

Unsaved edits in the Monaco File Editor were lost whenever the user switched tabs/panes and came back, because EditorPanel reloaded the file from disk on every filePath change, overwriting editedContent.

Changes

  • Added a module-level dirtyContentCache: Map<filePath, {dirty, original}> in EditorPanel.
  • On filePath change, if a cached dirty entry exists, it is restored (preserving the * unsaved state) instead of fetching from disk.
  • handleEditorChange writes to the cache on every keystroke.
  • handleSave clears the cache on successful save.
  • silentReload (used by "Reload" on disk conflict) clears the cache so the on-disk version wins.

Validation

  • make lint
  • make build

04mg added 2 commits July 20, 2026 20:46
Wire a focus/blur signal from the frontend (TerminalPanel) through the
terminal WS into the agent status engine so the idle-timeout watchdog
and the watchers' re-bind pass can account for which terminal pane the
user is currently driving.

- terminal: add OnPtyFocus callback and a `focus` message type handled
  in HandleTerminalWS.
- agent: track ptyFocus (single-focus map) with IsPtyFocused accessor;
  clean up on session exit.
- idle-timeout watchdog: exempt the focused PTY from the auto-revert to
  idle even when its output has gone quiet (the user may be mid-prompt
  or reading a long answer).
- watchers (claude/codex/copilot/opencode): allow the re-bind to fire
  when the PTY is focused even without recent PTY output, so a /new or
  /resume issued in the focused pane re-binds before the agent emits
  bytes; an unfocused PTY stays conservative and won't steal a
  sibling's session.
- frontend: TerminalPanel sends focus/blur on isActive changes and
  mirrors the flag onto TerminalInstance so connectWs.onopen re-sends
  it after a reconnect, preventing stale unfocused state.
Cache dirty editor content per filePath in a module-level store so
switching tabs/panes and returning restores in-memory edits instead of
reloading from disk. Cache is cleared on successful save, explicit
reload, or disk-conflict resolution.

Fixes #35
@04mg
04mg merged commit caa2c58 into develop Jul 21, 2026
@04mg
04mg deleted the fix/editor-persist-unsaved-changes branch July 21, 2026 00:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Monaco editor loses unsaved changes when switching tabs

1 participant