Skip to content

Commit

Permalink
Merge pull request #1433 from fox0430/fix-o-cmd
Browse files Browse the repository at this point in the history
Normal mode: Add '=' case to autoindent to 'o' command
  • Loading branch information
fox0430 authored Aug 20, 2021
2 parents 9099f20 + b974277 commit b4dc7ab
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
15 changes: 8 additions & 7 deletions src/moepkg/editor.nim
Original file line number Diff line number Diff line change
Expand Up @@ -902,12 +902,13 @@ proc insertIndentNimForOpenBlankLine(bufStatus: var BufferStatus,

if aboveLine.len > 0:
# Auto indent if the current line are "var", "let", "const".
# And, if finish the current line with ':', "object"
# And, if finish the current line with ':', "object, '='"
if (aboveLine.splitWhitespace == @[ru "var"] or
aboveLine.splitWhitespace == @[ru "let"] or
aboveLine.splitWhitespace == @[ru "const"] or
(aboveLine.len > 6 and aboveLine[aboveLine.len - 6 .. ^1] == ru "object") or
aboveLine[^1] == ru ':'):
aboveLine.splitWhitespace[^1] == (ru "object") or
aboveLine[^1] == (ru ':') or
aboveLine[^1] == (ru '=')):
let
count = countRepeat(aboveLine, Whitespace, 0) + tabStop
oldLine = bufStatus.buffer[currentLineNum]
Expand All @@ -918,8 +919,8 @@ proc insertIndentNimForOpenBlankLine(bufStatus: var BufferStatus,
bufStatus.buffer[currentLineNum] = newLine

# Auto indent if finish the current line with "or", "and"
elif ((aboveLine.len > 2 and aboveLine[aboveLine.len - 2 .. ^1] == ru "or") or
(aboveLine.len > 3 and aboveLine[aboveLine.len - 3 .. ^1] == ru "and")):
elif ((aboveLine.len > 2 and (aboveLine.splitWhitespace)[^1] == ru "or") or
(aboveLine.len > 3 and (aboveLine.splitWhitespace)[^1] == ru "and")):
let
count = countRepeat(aboveLine, Whitespace, 0) + tabStop
oldLine = bufStatus.buffer[currentLineNum]
Expand Down Expand Up @@ -948,8 +949,8 @@ proc insertIndentInPythonForOpenBlankLine(bufStatus: var BufferStatus,

if aboveLine.len > 0:
# if finish the current line with ':', "or", "and" in Python
if (aboveLine.len > 2 and aboveLine[aboveLine.len - 2 .. ^1] == ru "or") or
(aboveLine.len > 3 and aboveLine[aboveLine.len - 3 .. ^1] == ru "and") or
if (aboveLine.len > 2 and (aboveLine.splitWhitespace)[^1] == ru "or") or
(aboveLine.len > 3 and (aboveLine.splitWhitespace)[^1] == ru "and") or
(aboveLine[^1] == ru ':'):
let
count = countRepeat(aboveLine, Whitespace, 0) + tabStop
Expand Down
12 changes: 8 additions & 4 deletions tests/teditor.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1649,7 +1649,7 @@ suite "Editor: Open the blank line below":
# Generate test code
# Enable autoindent
# open the blank line below in Nim
# When the current line ends with "or", "and", ':', "object".
# When the current line ends with "or", "and", ':', "object", '='.
macro openLineBelowTestCase3(keyword: string): untyped =
quote do:
# Generate test title
Expand Down Expand Up @@ -1691,6 +1691,9 @@ suite "Editor: Open the blank line below":
block:
const keyword = "object"
openLineBelowTestCase3(keyword)
block:
const keyword = "="
openLineBelowTestCase3(keyword)

# Generate test code
# Enable/Disable autoindent
Expand Down Expand Up @@ -1932,7 +1935,7 @@ suite "Editor: Open the blank line abave":
# Generate test code
# Enable autoindent
# open the blank line above in Nim
# When the current line ends with "or", "and", ':', "object".
# When the current line ends with "or", "and", ':', "object", "=".
macro openLineAboveTestCase4(keyword: string): untyped =
quote do:
# Generate test title
Expand Down Expand Up @@ -1980,6 +1983,9 @@ suite "Editor: Open the blank line abave":
block:
const keyword = "object"
openLineAboveTestCase4(keyword)
block:
const keyword = "="
openLineAboveTestCase4(keyword)

# Generate test code
# Enable autoindent
Expand Down Expand Up @@ -2027,5 +2033,3 @@ suite "Editor: Open the blank line abave":
block:
const keyword = ":"
openLineAboveTestCase5(keyword)


0 comments on commit b4dc7ab

Please sign in to comment.