From 7a4585fe6484bca7e23723441b4059e0686d363e Mon Sep 17 00:00:00 2001 From: nosami Date: Wed, 6 Jun 2018 14:51:03 +0100 Subject: [PATCH] Fix dj/dk/d2j etc. Fixes #227 --- XSVim.Tests/DeleteTests.fs | 29 +++++++++++++++++++++++++ XSVim/Properties/AssemblyInfo.fs | 2 +- XSVim/XSVim.fs | 37 ++++++++++++++++++++++++++++---- 3 files changed, 63 insertions(+), 5 deletions(-) diff --git a/XSVim.Tests/DeleteTests.fs b/XSVim.Tests/DeleteTests.fs index 552cd6c..76cda55 100644 --- a/XSVim.Tests/DeleteTests.fs +++ b/XSVim.Tests/DeleteTests.fs @@ -18,6 +18,35 @@ module ``Delete tests`` = eeeeee"; assertText source "Vjd" expected + [] + let ``Delete line and line below``() = + let source = + @"aaaaaa + bb$bbbb + cccccc + dddddd + eeeeee"; + + let expected = + @"aaaaaa + d$ddddd + eeeeee"; + assertText source "dj" expected + + [] + let ``Delete line and next two lines``() = + let source = + @"aaaaaa + bb$bbbb + cccccc + dddddd + eeeeee"; + + let expected = + @"aaaaaa + e$eeeee"; + assertText source "d2j" expected + [] let ``dd first line``() = assertText "ab$c\n def" "dd" " d$ef" diff --git a/XSVim/Properties/AssemblyInfo.fs b/XSVim/Properties/AssemblyInfo.fs index 37d4a92..86d9c30 100644 --- a/XSVim/Properties/AssemblyInfo.fs +++ b/XSVim/Properties/AssemblyInfo.fs @@ -5,7 +5,7 @@ open System.Runtime.CompilerServices [] module AddinVersion = [] - let version = "0.60.2" + let version = "0.60.3" [] // The assembly version has the format {Major}.{Minor}.{Build}.{Revision} diff --git a/XSVim/XSVim.fs b/XSVim/XSVim.fs index a3d5707..d7c957b 100755 --- a/XSVim/XSVim.fs +++ b/XSVim/XSVim.fs @@ -670,6 +670,7 @@ module Vim = | _ -> None let (|LineWise|_|) = function + | Up | Down | WholeLine | WholeLineIncludingDelimiter | Jump (ToMark (_, MarkerJumpType.StartOfLine)) @@ -891,9 +892,25 @@ module Vim = { vimState with desiredColumn = Some editor.CaretColumn } newState | Delete -> + let linewise = isLineWise vimState command + let start, finish = + match linewise with + | true -> + + let min = min start finish + let maxOffset = max start finish + let line = editor.GetLineByOffset min + let finish = editor.GetLineByOffset(maxOffset).EndOffsetIncludingDelimiter + if eofOnLine line && line.LineNumber <> 1 then + let delimiter = inferDelimiter editor + line.Offset-delimiter.Length, finish + else + line.Offset, finish + | false -> start, finish + let newState = delete vimState start finish let offsetBeforeDelimiter = - match isLineWise vimState command with + match linewise with | true -> let line = editor.GetLineByOffset(editor.CaretOffset) let line = @@ -1443,6 +1460,18 @@ module Vim = | Some chars -> [ switchMode VisualMode; getCommand (chars-1 |> Some) Move (Right StopAtEndOfLine) ] | None -> [ switchMode VisualMode ] | NormalMode, [ "d"; "G" ] -> [ runOnce DeleteWholeLines (Jump LastLine)] + | NormalMode, [ "d"; "j" ] -> + let numberOfLines = + match numericArgument with + | Some lines -> lines + | None -> 1 + [ switchMode VisualLineMode; getCommand (numberOfLines |> Some) Move Down; runOnce Delete SelectedText ] + | NormalMode, [ "d"; "k" ] -> + let numberOfLines = + match numericArgument with + | Some lines -> lines + | None -> 1 + [ switchMode VisualLineMode; getCommand (numberOfLines |> Some) Move Up; runOnce Delete SelectedText ] | NotInsertMode, [ (Action _) ; UnfinishedMovement ] -> wait | NotInsertMode, [ UnfinishedMovement ] -> wait | NormalMode, [ "d"; "g"; "g" ] -> [ runOnce DeleteWholeLines (Jump StartOfDocument)] @@ -1462,7 +1491,7 @@ module Vim = | NormalMode, [ "" ] -> [ run Redo Nothing ] | NormalMode, [ "d"; "d" ] -> match numericArgument with - | None -> [ run Delete WholeLineIncludingDelimiter ] + | None -> [ run Delete WholeLine ] | Some lines -> [ switchMode VisualLineMode getCommand (lines-1 |> Some) Move Down @@ -1484,7 +1513,7 @@ module Vim = | NormalMode, [ "x" ] -> [ runOnce Delete (Character (numericArgument |> Option.defaultValue 1)) ] | NormalMode, [ "X" ] -> [ run DeleteLeft Nothing ] | NormalMode, [ "s"] -> [ run Substitute CurrentLocation] - | NormalMode, [ "S"] -> [ run Delete WholeLineIncludingDelimiter; runOnce (InsertLine After) Nothing; switchMode InsertMode ] + | NormalMode, [ "S"] -> [ run Delete WholeLine; runOnce (InsertLine After) Nothing; switchMode InsertMode ] | NormalMode, [ "p" ] -> [ run (Put After) Nothing ] | NormalMode, [ "P" ] -> [ run (Put Before) Nothing ] | VisualModes, [ "p" ] -> [ run (Put OverSelection) Nothing ] @@ -1591,7 +1620,7 @@ module Vim = | NormalMode, [ "~" ] -> [ run ToggleCase CurrentLocation ] | VisualModes, [ "~" ] -> [ run ToggleCase SelectedText; switchMode NormalMode ] | VisualModes, [ "y" ] -> [ run (Yank EmptyRegister) SelectedText; switchMode NormalMode ] - | VisualModes, [ "Y" ] -> [ run (Yank EmptyRegister) WholeLineIncludingDelimiter; switchMode NormalMode ] + | VisualModes, [ "Y" ] -> [ run (Yank EmptyRegister) WholeLine; switchMode NormalMode ] | VisualModes, [ ">" ] -> [ run (Func EditActions.IndentSelection) Nothing; switchMode NormalMode ] | VisualModes, [ "<" ] -> [ run (Func EditActions.UnIndentSelection) Nothing; switchMode NormalMode ] | VisualModes, [ "=" ] -> [ run EqualIndent SelectedText; switchMode NormalMode ]