Skip to content

Commit a370de3

Browse files
committed
Add search term unhighlighting
Preserve the active search while suppressing match highlights until the next search navigation. Resolved #1164
1 parent cb48ea7 commit a370de3

6 files changed

Lines changed: 16 additions & 0 deletions

File tree

oviewer/action.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,11 @@ func (root *Root) toggleStatusLine(context.Context) {
154154
}
155155
}
156156

157+
// unHighlight disables highlighting until the next search.
158+
func (root *Root) unHighlight(context.Context) {
159+
root.undoHighlight = true
160+
}
161+
157162
// toggleRuler cycles through the ruler types (None, Relative, Absolute) each time it is called.
158163
func (root *Root) toggleRuler(ctx context.Context) {
159164
switch root.Doc.RulerType {

oviewer/keybind.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ const (
9696
actionAlignFormat = "align_format"
9797
actionRawFormat = "raw_format"
9898
actionRuler = "toggle_ruler"
99+
actionUnHighlight = "un_highlight"
99100
actionStatusLine = "status_line"
100101

101102
// Change Display with Input
@@ -227,6 +228,7 @@ func (root *Root) handlers() map[string]func(context.Context) {
227228
actionAlignFormat: root.alignFormat,
228229
actionRawFormat: root.rawFormat,
229230
actionRuler: root.toggleRuler,
231+
actionUnHighlight: root.unHighlight,
230232
actionStatusLine: root.toggleStatusLine,
231233

232234
// Change Display with Input
@@ -431,6 +433,7 @@ var keyBindDescriptions = []KeyBindDescription{
431433
{Group: GroupChange, Action: actionAlignFormat, Description: "align columns"},
432434
{Group: GroupChange, Action: actionRawFormat, Description: "toggle raw output mode"},
433435
{Group: GroupChange, Action: actionRuler, Description: "ruler toggle"},
436+
{Group: GroupChange, Action: actionUnHighlight, Description: "unhighlight search results until the next search"},
434437
{Group: GroupChange, Action: actionStatusLine, Description: "status line toggle"},
435438
{Group: GroupChange, Action: actionStyleToggle, Description: "suppress style highlight by number"},
436439

oviewer/keydefine.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ func DefaultKeyBinds() KeyBind {
4747
actionRightAlign: {"alt+a"},
4848
actionRuler: {"alt+shift+F9"},
4949
actionWriteOriginal: {"alt+shift+F8"},
50+
actionUnHighlight: {"ctrl+alt+u"},
5051
actionStatusLine: {"ctrl+F10"},
5152

5253
// Move actions.

oviewer/oviewer.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ type Root struct {
7373

7474
// searchOpt is the search option.
7575
searchOpt string
76+
// undoHighlight indicates whether highlighting should be undone until the next search.
77+
undoHighlight bool
7678

7779
// message is the message to display.
7880
message string

oviewer/prepare_draw.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,9 @@ func (root *Root) multiColorHighlight(lineC LineC) {
550550
// searchHighlight applies the style of the search highlight.
551551
// Apply style to contents.
552552
func (root *Root) searchHighlight(lineC LineC) {
553+
if root.undoHighlight {
554+
return
555+
}
553556
if root.searcher == nil || root.searcher.String() == "" {
554557
return
555558
}

oviewer/search.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -679,12 +679,14 @@ func (root *Root) sendFirstSearch(value string, t searchType) {
679679

680680
// forwardSearch performs the forward search.
681681
func (root *Root) forwardSearch(ctx context.Context, str string, next int) {
682+
root.undoHighlight = false
682683
searcher := root.setSearcher(str, root.Config.CaseSensitive)
683684
root.searchMove(ctx, true, root.startSearchLN()+next, searcher)
684685
}
685686

686687
// backSearch performs the back search.
687688
func (root *Root) backSearch(ctx context.Context, str string, next int) {
689+
root.undoHighlight = false
688690
searcher := root.setSearcher(str, root.Config.CaseSensitive)
689691
root.searchMove(ctx, false, root.startSearchLN()+next, searcher)
690692
}

0 commit comments

Comments
 (0)