Fix newline only lines

This commit is contained in:
Florian Schroedl
2022-06-18 12:18:57 +02:00
parent 1558349999
commit dd84dc5d6e

View File

@@ -405,7 +405,13 @@ func highlightStreamPosition2(stream: string, position: int): string =
debugEcho "insertMessageAtIndex: " & $insertMessageAtIndex
stream.dup(insert(&"\n{spaceChars}^{lineChars} Char at \"{escapedChar}\"\n", insertMessageAtIndex))
let beforeNewline =
case (startIndex, ch):
of (-1, '\n'): "\n"
of (_, '\n'): ""
else: "\n"
stream.dup(insert(&"{beforeNewline}{spaceChars}^{lineChars} Char at \"{escapedChar}\"\n", insertMessageAtIndex))
proc `$`*(x: ParserState): string =
&"""ParserState(
@@ -457,14 +463,14 @@ when isMainModule:
D
EFG"""
# echo test1.highlightStreamPosition2(test1.find("B"))
# echo "=============="
# echo test1.highlightStreamPosition2(test1.find("C"))
# echo "=============="
# echo test1.highlightStreamPosition2(test1.find("D"))
echo test1.highlightStreamPosition2(test1.find("B"))
echo "=============="
echo test1.highlightStreamPosition2(test1.find("C"))
echo "=============="
echo test1.highlightStreamPosition2(test1.find("D"))
echo "=============="
echo test1.highlightStreamPosition2(test1.find("\n"))
echo "=============="
echo test1.highlightStreamPosition2(test1.find("\n", test1.find("\n") + 1))