diff options
author | Davyd McColl <davydm@gmail.com> | 2021-05-28 12:02:19 +0200 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2021-07-01 17:13:13 +1000 |
commit | a9f04d3925bff4ec487a8c622ce84c79ef64ab87 (patch) | |
tree | 58f80bb76136d06e5c5d189f89fd4174c3099d58 /pkg | |
parent | 83834a2c2e50922d58b052b116d50a9fc3903e84 (diff) |
:sparkles: facilitate toggling whitespace in the diff view with a hotkey (c-w by default)
Diffstat (limited to 'pkg')
-rw-r--r-- | pkg/commands/files.go | 12 | ||||
-rw-r--r-- | pkg/config/user_config.go | 2 | ||||
-rw-r--r-- | pkg/gui/files_panel.go | 4 | ||||
-rw-r--r-- | pkg/gui/gui.go | 3 | ||||
-rw-r--r-- | pkg/gui/keybindings.go | 7 | ||||
-rw-r--r-- | pkg/gui/quitting.go | 5 | ||||
-rw-r--r-- | pkg/gui/staging_panel.go | 4 | ||||
-rw-r--r-- | pkg/gui/submodules_panel.go | 2 | ||||
-rw-r--r-- | pkg/i18n/english.go | 2 |
9 files changed, 32 insertions, 9 deletions
diff --git a/pkg/commands/files.go b/pkg/commands/files.go index 9e077a462..648c5f511 100644 --- a/pkg/commands/files.go +++ b/pkg/commands/files.go @@ -189,17 +189,18 @@ func (c *GitCommand) Ignore(filename string) error { } // WorktreeFileDiff returns the diff of a file -func (c *GitCommand) WorktreeFileDiff(file *models.File, plain bool, cached bool) string { +func (c *GitCommand) WorktreeFileDiff(file *models.File, plain bool, cached bool, ignoreWhitespace bool) string { // for now we assume an error means the file was deleted - s, _ := c.OSCommand.RunCommandWithOutput(c.WorktreeFileDiffCmdStr(file, plain, cached)) + s, _ := c.OSCommand.RunCommandWithOutput(c.WorktreeFileDiffCmdStr(file, plain, cached, ignoreWhitespace)) return s } -func (c *GitCommand) WorktreeFileDiffCmdStr(node models.IFile, plain bool, cached bool) string { +func (c *GitCommand) WorktreeFileDiffCmdStr(node models.IFile, plain bool, cached bool, ignoreWhitespace bool) string { cachedArg := "" trackedArg := "--" colorArg := c.colorArg() path := c.OSCommand.Quote(node.GetPath()) + ignoreWhitespaceArg := "" if cached { cachedArg = "--cached" } @@ -209,8 +210,11 @@ func (c *GitCommand) WorktreeFileDiffCmdStr(node models.IFile, plain bool, cache if plain { colorArg = "never" } + if ignoreWhitespace { + ignoreWhitespaceArg = "-w" + } - return fmt.Sprintf("git diff --submodule --no-ext-diff --color=%s %s %s %s", colorArg, cachedArg, trackedArg, path) + return fmt.Sprintf("git diff --submodule --no-ext-diff --color=%s %s %s %s %s", colorArg, ignoreWhitespaceArg, cachedArg, trackedArg, path) } func (c *GitCommand) ApplyPatch(patch string, flags ...string) error { diff --git a/pkg/config/user_config.go b/pkg/config/user_config.go index e7231a55b..f87567ac0 100644 --- a/pkg/config/user_config.go +++ b/pkg/config/user_config.go @@ -165,6 +165,7 @@ type KeybindingUniversalConfig struct { SubmitEditorText string `yaml:"submitEditorText"` AppendNewline string `yaml:"appendNewline"` ExtrasMenu string `yaml:"extrasMenu"` + ToggleWhitespaceInDiffView string `yaml:"toggleWhitespaceInDiffView"` } type KeybindingStatusConfig struct { @@ -404,6 +405,7 @@ func GetDefaultConfig() *UserConfig { SubmitEditorText: "<enter>", AppendNewline: "<a-enter>", ExtrasMenu: "@", + ToggleWhitespaceInDiffView: "<c-w>", }, Status: KeybindingStatusConfig{ CheckForUpdate: "u", diff --git a/pkg/gui/files_panel.go b/pkg/gui/files_panel.go index 4d225d945..48c0621cb 100644 --- a/pkg/gui/files_panel.go +++ b/pkg/gui/files_panel.go @@ -71,7 +71,7 @@ func (gui *Gui) selectFile(alreadySelected bool) error { return gui.refreshMergePanelWithLock() } - cmdStr := gui.GitCommand.WorktreeFileDiffCmdStr(node, false, !node.GetHasUnstagedChanges() && node.GetHasStagedChanges()) + cmdStr := gui.GitCommand.WorktreeFileDiffCmdStr(node, false, !node.GetHasUnstagedChanges() && node.GetHasStagedChanges(), gui.State.IgnoreWhitespaceInDiffView) cmd := gui.OSCommand.ExecutableFromString(cmdStr) refreshOpts := refreshMainOpts{main: &viewUpdateOpts{ @@ -81,7 +81,7 @@ func (gui *Gui) selectFile(alreadySelected bool) error { if node.GetHasUnstagedChanges() { if node.GetHasStagedChanges() { - cmdStr := gui.GitCommand.WorktreeFileDiffCmdStr(node, false, true) + cmdStr := gui.GitCommand.WorktreeFileDiffCmdStr(node, false, true, gui.State.IgnoreWhitespaceInDiffView) cmd := gui.OSCommand.ExecutableFromString(cmdStr) refreshOpts.secondary = &viewUpdateOpts{ diff --git a/pkg/gui/gui.go b/pkg/gui/gui.go index 990654587..71b9702f2 100644 --- a/pkg/gui/gui.go +++ b/pkg/gui/gui.go @@ -339,6 +339,9 @@ type guiState struct { // do this whenever we switch back and forth between repos to get the views // back in sync with the repo state ViewsSetup bool + + // flag as to whether or not the diff view should ignore whitespace + IgnoreWhitespaceInDiffView bool } // reuseState determines if we pull the repo state from our repo state map or diff --git a/pkg/gui/keybindings.go b/pkg/gui/keybindings.go index 169a1be24..dbcb0b8fe 100644 --- a/pkg/gui/keybindings.go +++ b/pkg/gui/keybindings.go @@ -1720,6 +1720,13 @@ func (gui *Gui) GetInitialKeybindings() []*Binding { OpensMenu: true, }, { + ViewName: "files", + Contexts: []string{string(FILES_CONTEXT_KEY)}, + Key: gui.getKey(config.Universal.ToggleWhitespaceInDiffView), + Handler: gui.toggleWhitespaceInDiffView, + Description: gui.Tr.ToggleWhitespaceInDiffView, + }, + { ViewName: "extras", Key: gocui.MouseWheelUp, Handler: gui.scrollUpExtra, diff --git a/pkg/gui/quitting.go b/pkg/gui/quitting.go index 24b92efc2..8abe2e121 100644 --- a/pkg/gui/quitting.go +++ b/pkg/gui/quitting.go @@ -29,6 +29,11 @@ func (gui *Gui) handleQuitWithoutChangingDirectory() error { return gui.quit() } +func (gui *Gui) toggleWhitespaceInDiffView() error { + gui.State.IgnoreWhitespaceInDiffView = !gui.State.IgnoreWhitespaceInDiffView + return gui.refreshFilesAndSubmodules() +} + func (gui *Gui) handleQuit() error { gui.State.RetainOriginalDir = false return gui.quit() diff --git a/pkg/gui/staging_panel.go b/pkg/gui/staging_panel.go index c016586da..916361fc1 100644 --- a/pkg/gui/staging_panel.go +++ b/pkg/gui/staging_panel.go @@ -34,8 +34,8 @@ func (gui *Gui) refreshStagingPanel(forceSecondaryFocused bool, selectedLineIdx } // note for custom diffs, we'll need to send a flag here saying not to use the custom diff - diff := gui.GitCommand.WorktreeFileDiff(file, true, secondaryFocused) - secondaryDiff := gui.GitCommand.WorktreeFileDiff(file, true, !secondaryFocused) + diff := gui.GitCommand.WorktreeFileDiff(file, true, secondaryFocused, gui.State.IgnoreWhitespaceInDiffView) + secondaryDiff := gui.GitCommand.WorktreeFileDiff(file, true, !secondaryFocused, gui.State.IgnoreWhitespaceInDiffView) // if we have e.g. a deleted file with nothing else to the diff will have only // 4-5 lines in which case we'll swap panels diff --git a/pkg/gui/submodules_panel.go b/pkg/gui/submodules_panel.go index 8a1d8d753..cec3d3397 100644 --- a/pkg/gui/submodules_panel.go +++ b/pkg/gui/submodules_panel.go @@ -37,7 +37,7 @@ func (gui *Gui) handleSubmoduleSelect() error { if file == nil { task = NewRenderStringTask(prefix) } else { - cmdStr := gui.GitCommand.WorktreeFileDiffCmdStr(file, false, !file.HasUnstagedChanges && file.HasStagedChanges) + cmdStr := gui.GitCommand.WorktreeFileDiffCmdStr(file, false, !file.HasUnstagedChanges && file.HasStagedChanges, gui.State.IgnoreWhitespaceInDiffView) cmd := gui.OSCommand.ExecutableFromString(cmdStr) task = NewRunCommandTaskWithPrefix(cmd, prefix) } diff --git a/pkg/i18n/english.go b/pkg/i18n/english.go index fc7d59ebb..755f7c1be 100644 --- a/pkg/i18n/english.go +++ b/pkg/i18n/english.go @@ -451,6 +451,7 @@ type TranslationSet struct { CommandLogHeader string RandomTip string SelectParentCommitForMerge string + ToggleWhitespaceInDiffView string Spans Spans } @@ -995,6 +996,7 @@ func englishTranslationSet() TranslationSet { CommandLogHeader: "You can hide/focus this panel by pressing '%s' or hide it permanently in your config with `gui.showCommandLog: false`\n", RandomTip: "Random Tip", SelectParentCommitForMerge: "Select parent commit for merge", + ToggleWhitespaceInDiffView: "Toggle whether or not whitespace changes are shown in the diff view", Spans: Spans{ // TODO: combine this with the original keybinding descriptions (those are all in lowercase atm) CheckoutCommit: "Checkout commit", |