Skip to content

fix(desktop): preserve commit reword drafts across navigation#14361

Open
ameyypawar wants to merge 2 commits into
gitbutlerapp:masterfrom
ameyypawar:fix/preserve-reword-draft
Open

fix(desktop): preserve commit reword drafts across navigation#14361
ameyypawar wants to merge 2 commits into
gitbutlerapp:masterfrom
ameyypawar:fix/preserve-reword-draft

Conversation

@ameyypawar

Copy link
Copy Markdown
Contributor

Reword (edit commit message) drafts were lost on context switch — start editing a commit's message, navigate to another commit/branch/repo, come back, and the draft is gone. New-commit drafts already survive.

Cause: CommitView.svelte mounted the reword editor seeded from the original message with no onChange, so the draft lived only in the editor's local state and was destroyed when the editor unmounted on context switch. NewCommitView avoids this by persisting into lane.newCommitMessage (redux).

Fix: mirror that, scoped to reword — persist the draft per-commit in lane UI state, seed the editor from it, clear it on save or explicit cancel:

  • lib/commits/editCommitDraft.ts — pure resolveEditDraft / applyEditDraftUpdate helpers (+ EditCommitMessage type), with unit tests.
  • lib/state/uiState.svelte.ts — add editCommitMessage to lane StackState.
  • components/commit/CommitView.svelte — seed from the draft, persist on change, clear on save + explicit cancel.

Behavior: navigate away / close the drawer → draft preserved; return → restored; Cancel → discarded; Save → cleared. (RichTextEditor only seeds when empty, so restore happens on remount and there's no caret reset while typing.)

Two design points worth a maintainer call (cc @PavelLaptev, per the issue thread):

  1. Editor Cancel/Escape discard, but Drawer close / navigation preserve — biased toward preserving so navigation reliably keeps the draft. Happy to make Drawer-close discard too if preferred.
  2. One reword draft per lane, keyed by commit — starting to edit a second commit before returning overwrites the first's draft.

prettier, eslint, svelte-check (0 errors / 0 warnings), and the new vitest suite (7 cases) pass locally.

Fixes #13287

Reword (edit commit message) drafts lived only in the editor component's
local state, so switching context unmounted the editor and discarded the
draft. New-commit drafts already survive via `lane.newCommitMessage`.

Persist the reword draft per-commit in lane UI state: seed the editor from
it, save it on every change, and clear it on save or explicit cancel. The
draft now survives navigating away and back; only Cancel discards it.

Fixes gitbutlerapp#13287
Add a per-commit `editCommitMessage` slot to lane UI state, and make
CommitView seed the reword editor from it, persist on every change, and
clear it on save / explicit cancel.

Fixes gitbutlerapp#13287
@Byron

Byron commented Jun 22, 2026

Copy link
Copy Markdown
Collaborator

Thanks for giving it a shot.

Could you please add before and after videos? This would make it so much easier to get started with the review.
Thanks again.

@Byron Byron added the feedback requested Feedback was requested to help resolve the issue label Jun 22, 2026
@ameyypawar

Copy link
Copy Markdown
Contributor Author
after.mov

@ameyypawar

Copy link
Copy Markdown
Contributor Author
before.mov

@Byron Byron left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks a lot for the videos!

In the interest of time, I didn't validate this locally, just because I think the PR should receive its final approval from @mtsgrd. To me the code looks good and quite minimal, but I am missing the big picture to truly judge its fitness.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feedback requested Feedback was requested to help resolve the issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Extremely easy to lose commit message drafts

2 participants