Skip to content

Commit

Permalink
Fix off by one error when using x with repeat.
Browse files Browse the repository at this point in the history
Fixes #212
  • Loading branch information
nosami committed Apr 30, 2018
1 parent 04872b5 commit ff69ad0
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
6 changes: 5 additions & 1 deletion XSVim.Tests/DeleteTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,13 @@ $ bar
let ``Delete char at EOL``() =
assertText "abcdef$\n" "xx" "abcd$\n"

[<Test>]
let ``x with multiplier stops at EOL (caret at EOL)``() =
assertText "abcdef$\n" "4x" "abcde$\n"

[<Test>]
let ``x with multiplier stops at EOL``() =
assertText "abcdef$" "4x" "abcde$"
assertText "ab$cdef\n" "100x" "a$\n"

[<Test>]
let ``Delete char to left of caret``() =
Expand Down
2 changes: 1 addition & 1 deletion XSVim/Properties/AssemblyInfo.fs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ open System.Runtime.CompilerServices
[<AutoOpen>]
module AddinVersion =
[<Literal>]
let version = "0.54.3"
let version = "0.54.4"

[<assembly: AssemblyTitle("XSVim")>]
// The assembly version has the format {Major}.{Minor}.{Build}.{Revision}
Expand Down
15 changes: 12 additions & 3 deletions XSVim/XSVim.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1222,18 +1222,27 @@ module Vim =
// When the caret is at the end of the line,
// the multiplier should be ignored.
// As far as I can tell, this is an exception
// to the rule - x usually deletes the character
// to the rule.
// `x` usually deletes the character
// at the caret and then moves right,
// unless the caret is at the EOL, in which case
// it deletes and then moves to the left.
// We need to suppress this behaviour when repeat is used.
let offset = min (editor.Length-1) (editor.CaretOffset+1)
let charAtCaret = editor.[offset]

if not (isEOLChar charAtCaret) then
processCommands (count-1) newState command false
else
// stop repeating
newState
match command.repeat with
| Some repeat ->
// stop repeating
if count < repeat then
// we need to loop one more time
processCommands 1 newState command false
else
newState
| None -> newState
| _ -> processCommands (count-1) newState command false
let count = command.repeat |> Option.defaultValue 1

Expand Down

0 comments on commit ff69ad0

Please sign in to comment.