Skip to content

Commit

Permalink
Merge pull request #1427 from uninhm/develop
Browse files Browse the repository at this point in the history
't' & 'T' commands, and a typo fix
  • Loading branch information
fox0430 authored Aug 18, 2021
2 parents d5f52f7 + 70b495d commit 1a9bc1c
Showing 1 changed file with 48 additions and 12 deletions.
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

0 comments on commit 1a9bc1c

Please sign in to comment.