Skip to content

Commit e29ddf4

Browse files
authored
Wrap lines in staging view (#4098)
- **PR Description** Add a user config (on by default) to turn on line wrapping in the staging view (and custom patch building view). Fixes #3558. This is a bit of a longer PR because I had to fix a bunch of things to make this possible, and because it takes much more than just turning on `Wrap` on the staging view. Usually when I make changes to gocui I include them in the lazygit PR for easier review; this time, however, the changes required touching gocui's tests, which are not included in our vendored copy, so I made a [PR in gocui](jesseduffield/gocui#67) to be reviewed there, and only included the squashed changes here. Hot-reloading of the new user config is not perfect: if the staging view is focused, you need to escape out of it and enter it again for the change to take affect. I wasn't sure it's worth adding code to fix this. As for tests: I didn't find a way to add an integration test for this, as the view geometry is not fixed when you run them locally. But I didn't look into this very deeply. - **Please check if the PR fulfills these requirements** * [x] Cheatsheets are up-to-date (run `go generate ./...`) * [x] Code has been formatted (see [here](https://github.com/jesseduffield/lazygit/blob/master/CONTRIBUTING.md#code-formatting)) * [x] Tests have been added/updated (see [here](https://github.com/jesseduffield/lazygit/blob/master/pkg/integration/README.md) for the integration test guide) * [x] Text is internationalised (see [here](https://github.com/jesseduffield/lazygit/blob/master/CONTRIBUTING.md#internationalisation)) * [x] If a new UserConfig entry was added, make sure it can be hot-reloaded (see [here](https://github.com/jesseduffield/lazygit/blob/master/docs/dev/Codebase_Guide.md#using-userconfig)) * [ ] Docs have been updated if necessary * [x] You've read through your own file changes for silly mistakes etc
2 parents b61c395 + 15288b7 commit e29ddf4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+745
-169
lines changed

docs/Config.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,11 @@ gui:
8787
# - 'top': split the window vertically (side panel on top, main view below)
8888
enlargedSideViewLocation: left
8989

90+
# If true, wrap lines in the staging view to the width of the view. This
91+
# makes it much easier to work with diffs that have long lines, e.g.
92+
# paragraphs of markdown text.
93+
wrapLinesInStagingView: true
94+
9095
# One of 'auto' (default) | 'en' | 'zh-CN' | 'zh-TW' | 'pl' | 'nl' | 'ja' | 'ko' | 'ru'
9196
language: auto
9297

go.mod

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ require (
1616
github.com/integrii/flaggy v1.4.0
1717
github.com/jesseduffield/generics v0.0.0-20220320043834-727e535cbe68
1818
github.com/jesseduffield/go-git/v5 v5.1.2-0.20221018185014-fdd53fef665d
19-
github.com/jesseduffield/gocui v0.3.1-0.20241201093724-68c437bbd543
19+
github.com/jesseduffield/gocui v0.3.1-0.20241223111608-9967d0e928a0
2020
github.com/jesseduffield/kill v0.0.0-20220618033138-bfbe04675d10
2121
github.com/jesseduffield/lazycore v0.0.0-20221012050358-03d2e40243c5
2222
github.com/jesseduffield/minimal/gitignore v0.3.3-0.20211018110810-9cde264e6b1e
@@ -38,7 +38,7 @@ require (
3838
github.com/stretchr/testify v1.8.1
3939
github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778
4040
golang.org/x/exp v0.0.0-20220318154914-8dddf5d87bd8
41-
golang.org/x/sync v0.9.0
41+
golang.org/x/sync v0.10.0
4242
gopkg.in/ozeidan/fuzzy-patricia.v3 v3.0.0
4343
gopkg.in/yaml.v3 v3.0.1
4444
)
@@ -75,8 +75,8 @@ require (
7575
github.com/xanzy/ssh-agent v0.2.1 // indirect
7676
golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa // indirect
7777
golang.org/x/net v0.7.0 // indirect
78-
golang.org/x/sys v0.27.0 // indirect
79-
golang.org/x/term v0.26.0 // indirect
80-
golang.org/x/text v0.20.0 // indirect
78+
golang.org/x/sys v0.28.0 // indirect
79+
golang.org/x/term v0.27.0 // indirect
80+
golang.org/x/text v0.21.0 // indirect
8181
gopkg.in/warnings.v0 v0.1.2 // indirect
8282
)

go.sum

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,8 @@ github.com/jesseduffield/generics v0.0.0-20220320043834-727e535cbe68 h1:EQP2Tv8T
188188
github.com/jesseduffield/generics v0.0.0-20220320043834-727e535cbe68/go.mod h1:+LLj9/WUPAP8LqCchs7P+7X0R98HiFujVFANdNaxhGk=
189189
github.com/jesseduffield/go-git/v5 v5.1.2-0.20221018185014-fdd53fef665d h1:bO+OmbreIv91rCe8NmscRwhFSqkDJtzWCPV4Y+SQuXE=
190190
github.com/jesseduffield/go-git/v5 v5.1.2-0.20221018185014-fdd53fef665d/go.mod h1:nGNEErzf+NRznT+N2SWqmHnDnF9aLgANB1CUNEan09o=
191-
github.com/jesseduffield/gocui v0.3.1-0.20241201093724-68c437bbd543 h1:mizrpmhRsYX6G7pqaLH+Rg9zdQ05S7xYVHTvSuBSX70=
192-
github.com/jesseduffield/gocui v0.3.1-0.20241201093724-68c437bbd543/go.mod h1:XtEbqCbn45keRXEu+OMZkjN5gw6AEob59afsgHjokZ8=
191+
github.com/jesseduffield/gocui v0.3.1-0.20241223111608-9967d0e928a0 h1:R29+E15wHqTDBfZxmzCLu0x34j5ljsXWT/DhR+2YiOU=
192+
github.com/jesseduffield/gocui v0.3.1-0.20241223111608-9967d0e928a0/go.mod h1:XtEbqCbn45keRXEu+OMZkjN5gw6AEob59afsgHjokZ8=
193193
github.com/jesseduffield/kill v0.0.0-20220618033138-bfbe04675d10 h1:jmpr7KpX2+2GRiE91zTgfq49QvgiqB0nbmlwZ8UnOx0=
194194
github.com/jesseduffield/kill v0.0.0-20220618033138-bfbe04675d10/go.mod h1:aA97kHeNA+sj2Hbki0pvLslmE4CbDyhBeSSTUUnOuVo=
195195
github.com/jesseduffield/lazycore v0.0.0-20221012050358-03d2e40243c5 h1:CDuQmfOjAtb1Gms6a1p5L2P8RhbLUq5t8aL7PiQd2uY=
@@ -424,8 +424,8 @@ golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJ
424424
golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
425425
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
426426
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
427-
golang.org/x/sync v0.9.0 h1:fEo0HyrW1GIgZdpbhCRO0PkJajUS5H9IFUztCgEo2jQ=
428-
golang.org/x/sync v0.9.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
427+
golang.org/x/sync v0.10.0 h1:3NQrjDixjgGwUOCaF8w2+VYHv0Ve/vGYSbdkTa98gmQ=
428+
golang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
429429
golang.org/x/sys v0.0.0-20170407050850-f3918c30c5c2/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
430430
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
431431
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
@@ -475,14 +475,14 @@ golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBc
475475
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
476476
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
477477
golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
478-
golang.org/x/sys v0.27.0 h1:wBqf8DvsY9Y/2P8gAfPDEYNuS30J4lPHJxXSb/nJZ+s=
479-
golang.org/x/sys v0.27.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
478+
golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA=
479+
golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
480480
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
481481
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
482482
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
483483
golang.org/x/term v0.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk=
484-
golang.org/x/term v0.26.0 h1:WEQa6V3Gja/BhNxg540hBip/kkaYtRg3cxg4oXSw4AU=
485-
golang.org/x/term v0.26.0/go.mod h1:Si5m1o57C5nBNQo5z1iq+XDijt21BDBDp2bK0QI8e3E=
484+
golang.org/x/term v0.27.0 h1:WP60Sv1nlK1T6SupCHbXzSaN0b9wUmsPoRS9b61A23Q=
485+
golang.org/x/term v0.27.0/go.mod h1:iMsnZpn0cago0GOrHO2+Y7u7JPn5AylBrcoWkElMTSM=
486486
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
487487
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
488488
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
@@ -493,8 +493,8 @@ golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
493493
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
494494
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
495495
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
496-
golang.org/x/text v0.20.0 h1:gK/Kv2otX8gz+wn7Rmb3vT96ZwuoxnQlY+HlJVj7Qug=
497-
golang.org/x/text v0.20.0/go.mod h1:D4IsuqiFMhST5bX19pQ9ikHC2GsaKyk/oF+pn3ducp4=
496+
golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo=
497+
golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ=
498498
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
499499
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
500500
golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=

pkg/config/user_config.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,10 @@ type GuiConfig struct {
9191
// - 'left': split the window horizontally (side panel on the left, main view on the right)
9292
// - 'top': split the window vertically (side panel on top, main view below)
9393
EnlargedSideViewLocation string `yaml:"enlargedSideViewLocation"`
94+
// If true, wrap lines in the staging view to the width of the view. This
95+
// makes it much easier to work with diffs that have long lines, e.g.
96+
// paragraphs of markdown text.
97+
WrapLinesInStagingView bool `yaml:"wrapLinesInStagingView"`
9498
// One of 'auto' (default) | 'en' | 'zh-CN' | 'zh-TW' | 'pl' | 'nl' | 'ja' | 'ko' | 'ru'
9599
Language string `yaml:"language" jsonschema:"enum=auto,enum=en,enum=zh-TW,enum=zh-CN,enum=pl,enum=nl,enum=ja,enum=ko,enum=ru"`
96100
// Format used when displaying time e.g. commit time.
@@ -692,6 +696,7 @@ func GetDefaultConfig() *UserConfig {
692696
ExpandedSidePanelWeight: 2,
693697
MainPanelSplitMode: "flexible",
694698
EnlargedSideViewLocation: "left",
699+
WrapLinesInStagingView: true,
695700
Language: "auto",
696701
TimeFormat: "02 Jan 06",
697702
ShortTimeFormat: time.Kitchen,

pkg/gui/context/patch_explorer_context.go

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,13 @@ func NewPatchExplorerContext(
3939
mutex: &deadlock.Mutex{},
4040
getIncludedLineIndices: getIncludedLineIndices,
4141
SimpleContext: NewSimpleContext(NewBaseContext(NewBaseContextOpts{
42-
View: view,
43-
WindowName: windowName,
44-
Key: key,
45-
Kind: types.MAIN_CONTEXT,
46-
Focusable: true,
47-
HighlightOnFocus: true,
42+
View: view,
43+
WindowName: windowName,
44+
Key: key,
45+
Kind: types.MAIN_CONTEXT,
46+
Focusable: true,
47+
HighlightOnFocus: true,
48+
NeedsRerenderOnWidthChange: types.NEEDS_RERENDER_ON_WIDTH_CHANGE_WHEN_WIDTH_CHANGES,
4849
})),
4950
SearchTrait: NewSearchTrait(c),
5051
}
@@ -58,6 +59,8 @@ func NewPatchExplorerContext(
5859
}),
5960
)
6061

62+
ctx.SetHandleRenderFunc(ctx.OnViewWidthChanged)
63+
6164
return ctx
6265
}
6366

@@ -106,13 +109,13 @@ func (self *PatchExplorerContext) FocusSelection() {
106109
state := self.GetState()
107110
bufferHeight := view.InnerHeight()
108111
_, origin := view.Origin()
109-
numLines := view.LinesHeight()
112+
numLines := view.ViewLinesHeight()
110113

111114
newOriginY := state.CalculateOrigin(origin, bufferHeight, numLines)
112115

113116
view.SetOriginY(newOriginY)
114117

115-
startIdx, endIdx := state.SelectedRange()
118+
startIdx, endIdx := state.SelectedViewRange()
116119
// As far as the view is concerned, we are always selecting a range
117120
view.SetRangeSelectStart(startIdx)
118121
view.SetCursorY(endIdx - newOriginY)
@@ -140,3 +143,11 @@ func (self *PatchExplorerContext) GetMutex() *deadlock.Mutex {
140143
func (self *PatchExplorerContext) ModelSearchResults(searchStr string, caseSensitive bool) []gocui.SearchPosition {
141144
return nil
142145
}
146+
147+
func (self *PatchExplorerContext) OnViewWidthChanged() {
148+
if state := self.GetState(); state != nil {
149+
state.OnViewWidthChanged(self.GetView())
150+
self.setContent()
151+
self.RenderAndFocus()
152+
}
153+
}

pkg/gui/context/simple_context.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77

88
type SimpleContext struct {
99
*BaseContext
10+
handleRenderFunc func()
1011
}
1112

1213
func NewSimpleContext(baseContext *BaseContext) *SimpleContext {
@@ -54,6 +55,13 @@ func (self *SimpleContext) HandleFocusLost(opts types.OnFocusLostOpts) {
5455
}
5556

5657
func (self *SimpleContext) HandleRender() {
58+
if self.handleRenderFunc != nil {
59+
self.handleRenderFunc()
60+
}
61+
}
62+
63+
func (self *SimpleContext) SetHandleRenderFunc(f func()) {
64+
self.handleRenderFunc = f
5765
}
5866

5967
func (self *SimpleContext) HandleRenderToMain() {

pkg/gui/controllers/helpers/confirmation_helper.go

Lines changed: 4 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@ package helpers
33
import (
44
goContext "context"
55
"fmt"
6-
"strings"
76

87
"github.com/jesseduffield/lazygit/pkg/gui/style"
98
"github.com/jesseduffield/lazygit/pkg/gui/types"
109
"github.com/jesseduffield/lazygit/pkg/theme"
11-
"github.com/mattn/go-runewidth"
10+
"github.com/jesseduffield/lazygit/pkg/utils"
1211
)
1312

1413
type ConfirmationHelper struct {
@@ -57,61 +56,9 @@ func (self *ConfirmationHelper) DeactivateConfirmationPrompt() {
5756
self.clearConfirmationViewKeyBindings()
5857
}
5958

60-
// Temporary hack: we're just duplicating the logic in `gocui.lineWrap`
6159
func getMessageHeight(wrap bool, message string, width int) int {
62-
return len(wrapMessageToWidth(wrap, message, width))
63-
}
64-
65-
func wrapMessageToWidth(wrap bool, message string, width int) []string {
66-
lines := strings.Split(message, "\n")
67-
if !wrap {
68-
return lines
69-
}
70-
71-
wrappedLines := make([]string, 0, len(lines))
72-
73-
for _, line := range lines {
74-
n := 0
75-
offset := 0
76-
lastWhitespaceIndex := -1
77-
for i, currChr := range line {
78-
rw := runewidth.RuneWidth(currChr)
79-
n += rw
80-
81-
if n > width {
82-
if currChr == ' ' {
83-
wrappedLines = append(wrappedLines, line[offset:i])
84-
offset = i + 1
85-
n = 0
86-
} else if currChr == '-' {
87-
wrappedLines = append(wrappedLines, line[offset:i])
88-
offset = i
89-
n = rw
90-
} else if lastWhitespaceIndex != -1 && lastWhitespaceIndex+1 != i {
91-
if line[lastWhitespaceIndex] == '-' {
92-
wrappedLines = append(wrappedLines, line[offset:lastWhitespaceIndex+1])
93-
offset = lastWhitespaceIndex + 1
94-
n = i - lastWhitespaceIndex
95-
} else {
96-
wrappedLines = append(wrappedLines, line[offset:lastWhitespaceIndex])
97-
offset = lastWhitespaceIndex + 1
98-
n = i - lastWhitespaceIndex + 1
99-
}
100-
} else {
101-
wrappedLines = append(wrappedLines, line[offset:i])
102-
offset = i
103-
n = rw
104-
}
105-
lastWhitespaceIndex = -1
106-
} else if currChr == ' ' || currChr == '-' {
107-
lastWhitespaceIndex = i
108-
}
109-
}
110-
111-
wrappedLines = append(wrappedLines, line[offset:])
112-
}
113-
114-
return wrappedLines
60+
wrappedLines, _, _ := utils.WrapViewLinesToWidth(wrap, message, width)
61+
return len(wrappedLines)
11562
}
11663

11764
func (self *ConfirmationHelper) getPopupPanelDimensionsForContentHeight(panelWidth, contentHeight int, parentPopupContext types.Context) (int, int, int, int) {
@@ -329,7 +276,7 @@ func (self *ConfirmationHelper) layoutMenuPrompt(contentWidth int) int {
329276
var promptLines []string
330277
prompt := self.c.Contexts().Menu.GetPrompt()
331278
if len(prompt) > 0 {
332-
promptLines = wrapMessageToWidth(true, prompt, contentWidth)
279+
promptLines, _, _ = utils.WrapViewLinesToWidth(true, prompt, contentWidth)
333280
promptLines = append(promptLines, "")
334281
}
335282
self.c.Contexts().Menu.SetPromptLines(promptLines)

pkg/gui/controllers/helpers/patch_building_helper.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ func (self *PatchBuildingHelper) RefreshPatchBuildingPanel(opts types.OnFocusOpt
9191

9292
oldState := context.GetState()
9393

94-
state := patch_exploring.NewState(diff, selectedLineIdx, oldState, self.c.Log)
94+
state := patch_exploring.NewState(diff, selectedLineIdx, context.GetView(), oldState)
9595
context.SetState(state)
9696
if state == nil {
9797
self.Escape()

pkg/gui/controllers/helpers/staging_helper.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,11 @@ func (self *StagingHelper) RefreshStagingPanel(focusOpts types.OnFocusOpts) {
6363
secondaryContext.GetMutex().Lock()
6464

6565
mainContext.SetState(
66-
patch_exploring.NewState(mainDiff, mainSelectedLineIdx, mainContext.GetState(), self.c.Log),
66+
patch_exploring.NewState(mainDiff, mainSelectedLineIdx, mainContext.GetView(), mainContext.GetState()),
6767
)
6868

6969
secondaryContext.SetState(
70-
patch_exploring.NewState(secondaryDiff, secondarySelectedLineIdx, secondaryContext.GetState(), self.c.Log),
70+
patch_exploring.NewState(secondaryDiff, secondarySelectedLineIdx, secondaryContext.GetView(), secondaryContext.GetState()),
7171
)
7272

7373
mainState := mainContext.GetState()

pkg/gui/controllers/patch_building_controller.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,16 @@ func (self *PatchBuildingController) GetMouseKeybindings(opts types.KeybindingsO
6565
func (self *PatchBuildingController) GetOnFocus() func(types.OnFocusOpts) {
6666
return func(opts types.OnFocusOpts) {
6767
// no need to change wrap on the secondary view because it can't be interacted with
68-
self.c.Views().PatchBuilding.Wrap = false
68+
self.c.Views().PatchBuilding.Wrap = self.c.UserConfig().Gui.WrapLinesInStagingView
6969

7070
self.c.Helpers().PatchBuilding.RefreshPatchBuildingPanel(opts)
7171
}
7272
}
7373

7474
func (self *PatchBuildingController) GetOnFocusLost() func(types.OnFocusLostOpts) {
7575
return func(opts types.OnFocusLostOpts) {
76+
self.context().SetState(nil)
77+
7678
self.c.Views().PatchBuilding.Wrap = true
7779

7880
if self.c.Git().Patch.PatchBuilder.IsEmpty() {
@@ -134,13 +136,13 @@ func (self *PatchBuildingController) toggleSelection() error {
134136
if err != nil {
135137
return err
136138
}
137-
currentLineIsStaged := lo.Contains(includedLineIndices, state.GetSelectedLineIdx())
139+
currentLineIsStaged := lo.Contains(includedLineIndices, state.GetSelectedPatchLineIdx())
138140
if currentLineIsStaged {
139141
toggleFunc = self.c.Git().Patch.PatchBuilder.RemoveFileLineRange
140142
}
141143

142144
// add range of lines to those set for the file
143-
firstLineIdx, lastLineIdx := state.SelectedRange()
145+
firstLineIdx, lastLineIdx := state.SelectedPatchRange()
144146

145147
if err := toggleFunc(filename, firstLineIdx, lastLineIdx); err != nil {
146148
// might actually want to return an error here

0 commit comments

Comments
 (0)