From af9b37a18361e9303c78666c75b6f1012ad244c6 Mon Sep 17 00:00:00 2001 From: fox0430 Date: Thu, 16 Dec 2021 19:03:21 +0900 Subject: [PATCH 1/2] Fix #1455 --- src/moepkg/editorstatus.nim | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/src/moepkg/editorstatus.nim b/src/moepkg/editorstatus.nim index 2561c634d..cbc7def11 100644 --- a/src/moepkg/editorstatus.nim +++ b/src/moepkg/editorstatus.nim @@ -438,10 +438,20 @@ proc initSyntaxHighlight(windowNode: var WindowNode, proc isLogViewerMode(mode, prevMode: Mode): bool {.inline.} = (mode == logViewer) or (mode == ex and prevMode == logViewer) -proc updateLogViewer(status: var Editorstatus, bufferIndex: int) = - status.bufStatus[bufferIndex].buffer = initGapBuffer(@[ru""]) - for i in 0 ..< status.messageLog.len: - status.bufStatus[bufferIndex].buffer.insert(status.messageLog[i], i) +proc updateLogViewer(bufStatus: var BufferStatus, + node: var WindowNode, + messageLog: seq[seq[Rune]]) = + + bufStatus.buffer = initGapBuffer(@[ru""]) + for i in 0 ..< messageLog.len: + bufStatus.buffer.insert(messageLog[i], i) + + const EMPTY_RESERVEDWORD: seq[ReservedWord] = @[] + + node.highlight = initHighlight( + $bufStatus.buffer, + EMPTY_RESERVEDWORD, + SourceLanguage.langNone) proc updateDebugModeBuffer(status: var EditorStatus) @@ -508,14 +518,14 @@ proc update*(status: var EditorStatus) = not isConfigMode(currentMode, prevMode): if isLogViewerMode(currentMode, prevMode): - status.updateLogViewer(node.bufferIndex) - - highlight.updateHighlight( - bufStatus, - node, - status.isSearchHighlight, - status.searchHistory, - settings) + status.bufStatus[node.bufferIndex].updateLogViewer(node, status.messageLog) + else: + highlight.updateHighlight( + bufStatus, + node, + status.isSearchHighlight, + status.searchHistory, + settings) let startSelectedLine = bufStatus.selectArea.startLine From e7b5bba62038e6221cbb286efb1b99f1f9a99d85 Mon Sep 17 00:00:00 2001 From: fox0430 Date: Thu, 16 Dec 2021 19:05:51 +0900 Subject: [PATCH 2/2] Add and fix tests for Logvviewer --- tests/tlogviewer.nim | 44 ++++++++++++++++++++++++++++++++++++-------- 1 file changed, 36 insertions(+), 8 deletions(-) diff --git a/tests/tlogviewer.nim b/tests/tlogviewer.nim index 573c19377..df1288c0d 100644 --- a/tests/tlogviewer.nim +++ b/tests/tlogviewer.nim @@ -1,13 +1,41 @@ import unittest -import moepkg/[editorstatus, logviewer, bufferstatus] +import moepkg/[editorstatus, logviewer, bufferstatus, unicodeext] -test "Exit log viewer": - var status = initEditorStatus() - status.addNewBuffer("Log viewer", Mode.logViewer) +suite "Log viewer": + test "Open the log viewer (Fix #1455)": + var status = initEditorStatus() + status.addNewBuffer - status.resize(100, 100) - status.update + status.resize(100, 100) + status.update - status.exitLogViewer(100, 100) + status.messageLog = @[ru "test"] - status.resize(100, 100) + status.verticalSplitWindow + status.resize(100, 100) + status.moveNextWindow + + status.addNewBuffer + status.changeCurrentBuffer(status.bufStatus.high) + status.changeMode(bufferstatus.Mode.logviewer) + + # In the log viewer + currentBufStatus.path = ru"Log viewer" + + status.resize(100, 100) + status.update + + let currentBufferIndex = status.bufferIndexInCurrentWindow + + status.update + + test "Exit viewer": + var status = initEditorStatus() + status.addNewBuffer("Log viewer", Mode.logViewer) + + status.resize(100, 100) + status.update + + status.exitLogViewer(100, 100) + + status.resize(100, 100)