Skip to content

Commit

Permalink
Enable search highlighting in log viewer (#2250)
Browse files Browse the repository at this point in the history
  • Loading branch information
fox0430 authored Feb 17, 2025
1 parent a0b4888 commit 21d1ad7
Show file tree
Hide file tree
Showing 4 changed files with 151 additions and 32 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.. _#2250: https://github.com/fox0430/moe/pull/2250

Added
.....

- `#2250`_ Enable search highlighting in log viewer

15 changes: 7 additions & 8 deletions src/moepkg/editorstatus.nim
Original file line number Diff line number Diff line change
Expand Up @@ -997,14 +997,13 @@ proc update*(status: var EditorStatus) =
var highlight = Highlight()
highlight.colorSegments = b.highlight.colorSegments

if b.isEditMode:
highlight.updateViewHighlight(
b,
node,
status.highlightingText,
settings,
status.lspClients.getLspCapabilities(b.langId),
)
highlight.updateViewHighlight(
b,
node,
status.highlightingText,
settings,
status.lspClients.getLspCapabilities(b.langId),
)

if node.view.sidebar.isSome:
# Update the EditorView.Sidebar.buffer
Expand Down
46 changes: 24 additions & 22 deletions src/moepkg/viewhighlight.nim
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#[###################### GNU General Public License 3.0 ######################]#
# #
# Copyright (C) 2017─2024 Shuhei Nogawa #
# Copyright (C) 2017─2025 Shuhei Nogawa #
# #
# This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by #
Expand Down Expand Up @@ -300,7 +300,7 @@ proc highlightFullWidthSpace(
)
highlight.overwrite(colorSegment)

proc highlightText(
proc highlightText*(
highlight: var Highlight,
bufferInView: BufferInView,
highlightingText: HighlightingText,
Expand Down Expand Up @@ -399,30 +399,32 @@ proc updateViewHighlight*(
) =
let bufferInView = initBufferInView(bufStatus, windowNode)

# LSP or build-in
if lspCapabilities.isSome and lspCapabilities.get.documentHighlight:
h.highlightDocumentHighlights(
windowNode.bufferPosition, bufStatus.documentHighlightInfo.ranges
)
elif settings.highlight.currentWord:
h.highlightReferences(bufferInView, settings.standard.colorMode)
if bufStatus.isEditMode:
# LSP or build-in
if lspCapabilities.isSome and lspCapabilities.get.documentHighlight:
h.highlightDocumentHighlights(
windowNode.bufferPosition, bufStatus.documentHighlightInfo.ranges
)
elif settings.highlight.currentWord:
h.highlightReferences(bufferInView, settings.standard.colorMode)

if bufStatus.selectedArea.isSome:
h.highlightSelectedArea(bufStatus, windowNode.initBufferPosition)
if bufStatus.selectedArea.isSome:
h.highlightSelectedArea(bufStatus, windowNode.initBufferPosition)

if settings.highlight.pairOfParen:
h.highlightPairOfParen(bufferInView)
if settings.highlight.pairOfParen:
h.highlightPairOfParen(bufferInView)

if settings.highlight.trailingSpaces and bufStatus.isEditMode:
h.highlightTrailingSpaces(bufferInView)
if settings.highlight.trailingSpaces and bufStatus.isEditMode:
h.highlightTrailingSpaces(bufferInView)

if settings.highlight.fullWidthSpace:
h.highlightFullWidthSpace(windowNode, bufferInView)
if settings.highlight.fullWidthSpace:
h.highlightFullWidthSpace(windowNode, bufferInView)

if highlightingText.isSome:
h.highlightText(bufferInView, highlightingText.get)
if bufStatus.syntaxCheckResults.len > 0:
h.highlightSyntaxCheckerReuslts(bufferInView, bufStatus.syntaxCheckResults)

if bufStatus.syntaxCheckResults.len > 0:
h.highlightSyntaxCheckerReuslts(bufferInView, bufStatus.syntaxCheckResults)
h.highlightGitConflicts(bufferInView)

h.highlightGitConflicts(bufferInView)
# highlightText apply all buffers
if highlightingText.isSome:
h.highlightText(bufferInView, highlightingText.get)
115 changes: 113 additions & 2 deletions tests/tviewhighlight.nim
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#[###################### GNU General Public License 3.0 ######################]#
# #
# Copyright (C) 2017─2023 Shuhei Nogawa #
# Copyright (C) 2017─2025 Shuhei Nogawa #
# #
# This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by #
Expand All @@ -26,7 +26,7 @@ import moepkg/syntax/highlite
import
moepkg/[
editorstatus, highlight, color, gapbuffer, unicodeext, movement, windownode, ui,
independentutils, bufferstatus,
independentutils, bufferstatus, messagelog,
]

import utils
Expand Down Expand Up @@ -1337,3 +1337,114 @@ suite "viewhighlight: highlightText":
h.highlightText(bufferInView, highlightText)

check h.colorSegments == beforeSegments

suite "viewhighlight: updateViewHighlight":
const ReservedWords: seq[ReservedWord] = @[]

test "Check highlightingText":
var status = initEditorStatus()
discard status.addNewBufferInCurrentWin.get
currentBufStatus.buffer = @["abcdef", "ghijkl"].toSeqRunes.toGapBuffer

status.resize(100, 100)
status.update

let highlightingText =
HighlightingText(kind: HighlightingTextKind.search, text: @["ghi"].toSeqRunes)

var h = Highlight(colorSegments: currentBufStatus.highlight.colorSegments)
h.updateViewHighlight(
currentBufStatus,
currentMainWindowNode,
some(highlightingText),
status.settings,
none(LspCapabilities),
)

check h.colorSegments ==
@[
ColorSegment(
firstRow: 0,
firstColumn: 0,
lastRow: 0,
lastColumn: 5,
color: EditorColorPairIndex.default,
attribute: Attribute.normal,
),
ColorSegment(
firstRow: 1,
firstColumn: 0,
lastRow: 1,
lastColumn: 2,
color: searchResult,
attribute: Attribute.normal,
),
ColorSegment(
firstRow: 1,
firstColumn: 3,
lastRow: 1,
lastColumn: 5,
color: EditorColorPairIndex.default,
attribute: Attribute.normal,
),
]

test "Check highlightingText in logviewer mode":
var status = initEditorStatus()
discard status.addNewBufferInCurrentWin.get
currentBufStatus.mode = Mode.logviewer

addMessageLog "abcdef"
addMessageLog "ghijkl"

status.resize(100, 100)
status.update

let highlightingText =
HighlightingText(kind: HighlightingTextKind.search, text: @["ghi"].toSeqRunes)

var h = Highlight()
h.colorSegments = currentBufStatus.highlight.colorSegments
h.updateViewHighlight(
currentBufStatus,
currentMainWindowNode,
some(highlightingText),
status.settings,
none(LspCapabilities),
)

check h.colorSegments ==
@[
ColorSegment(
firstRow: 0,
firstColumn: 0,
lastRow: 0,
lastColumn: 5,
color: EditorColorPairIndex.default,
attribute: Attribute.normal,
),
ColorSegment(
firstRow: 1,
firstColumn: 0,
lastRow: 1,
lastColumn: -1,
color: EditorColorPairIndex.default,
attribute: Attribute.normal,
),
ColorSegment(
firstRow: 2,
firstColumn: 0,
lastRow: 2,
lastColumn: 2,
color: EditorColorPairIndex.searchResult,
attribute: Attribute.normal,
),
ColorSegment(
firstRow: 2,
firstColumn: 3,
lastRow: 2,
lastColumn: 5,
color: EditorColorPairIndex.default,
attribute: Attribute.normal,
),
]

0 comments on commit 21d1ad7

Please sign in to comment.