Skip to content

Commit 7c2063c

Browse files
authored
Allow changing diff context size and rename threshold when main view is focused (#4505)
- **PR Description** Allow pressing `{`, `}`, `(`, and `)` to change the diff context size and rename threshold when the main view is focused. This was forgotten in #4429.
2 parents aa68885 + da24deb commit 7c2063c

File tree

4 files changed

+51
-4
lines changed

4 files changed

+51
-4
lines changed

pkg/gui/controllers/context_lines_controller.go

+14-2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ var CONTEXT_KEYS_SHOWING_DIFFS = []types.ContextKey{
2222
context.STAGING_SECONDARY_CONTEXT_KEY,
2323
context.PATCH_BUILDING_MAIN_CONTEXT_KEY,
2424
context.PATCH_BUILDING_SECONDARY_CONTEXT_KEY,
25+
context.NORMAL_MAIN_CONTEXT_KEY,
26+
context.NORMAL_SECONDARY_CONTEXT_KEY,
2527
}
2628

2729
type ContextLinesController struct {
@@ -97,7 +99,7 @@ func (self *ContextLinesController) applyChange() error {
9799
self.c.Toast(fmt.Sprintf(self.c.Tr.DiffContextSizeChanged, self.c.AppState.DiffContextSize))
98100
self.c.SaveAppStateAndLogError()
99101

100-
currentContext := self.c.Context().CurrentStatic()
102+
currentContext := self.currentSidePanel()
101103
switch currentContext.GetKey() {
102104
// we make an exception for our staging and patch building contexts because they actually need to refresh their state afterwards.
103105
case context.PATCH_BUILDING_MAIN_CONTEXT_KEY:
@@ -121,6 +123,16 @@ func (self *ContextLinesController) checkCanChangeContext() error {
121123
func (self *ContextLinesController) isShowingDiff() bool {
122124
return lo.Contains(
123125
CONTEXT_KEYS_SHOWING_DIFFS,
124-
self.c.Context().CurrentStatic().GetKey(),
126+
self.currentSidePanel().GetKey(),
125127
)
126128
}
129+
130+
func (self *ContextLinesController) currentSidePanel() types.Context {
131+
currentContext := self.c.Context().CurrentStatic()
132+
if currentContext.GetKey() == context.NORMAL_MAIN_CONTEXT_KEY ||
133+
currentContext.GetKey() == context.NORMAL_SECONDARY_CONTEXT_KEY {
134+
return currentContext.GetParentContext()
135+
}
136+
137+
return currentContext
138+
}

pkg/gui/controllers/rename_similarity_threshold_controller.go

+14-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ var CONTEXT_KEYS_SHOWING_RENAMES = []types.ContextKey{
1515
context.SUB_COMMITS_CONTEXT_KEY,
1616
context.LOCAL_COMMITS_CONTEXT_KEY,
1717
context.STASH_CONTEXT_KEY,
18+
context.NORMAL_MAIN_CONTEXT_KEY,
19+
context.NORMAL_SECONDARY_CONTEXT_KEY,
1820
}
1921

2022
type RenameSimilarityThresholdController struct {
@@ -82,7 +84,7 @@ func (self *RenameSimilarityThresholdController) applyChange() error {
8284
self.c.Toast(fmt.Sprintf(self.c.Tr.RenameSimilarityThresholdChanged, self.c.AppState.RenameSimilarityThreshold))
8385
self.c.SaveAppStateAndLogError()
8486

85-
currentContext := self.c.Context().CurrentStatic()
87+
currentContext := self.currentSidePanel()
8688
switch currentContext.GetKey() {
8789
// we make an exception for our files context, because it actually need to refresh its state afterwards.
8890
case context.FILES_CONTEXT_KEY:
@@ -96,6 +98,16 @@ func (self *RenameSimilarityThresholdController) applyChange() error {
9698
func (self *RenameSimilarityThresholdController) isShowingRenames() bool {
9799
return lo.Contains(
98100
CONTEXT_KEYS_SHOWING_RENAMES,
99-
self.c.Context().CurrentStatic().GetKey(),
101+
self.currentSidePanel().GetKey(),
100102
)
101103
}
104+
105+
func (self *RenameSimilarityThresholdController) currentSidePanel() types.Context {
106+
currentContext := self.c.Context().CurrentStatic()
107+
if currentContext.GetKey() == context.NORMAL_MAIN_CONTEXT_KEY ||
108+
currentContext.GetKey() == context.NORMAL_SECONDARY_CONTEXT_KEY {
109+
return currentContext.GetParentContext()
110+
}
111+
112+
return currentContext
113+
}

pkg/integration/tests/diff/rename_similarity_threshold_change.go

+12
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,17 @@ var RenameSimilarityThresholdChange = NewIntegrationTest(NewIntegrationTestArgs{
3737
Contains("original => renamed"),
3838
Contains("1 file changed, 5 insertions(+)"),
3939
)
40+
41+
t.Views().Commits().
42+
Press(keys.Universal.FocusMainView)
43+
44+
t.Views().Main().
45+
Press(keys.Universal.IncreaseRenameSimilarityThreshold).
46+
Tap(func() {
47+
t.ExpectToast(Equals("Changed rename similarity threshold to 50%"))
48+
}).
49+
ContainsLines(
50+
Contains("2 files changed, 10 insertions(+), 5 deletions(-)"),
51+
)
4052
},
4153
})

pkg/integration/tests/file/rename_similarity_threshold_change.go

+11
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,17 @@ var RenameSimilarityThresholdChange = NewIntegrationTest(NewIntegrationTestArgs{
3131
}).
3232
Lines(
3333
Equals("R original → renamed"),
34+
).
35+
Press(keys.Universal.FocusMainView).
36+
Tap(func() {
37+
t.Views().Main().
38+
Press(keys.Universal.IncreaseRenameSimilarityThreshold)
39+
t.ExpectToast(Equals("Changed rename similarity threshold to 50%"))
40+
}).
41+
Lines(
42+
Equals("▼ /"),
43+
Equals(" D original"),
44+
Equals(" A renamed"),
3445
)
3546
},
3647
})

0 commit comments

Comments
 (0)