Skip to content

Commit

Permalink
Merge pull request #1451 from fox0430/fix#1450
Browse files Browse the repository at this point in the history
Fix #1450
  • Loading branch information
fox0430 authored Nov 4, 2021
2 parents e7b52d8 + 51b301d commit f043256
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/moepkg/editor.nim
Original file line number Diff line number Diff line change
Expand Up @@ -320,10 +320,13 @@ proc insertIndentInNimForKeyEnter(bufStatus: var BufferStatus,
# Auto indent if the current line are "var", "let", "const".
# And, if finish the current line with ':', "object"
if currentColumn == line.len and (
line.splitWhitespace == @[ru "var"] or
line.splitWhitespace == @[ru "let"] or
line.splitWhitespace == @[ru "const"] or
line.splitWhitespace[^1] == (ru "object") or
(line.len > 2 and
line.splitWhitespace == @[ru "var"] or
line.splitWhitespace == @[ru "let"]) or
(line.len > 4 and
line.splitWhitespace == @[ru "const"]) or
(line.len > 4 and
line.splitWhitespace[^1] == (ru "object")) or
line[^1] == (ru ':') or
line[^1] == (ru '=')
):
Expand Down
16 changes: 16 additions & 0 deletions tests/teditor.nim
Original file line number Diff line number Diff line change
Expand Up @@ -925,6 +925,22 @@ suite "Editor: keyEnter and autoindent in Python":
check currentBufStatus.buffer[0] == ru"if true or"
check currentBufStatus.buffer[1] == ru" "

test "Insert a new line in Nim (Fix #1450)":
var status = initEditorStatus()
status.addNewBuffer

status.bufStatus[0].buffer = initGapBuffer(@[ru"block:", ru" const a = 0"])
currentBufStatus.language = SourceLanguage.langNim
status.bufStatus[0].mode = Mode.insert
currentMainWindowNode.currentLine = 1
currentMainWindowNode.currentColumn = currentBufStatus.buffer[1].len

const isAutoIndent = true
for i in 0 ..< 2:
currentBufStatus.keyEnter(currentMainWindowNode,
isAutoIndent,
status.settings.tabStop)

suite "Delete character before cursor":
test "Delete one character":
var status = initEditorStatus()
Expand Down

0 comments on commit f043256

Please sign in to comment.