diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2024-01-14 00:18:05 +1100 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2024-01-19 10:47:21 +1100 |
commit | f3eb180f75496637719895902abf76af10b8425f (patch) | |
tree | 2734dec7d15d35e8c4ff1b65aa3d722cdbd69ac5 /pkg/commands/patch | |
parent | c0c3aac02e048903764e4b42b513334e58855d73 (diff) |
Standardise display of range selection across views
We're not fully standardising here: different contexts can store their range state however
they like. What we are standardising on is that now the view is always responsible for
highlighting the selected lines, meaning the context/controller needs to tell the view
where the range start is.
Two convenient benefits from this change:
1) we no longer need bespoke code in integration tests for asserting on selected lines because
we can just ask the view
2) line selection in staging/patch-building/merge-conflicts views now look the same as in
list views i.e. the highlight applies to the whole line (including trailing space)
I also noticed a bug with merge conflicts not rendering the selection on focus though I suspect
it wasn't a bug with any real consequences when the view wasn't displaying the selection.
I'm going to scrap the selectedRangeBgColor config and just let it use the single line
background color. Hopefully nobody cares, but there's really no need for an extra config.
Diffstat (limited to 'pkg/commands/patch')
-rw-r--r-- | pkg/commands/patch/format.go | 24 | ||||
-rw-r--r-- | pkg/commands/patch/patch_builder.go | 4 |
2 files changed, 3 insertions, 25 deletions
diff --git a/pkg/commands/patch/format.go b/pkg/commands/patch/format.go index d04b6bec1..c61c8ef05 100644 --- a/pkg/commands/patch/format.go +++ b/pkg/commands/patch/format.go @@ -14,11 +14,6 @@ type patchPresenter struct { // if true, all following fields are ignored plain bool - isFocused bool - // first line index for selected cursor range - firstLineIndex int - // last line index for selected cursor range - lastLineIndex int // line indices for tagged lines (e.g. lines added to a custom patch) incLineIndices *set.Set[int] } @@ -44,11 +39,6 @@ func formatRangePlain(patch *Patch, startIdx int, endIdx int) string { } type FormatViewOpts struct { - IsFocused bool - // first line index for selected cursor range - FirstLineIndex int - // last line index for selected cursor range - LastLineIndex int // line indices for tagged lines (e.g. lines added to a custom patch) IncLineIndices *set.Set[int] } @@ -63,9 +53,6 @@ func formatView(patch *Patch, opts FormatViewOpts) string { presenter := &patchPresenter{ patch: patch, plain: false, - isFocused: opts.IsFocused, - firstLineIndex: opts.FirstLineIndex, - lastLineIndex: opts.LastLineIndex, incLineIndices: includedLineIndices, } return presenter.format() @@ -112,7 +99,6 @@ func (self *patchPresenter) format() string { self.formatLineAux( hunk.headerContext, theme.DefaultTextColor, - lineIdx, false, ), ) @@ -139,23 +125,17 @@ func (self *patchPresenter) patchLineStyle(patchLine *PatchLine) style.TextStyle func (self *patchPresenter) formatLine(str string, textStyle style.TextStyle, index int) string { included := self.incLineIndices.Includes(index) - return self.formatLineAux(str, textStyle, index, included) + return self.formatLineAux(str, textStyle, included) } // 'selected' means you've got it highlighted with your cursor // 'included' means the line has been included in the patch (only applicable when // building a patch) -func (self *patchPresenter) formatLineAux(str string, textStyle style.TextStyle, index int, included bool) string { +func (self *patchPresenter) formatLineAux(str string, textStyle style.TextStyle, included bool) string { if self.plain { return str } - selected := self.isFocused && index >= self.firstLineIndex && index <= self.lastLineIndex - - if selected { - textStyle = textStyle.MergeStyle(theme.SelectedRangeBgColor) - } - firstCharStyle := textStyle if included { firstCharStyle = firstCharStyle.MergeStyle(style.BgGreen) diff --git a/pkg/commands/patch/patch_builder.go b/pkg/commands/patch/patch_builder.go index 2f350a40b..88f1becc5 100644 --- a/pkg/commands/patch/patch_builder.go +++ b/pkg/commands/patch/patch_builder.go @@ -197,9 +197,7 @@ func (p *PatchBuilder) RenderPatchForFile(filename string, plain bool, reverse b if plain { return patch.FormatPlain() } else { - return patch.FormatView(FormatViewOpts{ - IsFocused: false, - }) + return patch.FormatView(FormatViewOpts{}) } } |