mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-04-19 12:12:42 +02:00
✨ facilitate toggling whitespace in the diff view with a hotkey (c-w by default)
This commit is contained in:
parent
83834a2c2e
commit
a9f04d3925
@ -189,17 +189,18 @@ func (c *GitCommand) Ignore(filename string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// WorktreeFileDiff returns the diff of a file
|
// 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
|
// 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
|
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 := ""
|
cachedArg := ""
|
||||||
trackedArg := "--"
|
trackedArg := "--"
|
||||||
colorArg := c.colorArg()
|
colorArg := c.colorArg()
|
||||||
path := c.OSCommand.Quote(node.GetPath())
|
path := c.OSCommand.Quote(node.GetPath())
|
||||||
|
ignoreWhitespaceArg := ""
|
||||||
if cached {
|
if cached {
|
||||||
cachedArg = "--cached"
|
cachedArg = "--cached"
|
||||||
}
|
}
|
||||||
@ -209,8 +210,11 @@ func (c *GitCommand) WorktreeFileDiffCmdStr(node models.IFile, plain bool, cache
|
|||||||
if plain {
|
if plain {
|
||||||
colorArg = "never"
|
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 {
|
func (c *GitCommand) ApplyPatch(patch string, flags ...string) error {
|
||||||
|
@ -165,6 +165,7 @@ type KeybindingUniversalConfig struct {
|
|||||||
SubmitEditorText string `yaml:"submitEditorText"`
|
SubmitEditorText string `yaml:"submitEditorText"`
|
||||||
AppendNewline string `yaml:"appendNewline"`
|
AppendNewline string `yaml:"appendNewline"`
|
||||||
ExtrasMenu string `yaml:"extrasMenu"`
|
ExtrasMenu string `yaml:"extrasMenu"`
|
||||||
|
ToggleWhitespaceInDiffView string `yaml:"toggleWhitespaceInDiffView"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type KeybindingStatusConfig struct {
|
type KeybindingStatusConfig struct {
|
||||||
@ -404,6 +405,7 @@ func GetDefaultConfig() *UserConfig {
|
|||||||
SubmitEditorText: "<enter>",
|
SubmitEditorText: "<enter>",
|
||||||
AppendNewline: "<a-enter>",
|
AppendNewline: "<a-enter>",
|
||||||
ExtrasMenu: "@",
|
ExtrasMenu: "@",
|
||||||
|
ToggleWhitespaceInDiffView: "<c-w>",
|
||||||
},
|
},
|
||||||
Status: KeybindingStatusConfig{
|
Status: KeybindingStatusConfig{
|
||||||
CheckForUpdate: "u",
|
CheckForUpdate: "u",
|
||||||
|
@ -71,7 +71,7 @@ func (gui *Gui) selectFile(alreadySelected bool) error {
|
|||||||
return gui.refreshMergePanelWithLock()
|
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)
|
cmd := gui.OSCommand.ExecutableFromString(cmdStr)
|
||||||
|
|
||||||
refreshOpts := refreshMainOpts{main: &viewUpdateOpts{
|
refreshOpts := refreshMainOpts{main: &viewUpdateOpts{
|
||||||
@ -81,7 +81,7 @@ func (gui *Gui) selectFile(alreadySelected bool) error {
|
|||||||
|
|
||||||
if node.GetHasUnstagedChanges() {
|
if node.GetHasUnstagedChanges() {
|
||||||
if node.GetHasStagedChanges() {
|
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)
|
cmd := gui.OSCommand.ExecutableFromString(cmdStr)
|
||||||
|
|
||||||
refreshOpts.secondary = &viewUpdateOpts{
|
refreshOpts.secondary = &viewUpdateOpts{
|
||||||
|
@ -339,6 +339,9 @@ type guiState struct {
|
|||||||
// do this whenever we switch back and forth between repos to get the views
|
// do this whenever we switch back and forth between repos to get the views
|
||||||
// back in sync with the repo state
|
// back in sync with the repo state
|
||||||
ViewsSetup bool
|
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
|
// reuseState determines if we pull the repo state from our repo state map or
|
||||||
|
@ -1719,6 +1719,13 @@ func (gui *Gui) GetInitialKeybindings() []*Binding {
|
|||||||
Description: gui.Tr.LcViewBulkSubmoduleOptions,
|
Description: gui.Tr.LcViewBulkSubmoduleOptions,
|
||||||
OpensMenu: true,
|
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",
|
ViewName: "extras",
|
||||||
Key: gocui.MouseWheelUp,
|
Key: gocui.MouseWheelUp,
|
||||||
|
@ -29,6 +29,11 @@ func (gui *Gui) handleQuitWithoutChangingDirectory() error {
|
|||||||
return gui.quit()
|
return gui.quit()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (gui *Gui) toggleWhitespaceInDiffView() error {
|
||||||
|
gui.State.IgnoreWhitespaceInDiffView = !gui.State.IgnoreWhitespaceInDiffView
|
||||||
|
return gui.refreshFilesAndSubmodules()
|
||||||
|
}
|
||||||
|
|
||||||
func (gui *Gui) handleQuit() error {
|
func (gui *Gui) handleQuit() error {
|
||||||
gui.State.RetainOriginalDir = false
|
gui.State.RetainOriginalDir = false
|
||||||
return gui.quit()
|
return gui.quit()
|
||||||
|
@ -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
|
// 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)
|
diff := gui.GitCommand.WorktreeFileDiff(file, true, secondaryFocused, gui.State.IgnoreWhitespaceInDiffView)
|
||||||
secondaryDiff := gui.GitCommand.WorktreeFileDiff(file, true, !secondaryFocused)
|
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
|
// 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
|
// 4-5 lines in which case we'll swap panels
|
||||||
|
@ -37,7 +37,7 @@ func (gui *Gui) handleSubmoduleSelect() error {
|
|||||||
if file == nil {
|
if file == nil {
|
||||||
task = NewRenderStringTask(prefix)
|
task = NewRenderStringTask(prefix)
|
||||||
} else {
|
} 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)
|
cmd := gui.OSCommand.ExecutableFromString(cmdStr)
|
||||||
task = NewRunCommandTaskWithPrefix(cmd, prefix)
|
task = NewRunCommandTaskWithPrefix(cmd, prefix)
|
||||||
}
|
}
|
||||||
|
@ -451,6 +451,7 @@ type TranslationSet struct {
|
|||||||
CommandLogHeader string
|
CommandLogHeader string
|
||||||
RandomTip string
|
RandomTip string
|
||||||
SelectParentCommitForMerge string
|
SelectParentCommitForMerge string
|
||||||
|
ToggleWhitespaceInDiffView string
|
||||||
Spans Spans
|
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",
|
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",
|
RandomTip: "Random Tip",
|
||||||
SelectParentCommitForMerge: "Select parent commit for merge",
|
SelectParentCommitForMerge: "Select parent commit for merge",
|
||||||
|
ToggleWhitespaceInDiffView: "Toggle whether or not whitespace changes are shown in the diff view",
|
||||||
Spans: Spans{
|
Spans: Spans{
|
||||||
// TODO: combine this with the original keybinding descriptions (those are all in lowercase atm)
|
// TODO: combine this with the original keybinding descriptions (those are all in lowercase atm)
|
||||||
CheckoutCommit: "Checkout commit",
|
CheckoutCommit: "Checkout commit",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user