Skip to content

Commit

Permalink
Fix 'x' with multiplier from deleting past end of line. Fixes #212
Browse files Browse the repository at this point in the history
  • Loading branch information
nosami committed Apr 29, 2018
1 parent df226bc commit 2f2dab5
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 7 deletions.
8 changes: 8 additions & 0 deletions XSVim.Tests/DeleteTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,14 @@ $ bar
let ``Delete char under caret``() =
assertText "abc$def" "x" "abd$ef"

[<Test>]
let ``Delete char at EOL``() =
assertText "abcdef$\n" "xx" "abcd$\n"

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

[<Test>]
let ``Delete char to left of caret``() =
assertText "abc$def" "X" "ac$def"
Expand Down
4 changes: 0 additions & 4 deletions XSVim.Tests/XSVim.Tests.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,6 @@
<Reference Include="atk-sharp, Version=2.12.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f" />
<Reference Include="pango-sharp, Version=2.12.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f" />
<Reference Include="Mono.Posix" />
<Reference Include="FSharp.Core">
<HintPath>..\packages\FSharp.Core.4.3.4\lib\net45\FSharp.Core.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.fs" />
Expand All @@ -80,7 +77,6 @@
<Compile Include="ExModeTests.fs" />
<Compile Include="MacrosTests.fs" />
<Compile Include="IndentationTests.fs" />
<None Include="packages.config" />
<ProjectReference Include="..\XSVim\XSVim.fsproj">
<Project>{9DB313D4-4CD1-455F-846F-42CD234DE626}</Project>
<Name>XSVim</Name>
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.1.1"
let version = "0.54.2"

[<assembly: AssemblyTitle("XSVim")>]
// The assembly version has the format {Major}.{Minor}.{Build}.{Revision}
Expand Down
25 changes: 23 additions & 2 deletions XSVim/XSVim.fs
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,7 @@ module Vim =
let endLine = editor.GetLineByOffset endPos
editor.SetSelection(startLine.Offset, endLine.EndOffsetIncludingDelimiter)
if editor.SelectionMode = SelectionMode.Block then EditActions.ToggleBlockSelectionMode editor
| _ -> editor.SetSelection(start, finish)
| _ -> editor.SetSelection(start, min finish editor.Length)

let (|MoveUpOrDown|_|) = function
| { commandType=Move; textObject=Up }
Expand Down Expand Up @@ -1213,7 +1213,28 @@ module Vim =
|> Option.iter(fun token -> token.Cancel())
{ vimState with insertModeCancellationTokenSource = None }
| _ -> vimState
if count = 1 then newState else processCommands (count-1) newState command false

match count with
| 1 -> newState
| _ ->
match command.commandType, command.textObject with
| Delete, CurrentLocation ->
// 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
// 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.
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
| _ -> processCommands (count-1) newState command false
let count = command.repeat |> Option.defaultValue 1

processCommands count vimState command true
Expand Down

0 comments on commit 2f2dab5

Please sign in to comment.