Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Normal mode: Add '=' case to autoindent to 'o' command #1433

Merged
merged 2 commits into from
Aug 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)