jesseduffield.lazygit/pkg/gui/controllers
Stefan Haller 227081f1d1 Preserve whitespace when remembering a commit message
This is useful when cancelling out of the commit panel mid-sentence (after
having typed the space for the next word); when entering the commit message
panel again, the space was gone and you had to type it again. Small thing, but
it just seems better to resume the panel in exactly the state that you left it
in. (Which we actually don't do; we don't remember the cursor position, or which
of the subject/description panels was active. That would be a separate
improvement.)

The save path and the load path used to be asymmetric. On save, the textarea
getters applied strings.TrimSpace, which stripped any leading blank lines, a
trailing newline after the cursor, or indentation on the very first line of the
description — all of which are legitimate user content. On load,
SplitCommitMessageAndDescription did TrimSpace on the description as well, and
the preserved message was routed through that same git-format split because
HandleCommitPress passed it as OpenCommitMessagePanel's InitialMessage. The
result: every round-trip through "escape and reopen" silently mutated the
message.

The fix is to treat our own preservation file as its own format, distinct from
git's canonical "summary\n\nbody" format:

- The textarea getters return raw content. strings.TrimSpace moves to the one
  place that still needs it: the empty-summary check in HandleCommitConfirm (git
  itself strips trailing whitespace and blank lines, so no pre-trim is needed
  before -m).
- SplitPreservedCommitMessage / SetPreservedMessageInView split on the single
  "\n" our Join uses, without any trimming — truly lossless.
- SplitCommitMessageAndDescription keeps its git-format behavior but replaces
  TrimSpace with TrimPrefix("\n"), so it strips only the blank-line separator
  and leaves body indentation intact.
- HandleCommitPress now mirrors HandleWIPCommitPress: it no longer passes the
  preserved message as InitialMessage. OpenCommitMessagePanel resolves the
  preserved content itself, uses it for display via the preservation-format
  setter, and stores it as the initial message so the close-time "did the user
  change anything?" check still correctly detects a cleared panel.
- GetInitialMessage no longer trims. With raw getters on both sides of the
  comparison, trimming here caused spurious non-matches (e.g. for preserved
  content with trailing whitespace). The original motivation — matching a
  "WIP: " prefix with trailing space — works unchanged.
- UpdateCommitPanelView becomes dead code and is removed; its one remaining
  caller (history cycling, always git-format) goes directly through
  SetMessageAndDescriptionInView.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-21 18:51:17 +02:00
..
helpers Preserve whitespace when remembering a commit message 2026-04-21 18:51:17 +02:00
attach.go Add OnQuit hook for controllers 2026-04-21 11:25:29 +02:00
base_controller.go Add OnQuit hook for controllers 2026-04-21 11:25:29 +02:00
basic_commits_controller.go Remove the "old cherry-pick key" warning 2026-01-28 10:15:15 +01:00
bisect_controller.go Change Refresh to not return an error 2025-07-02 16:09:42 +02:00
branches_controller.go Hide closed pull requests on main branches 2026-04-13 21:56:49 +02:00
command_log_controller.go Remove return value of Focus-related functions 2024-09-06 08:45:48 +02:00
commit_description_controller.go Preserve commit message when quitting while the commit message panel is open 2026-04-21 11:25:29 +02:00
commit_message_controller.go Preserve whitespace when remembering a commit message 2026-04-21 18:51:17 +02:00
commits_files_controller.go Fix copying a file's absolute path when running in a linked worktree 2026-04-19 11:16:02 +02:00
common.go lots of changes 2023-04-30 13:19:53 +10:00
confirmation_controller.go Refactor: add a separate Prompt view 2025-09-05 10:42:03 +02:00
context_lines_controller.go Cleanup: use CurrentSide() instead of private currentSidePanel 2026-03-09 19:42:28 +01:00
custom_patch_options_menu_action.go Remove redundant CantPatchWhileRebasingError checks in handlers 2026-03-07 20:47:19 +11:00
diffing_menu_action.go Remove TrimSpace calls that are no longer needed 2025-11-15 15:38:24 +01:00
files_controller.go Fix copying a file's absolute path when running in a linked worktree 2026-04-19 11:16:02 +02:00
filter_controller.go Introduce filtered list view model 2023-07-03 12:54:13 +10:00
filtering_menu_action.go Remove TrimSpace calls that are no longer needed 2025-11-15 15:38:24 +01:00
git_flow_controller.go Remove unnecessary type arguments 2025-03-03 21:24:49 +01:00
global_controller.go Replace paging config with an array of pagers 2025-10-14 12:17:13 +02:00
jump_to_side_window_controller.go Cleanup: get rid of the variadic parameter of ContextMgr.Push 2025-04-08 16:08:25 +02:00
list_controller.go Add GetOnClick to HasKeybindings 2026-03-25 17:08:02 +01:00
list_controller_trait.go Enable nolintlint linter, and fix warnings 2025-06-30 18:30:11 +02:00
local_commits_controller.go Add commands for opening a Github PR in the browser 2026-04-01 09:13:55 +02:00
local_commits_controller_test.go Move isFixupCommit to FixupHelper 2026-01-24 16:04:35 +01:00
main_view_controller.go Show "Exit back to side panel" in options status bar for focused main view 2025-08-14 17:59:38 +02:00
menu_controller.go Call OnMenuPress(nil) when hitting esc in a menu 2026-04-01 09:13:55 +02:00
merge_conflicts_controller.go Add merge options menu 2025-10-09 08:45:58 +02:00
options_menu_action.go Rename KeepConfirmKeybindings to KeepConflictingKeybindings 2025-12-22 09:37:06 +01:00
patch_building_controller.go Prevent patch building panel from briefly appearing when discarding change from commit 2026-03-07 20:47:20 +11:00
patch_explorer_controller.go Change the "toggle hunk selection" binding description to be dynamic 2025-08-01 10:35:16 +02:00
patch_explorer_controller_test.go Strip the '+' and '-' characters when copying parts of a diff to the clipboard 2025-04-29 11:33:47 +02:00
prompt_controller.go Hard-code "enter" for editable prompts 2025-09-05 10:42:04 +02:00
quit_actions.go Show context-specific labels for the global <esc> binding 2025-08-14 17:59:38 +02:00
reflog_commits_controller.go Fix showing diffs for renamed file when filtering by path 2025-07-27 12:05:41 +02:00
remote_branches_controller.go Add a prompt for the sort order menus for branches 2025-07-09 13:16:42 +02:00
remotes_controller.go Rename GetOnClick (et al) to GetOnDoubleClick 2026-03-25 14:58:53 +01:00
remotes_controller_test.go feat: add fork remote command 2025-11-16 17:26:00 +01:00
rename_similarity_threshold_controller.go Cleanup: use CurrentSide() instead of private currentSidePanel 2026-03-09 19:42:28 +01:00
screen_mode_actions.go Re-render main view when changing screen mode 2026-03-09 19:42:28 +01:00
scroll_off_margin.go Replace min/max helpers with built-in min/max 2024-04-07 23:24:10 +08:00
scroll_off_margin_test.go Add tests for scroll-off margin of zero 2023-08-21 08:10:28 +02:00
search_controller.go Introduce filtered list view model 2023-07-03 12:54:13 +10:00
search_prompt_controller.go Hard-code "enter" for search prompt 2025-09-05 10:42:04 +02:00
shell_command_action.go Strip leading/trailing whitespace from prompt input 2025-11-15 15:38:24 +01:00
side_window_controller.go Cleanup: get rid of the variadic parameter of ContextMgr.Push 2025-04-08 16:08:25 +02:00
snake_controller.go Cleanup: get rid of the variadic parameter of ContextMgr.Push 2025-04-08 16:08:25 +02:00
staging_controller.go Show context-specific labels for <esc> in staging and patch building view 2025-08-14 17:59:38 +02:00
stash_controller.go Localize "Dropping stash" log 2026-04-06 19:06:25 +02:00
status_controller.go Add backward cycling support for all branches log view 2026-03-08 17:06:17 +01:00
sub_commits_controller.go Use async refresh rather than manual OnWorker call 2025-07-02 16:10:04 +02:00
submodules_controller.go Rename GetOnClick (et al) to GetOnDoubleClick 2026-03-25 14:58:53 +01:00
suggestions_controller.go Add separate keybindings for confirmMenu and confirmSuggestion 2025-09-05 10:42:04 +02:00
switch_to_diff_files_controller.go Rename GetOnClick (et al) to GetOnDoubleClick 2026-03-25 14:58:53 +01:00
switch_to_focused_main_view_controller.go Move the "Focus main view" command to the global section of the keybindings menu 2025-07-27 12:25:16 +02:00
switch_to_sub_commits_controller.go Rename GetOnClick (et al) to GetOnDoubleClick 2026-03-25 14:58:53 +01:00
sync_controller.go Change Refresh to not return an error 2025-07-02 16:09:42 +02:00
tags_controller.go Switch to branches view when checking out a commit 2025-11-16 21:23:40 +01:00
toggle_whitespace_action.go Move IgnoreWhitespaceInDiffView to user config 2025-07-09 13:15:03 +02:00
undo_controller.go Avoid auto-stashing when only submodules are out of date 2025-10-16 12:00:31 +02:00
vertical_scroll_controller.go Add IGuiCommon.GetViewBufferManagerForView 2025-04-21 18:03:18 +02:00
view_selection_controller.go Read all lines from task when jumping to bottom 2025-04-21 18:03:19 +02:00
workspace_reset_controller.go Avoid auto-stashing when only submodules are out of date 2025-10-16 12:00:31 +02:00
worktree_options_controller.go Remove unnecessary type arguments 2025-03-03 21:24:49 +01:00
worktrees_controller.go Rename GetOnClick (et al) to GetOnDoubleClick 2026-03-25 14:58:53 +01:00