diff --git a/changelog.d/20250217_230643_github-actions[bot]_search-highlight-in-logviewer.rst b/changelog.d/20250217_230643_github-actions[bot]_search-highlight-in-logviewer.rst new file mode 100644 index 000000000..b9be0f631 --- /dev/null +++ b/changelog.d/20250217_230643_github-actions[bot]_search-highlight-in-logviewer.rst @@ -0,0 +1,7 @@ +.. _#2250: https://github.com/fox0430/moe/pull/2250 + +Added +..... + +- `#2250`_ Enable search highlighting in log viewer + diff --git a/src/moepkg/editorstatus.nim b/src/moepkg/editorstatus.nim index f027b9fbb..1094e2cbb 100644 --- a/src/moepkg/editorstatus.nim +++ b/src/moepkg/editorstatus.nim @@ -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 diff --git a/src/moepkg/viewhighlight.nim b/src/moepkg/viewhighlight.nim index 05eb2b0a1..20589aaec 100644 --- a/src/moepkg/viewhighlight.nim +++ b/src/moepkg/viewhighlight.nim @@ -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 # @@ -300,7 +300,7 @@ proc highlightFullWidthSpace( ) highlight.overwrite(colorSegment) -proc highlightText( +proc highlightText*( highlight: var Highlight, bufferInView: BufferInView, highlightingText: HighlightingText, @@ -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) diff --git a/tests/tviewhighlight.nim b/tests/tviewhighlight.nim index b3272235b..6d676d65d 100644 --- a/tests/tviewhighlight.nim +++ b/tests/tviewhighlight.nim @@ -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 # @@ -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 @@ -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, + ), + ]