From e31f17a517f3ebaa2d5218d7d1a1675400edfe1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Unai=20Hern=C3=A1ndez=20Minaberry?= Date: Tue, 17 Aug 2021 23:31:05 -0300 Subject: [PATCH 1/4] Add command 't' --- src/moepkg/normalmode.nim | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/src/moepkg/normalmode.nim b/src/moepkg/normalmode.nim index 0d5f6765b..2c930b244 100644 --- a/src/moepkg/normalmode.nim +++ b/src/moepkg/normalmode.nim @@ -11,7 +11,8 @@ type InputState = enum proc searchOneCharactorToEndOfLine(bufStatus: var BufferStatus, windowNode: WindowNode, - rune: Rune) = + rune: Rune): int = + result = -1 let line = bufStatus.buffer[windowNode.currentLine] @@ -20,7 +21,7 @@ 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, @@ -1148,9 +1149,20 @@ proc normalCommand(status: var EditorStatus, status.searchNextOccurrenceReversely(word) elif key == ord('f'): let secondKey = commands[1] - currentBufStatus.searchOneCharactorToEndOfLine( - currentMainWindowNode, - secondKey) + let pos = + currentBufStatus.searchOneCharactorToEndOfLine( + currentMainWindowNode, + secondKey) + if pos >= 0: + currentMainWindowNode.currentColumn = pos + elif key == ord('t'): + let secondKey = commands[1] + let pos = + currentBufStatus.searchOneCharactorToEndOfLine( + currentMainWindowNode, + secondKey) + if pos > 0: + currentMainWindowNode.currentColumn = pos - 1 elif key == ord('F'): let secondKey = commands[1] currentBufStatus.searchOneCharactorToBeginOfLine( @@ -1354,6 +1366,12 @@ 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 From 2e8bb607648b0033aaf2552c22b8f090c43f6751 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Unai=20Hern=C3=A1ndez=20Minaberry?= Date: Tue, 17 Aug 2021 23:38:20 -0300 Subject: [PATCH 2/4] Add command 'T' --- src/moepkg/normalmode.nim | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/src/moepkg/normalmode.nim b/src/moepkg/normalmode.nim index 2c930b244..64b236ef1 100644 --- a/src/moepkg/normalmode.nim +++ b/src/moepkg/normalmode.nim @@ -26,7 +26,8 @@ proc searchOneCharactorToEndOfLine(bufStatus: var BufferStatus, proc searchOneCharactorToBeginOfLine(bufStatus: var BufferStatus, windowNode: WindowNode, - rune: Rune) = + rune: Rune): int = + result = -1 let line = bufStatus.buffer[windowNode.currentLine] @@ -34,7 +35,7 @@ proc searchOneCharactorToBeginOfLine(bufStatus: var BufferStatus, 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]) = @@ -1165,9 +1166,20 @@ proc normalCommand(status: var EditorStatus, currentMainWindowNode.currentColumn = pos - 1 elif key == ord('F'): let secondKey = commands[1] - currentBufStatus.searchOneCharactorToBeginOfLine( - currentMainWindowNode, - secondKey) + let pos = + currentBufStatus.searchOneCharactorToBeginOfLine( + currentMainWindowNode, + secondKey) + if pos >= 0: + currentMainWindowNode.currentColumn = pos + elif key == ord('T'): + let secondKey = commands[1] + let pos = + currentBufStatus.searchOneCharactorToBeginOfLine( + currentMainWindowNode, + secondKey) + if pos >= 0: + currentMainWindowNode.currentColumn = pos + 1 elif key == ord('R'): status.changeModeToReplaceMode elif key == ord('i'): @@ -1378,6 +1390,12 @@ 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('Z'): if command.len == 1: result = InputState.Continue From d37d8b974141621972f3be65a572a165bf05dfd7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Unai=20Hern=C3=A1ndez=20Minaberry?= Date: Tue, 17 Aug 2021 23:40:55 -0300 Subject: [PATCH 3/4] Remove unnecessary checks --- src/moepkg/normalmode.nim | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/moepkg/normalmode.nim b/src/moepkg/normalmode.nim index 64b236ef1..9deaeba69 100644 --- a/src/moepkg/normalmode.nim +++ b/src/moepkg/normalmode.nim @@ -1154,7 +1154,7 @@ proc normalCommand(status: var EditorStatus, currentBufStatus.searchOneCharactorToEndOfLine( currentMainWindowNode, secondKey) - if pos >= 0: + if pos != -1: currentMainWindowNode.currentColumn = pos elif key == ord('t'): let secondKey = commands[1] @@ -1162,7 +1162,7 @@ proc normalCommand(status: var EditorStatus, currentBufStatus.searchOneCharactorToEndOfLine( currentMainWindowNode, secondKey) - if pos > 0: + if pos != -1: currentMainWindowNode.currentColumn = pos - 1 elif key == ord('F'): let secondKey = commands[1] @@ -1170,7 +1170,7 @@ proc normalCommand(status: var EditorStatus, currentBufStatus.searchOneCharactorToBeginOfLine( currentMainWindowNode, secondKey) - if pos >= 0: + if pos != -1: currentMainWindowNode.currentColumn = pos elif key == ord('T'): let secondKey = commands[1] @@ -1178,7 +1178,7 @@ proc normalCommand(status: var EditorStatus, currentBufStatus.searchOneCharactorToBeginOfLine( currentMainWindowNode, secondKey) - if pos >= 0: + if pos != -1: currentMainWindowNode.currentColumn = pos + 1 elif key == ord('R'): status.changeModeToReplaceMode From 70b495d7990fcce9e3103dd3d9ac5303970a87ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Unai=20Hern=C3=A1ndez=20Minaberry?= Date: Tue, 17 Aug 2021 23:42:42 -0300 Subject: [PATCH 4/4] Fix #1426 --- src/moepkg/normalmode.nim | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/moepkg/normalmode.nim b/src/moepkg/normalmode.nim index 9deaeba69..43ffbcdd4 100644 --- a/src/moepkg/normalmode.nim +++ b/src/moepkg/normalmode.nim @@ -9,7 +9,7 @@ type InputState = enum Valid Invalid -proc searchOneCharactorToEndOfLine(bufStatus: var BufferStatus, +proc searchOneCharacterToEndOfLine(bufStatus: var BufferStatus, windowNode: WindowNode, rune: Rune): int = result = -1 @@ -24,7 +24,7 @@ proc searchOneCharactorToEndOfLine(bufStatus: var BufferStatus, result = col break -proc searchOneCharactorToBeginOfLine(bufStatus: var BufferStatus, +proc searchOneCharacterToBeginOfLine(bufStatus: var BufferStatus, windowNode: WindowNode, rune: Rune): int = result = -1 @@ -1151,7 +1151,7 @@ proc normalCommand(status: var EditorStatus, elif key == ord('f'): let secondKey = commands[1] let pos = - currentBufStatus.searchOneCharactorToEndOfLine( + currentBufStatus.searchOneCharacterToEndOfLine( currentMainWindowNode, secondKey) if pos != -1: @@ -1159,7 +1159,7 @@ proc normalCommand(status: var EditorStatus, elif key == ord('t'): let secondKey = commands[1] let pos = - currentBufStatus.searchOneCharactorToEndOfLine( + currentBufStatus.searchOneCharacterToEndOfLine( currentMainWindowNode, secondKey) if pos != -1: @@ -1167,7 +1167,7 @@ proc normalCommand(status: var EditorStatus, elif key == ord('F'): let secondKey = commands[1] let pos = - currentBufStatus.searchOneCharactorToBeginOfLine( + currentBufStatus.searchOneCharacterToBeginOfLine( currentMainWindowNode, secondKey) if pos != -1: @@ -1175,7 +1175,7 @@ proc normalCommand(status: var EditorStatus, elif key == ord('T'): let secondKey = commands[1] let pos = - currentBufStatus.searchOneCharactorToBeginOfLine( + currentBufStatus.searchOneCharacterToBeginOfLine( currentMainWindowNode, secondKey) if pos != -1: