Skip to content

Commit

Permalink
Merge pull request #280 from fox0430/fix#272
Browse files Browse the repository at this point in the history
Fix #272
  • Loading branch information
fox0430 authored May 9, 2019
2 parents 918f05d + 09bbc98 commit 055cb26
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/moepkg/editorview.nim
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ proc writeAllLines*[T](view: var EditorView, win: var Window, lineNumber, curren

while i < highlight.len and highlight[i].firstRow < view.originalLine[y]: inc(i)
while i < highlight.len and highlight[i].firstRow == view.originalLine[y]:
if (highlight[i].firstRow, highlight[i].firstColumn) > (highlight[i].lastRow, highlight[i].lastColumn) : break # skip an empty segment
let
first = max(highlight[i].firstColumn-view.start[y], 0)
last = min(highlight[i].lastColumn-view.start[y], view.lines[y].high)
Expand Down
2 changes: 1 addition & 1 deletion src/moepkg/highlight.nim
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ proc initHighlight*(buffer: string, language: SourceLanguage, defaultColor: Colo
empty = true
for r in runes(str):
if r == newline:
if empty: result.colorSegments.add(ColorSegment(firstRow: currentRow, firstColumn: 0, lastRow: currentRow, lastColumn: -1, color: defaultColor))
if empty: result.colorSegments.add(ColorSegment(firstRow: currentRow, firstColumn: currentColumn, lastRow: currentRow, lastColumn: currentColumn-1, color: defaultColor)) # push an empty segment
else: result.colorSegments.add(cs)
inc(currentRow)
currentColumn = 0
Expand Down
31 changes: 31 additions & 0 deletions tests/thighlight.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import unittest, packages/docutils/highlite, strutils
import moepkg/highlight, moepkg/ui

test "initHighlight: start with newline":
let
code = "\x0Aproc test =\x0A echo \"Hello, world!\""
buffer = split(code, '\n')
highlight = initHighlight(code, SourceLanguage.langNim, ColorPair.brightWhiteDefault)

# unite segments
var unitedStr: string
for i in 0 ..< highlight.len:
let segment = highlight[i]
if i > 0 and segment.firstRow != highlight[i-1].lastRow: unitedStr &= "\n"
unitedStr &= buffer[segment.firstRow][segment.firstColumn .. segment.lastColumn]

check(unitedStr == code)

test "index: basic":
let
code = "proc test =\x0A echo \"Hello, world!\""
highlight = initHighlight(code, SourceLanguage.langNim, ColorPair.brightWhiteDefault)

check(highlight.index(0, 0) == 0)

test "index: start with newline":
let
code = "\x0Aproc test =\x0A echo \"Hello, world!\""
highlight = initHighlight(code, SourceLanguage.langNim, ColorPair.brightWhiteDefault)

check(highlight.index(0, 0) == 0)

0 comments on commit 055cb26

Please sign in to comment.