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

't' & 'T' commands, and a typo fix #1427

Merged
merged 4 commits into from
Aug 18, 2021
Merged
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
60 changes: 48 additions & 12 deletions src/moepkg/normalmode.nim
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ type InputState = enum
Valid
Invalid

proc searchOneCharactorToEndOfLine(bufStatus: var BufferStatus,
proc searchOneCharacterToEndOfLine(bufStatus: var BufferStatus,
windowNode: WindowNode,
rune: Rune) =
rune: Rune): int =
result = -1

let line = bufStatus.buffer[windowNode.currentLine]

Expand All @@ -20,20 +21,21 @@ proc searchOneCharactorToEndOfLine(bufStatus: var BufferStatus,

for col in windowNode.currentColumn + 1 ..< line.len:
if line[col] == rune:
windowNode.currentColumn = col
result = col
break

proc searchOneCharactorToBeginOfLine(bufStatus: var BufferStatus,
proc searchOneCharacterToBeginOfLine(bufStatus: var BufferStatus,
windowNode: WindowNode,
rune: Rune) =
rune: Rune): int =
result = -1

let line = bufStatus.buffer[windowNode.currentLine]

if line.len < 1 or isEscKey(rune) or (windowNode.currentColumn == 0): return

for col in countdown(windowNode.currentColumn - 1, 0):
if line[col] == rune:
windowNode.currentColumn = col
result = col
break

proc searchNextOccurrence(status: var EditorStatus, keyword: seq[Rune]) =
Expand Down Expand Up @@ -1148,14 +1150,36 @@ proc normalCommand(status: var EditorStatus,
status.searchNextOccurrenceReversely(word)
elif key == ord('f'):
let secondKey = commands[1]
currentBufStatus.searchOneCharactorToEndOfLine(
currentMainWindowNode,
secondKey)
let pos =
currentBufStatus.searchOneCharacterToEndOfLine(
currentMainWindowNode,
secondKey)
if pos != -1:
currentMainWindowNode.currentColumn = pos
elif key == ord('t'):
let secondKey = commands[1]
let pos =
currentBufStatus.searchOneCharacterToEndOfLine(
currentMainWindowNode,
secondKey)
if pos != -1:
currentMainWindowNode.currentColumn = pos - 1
elif key == ord('F'):
let secondKey = commands[1]
currentBufStatus.searchOneCharactorToBeginOfLine(
currentMainWindowNode,
secondKey)
let pos =
currentBufStatus.searchOneCharacterToBeginOfLine(
currentMainWindowNode,
secondKey)
if pos != -1:
currentMainWindowNode.currentColumn = pos
elif key == ord('T'):
let secondKey = commands[1]
let pos =
currentBufStatus.searchOneCharacterToBeginOfLine(
currentMainWindowNode,
secondKey)
if pos != -1:
currentMainWindowNode.currentColumn = pos + 1
elif key == ord('R'):
status.changeModeToReplaceMode
elif key == ord('i'):
Expand Down Expand Up @@ -1354,12 +1378,24 @@ proc isNormalModeCommand(command: seq[Rune]): InputState =
elif command.len == 2:
result = InputState.Valid

elif command[0] == ord('t'):
if command.len == 1:
result = InputState.Continue
elif command.len == 2:
result = InputState.Valid

elif command[0] == ord('F'):
if command.len == 1:
result = InputState.Continue
elif command.len == 2:
result = InputState.Valid

elif command[0] == ord('T'):
if command.len == 1:
result = InputState.Continue
elif command.len == 2:
result = InputState.Valid

elif command[0] == ord('Z'):
if command.len == 1:
result = InputState.Continue
Expand Down