From 27c9c02573175983d22ad725066d2e134d3734e5 Mon Sep 17 00:00:00 2001 From: nosami Date: Tue, 1 May 2018 08:25:27 +0100 Subject: [PATCH] Fix `I` with dot. Fixes #215 --- XSVim.Tests/MiscTests.fs | 36 +++++++++++++++++++++++++++++--- XSVim.Tests/TestHelpers.fs | 20 ++++++++++-------- XSVim/Properties/AssemblyInfo.fs | 2 +- XSVim/XSVim.fs | 9 ++++---- 4 files changed, 50 insertions(+), 17 deletions(-) diff --git a/XSVim.Tests/MiscTests.fs b/XSVim.Tests/MiscTests.fs index eca0df3..6c53cf0 100644 --- a/XSVim.Tests/MiscTests.fs +++ b/XSVim.Tests/MiscTests.fs @@ -38,11 +38,11 @@ module ``Miscellaneous tests`` = [] let ``Repeat typed chars``() = - assertText " $" "iabc ." "abcabc $ " + assertText "d$" "iabc ." "abcabc $ d" [] let ``backspace is repeated``() = - assertText " $" "iabc ." "abab $ " + assertText "d$" "iabc ." "abab $ d" [] let ``delete key is repeated``() = @@ -52,13 +52,43 @@ module ``Miscellaneous tests`` = let `` escapes``() = assertText " abc$" "i" " ab$c" + [] + let ``dot repeats at start of line``() = + assertText + """ + def$ + def + """ + + "Iabcj." + + """ + abcdef + abc$def + """ + + [] + let ``dot repeats at end of line``() = + assertText + """ + a$bc + a$bc + """ + + "Adefj." + + """ + abcdef + abcdef$ + """ + [] let ``Repeat delete word``() = assertText "a$bc de fgh" "dww." "de $" [] let ``Repeat change word``() = - assertText "a$bc de fgz " "cwxxxww." "xxx de xxx $" + assertText "a$bc de fgz " "cwxxxww." "xxx de xxx$ " [] let ``r should be repeatable``() = diff --git a/XSVim.Tests/TestHelpers.fs b/XSVim.Tests/TestHelpers.fs index 7633c2b..58452a4 100644 --- a/XSVim.Tests/TestHelpers.fs +++ b/XSVim.Tests/TestHelpers.fs @@ -110,6 +110,15 @@ module TestHelpers = let keys = Regex.Replace(keys, "<(.*?)>", "§$1§") keys.Split '§' |> Array.collect groupToKeys + let getEditorText (editor:TextEditor) state = + if state.mode = InsertMode then + editor.Text.Insert(editor.CaretOffset, "|") + else + if editor.CaretOffset = editor.Text.Length then + editor.Text + "$" + else + editor.Text.Insert(editor.CaretOffset+1, "$") + let testWithEol (source:string) (keys:string) eolMarker = FixtureSetup.initialiseMonoDevelop() let config = { insertModeEscapeKey = None } @@ -128,20 +137,13 @@ module TestHelpers = |> Array.fold(fun state (descriptor, vimKey) -> let handledState, handledKeyPress = Vim.handleKeyPress state descriptor editor config printfn "%A" handledState - printfn "%s" editor.Text + printfn "\"%s\"" (getEditorText editor handledState) if state.mode = InsertMode && descriptor.ModifierKeys <> ModifierKeys.Control && descriptor.SpecialKey <> SpecialKey.Escape then Vim.processVimKey editor vimKey handledState) VimState.Default let cursor = if newState.mode = InsertMode then "|" else "$" - let text = - if newState.mode = InsertMode then - editor.Text.Insert(editor.CaretOffset, "|") - else - if editor.CaretOffset = editor.Text.Length then - editor.Text + "$" - else - editor.Text.Insert(editor.CaretOffset+1, "$") + let text = getEditorText editor newState text, newState let test source keys = testWithEol source keys "\n" diff --git a/XSVim/Properties/AssemblyInfo.fs b/XSVim/Properties/AssemblyInfo.fs index 6ed1699..b2cd67a 100644 --- a/XSVim/Properties/AssemblyInfo.fs +++ b/XSVim/Properties/AssemblyInfo.fs @@ -5,7 +5,7 @@ open System.Runtime.CompilerServices [] module AddinVersion = [] - let version = "0.54.5" + let version = "0.54.6" [] // The assembly version has the format {Major}.{Minor}.{Build}.{Revision} diff --git a/XSVim/XSVim.fs b/XSVim/XSVim.fs index 51286a3..fc7a633 100755 --- a/XSVim/XSVim.fs +++ b/XSVim/XSVim.fs @@ -753,6 +753,8 @@ module Vim = // https://github.com/mono/monodevelop/blob/fdbfbe89529bd9076e1906e7b70fdb51a9ae6b99/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Editor.Extension/CompletionTextEditorExtension.cs#L153 if editor.SelectionMode = SelectionMode.Normal then EditActions.ToggleBlockSelectionMode editor vimState.undoGroup |> Option.iter(fun d -> d.Dispose()) + if vimState.mode = InsertMode then + EditActions.MoveCaretLeft editor { vimState with mode = NormalMode; lastSelection = lastSelection; undoGroup = None; statusMessage = None } let processVimKey (editor:TextEditor) = @@ -1439,20 +1441,18 @@ module Vim = match state.mode, keyList with | VisualBlockMode, [ Escape ] -> [ switchMode NormalMode; run Move SelectionStart ] | NormalMode, [ Escape ] -> resetKeys - | VisualModes, [ Escape ] -> [ switchMode NormalMode ] - | ExMode _, [ Escape ] -> [ switchMode NormalMode ] + | _, [ Escape ] -> [ switchMode NormalMode ] | InsertMode, [ c ] when c = insertModeEscapeFirstChar -> delayedFunc (fun editor -> editor.InsertAtCaret insertModeEscapeFirstChar let oldState = editorStates.[editor.FileName.FullPath |> string] editorStates.[editor.FileName.FullPath |> string] <- { oldState with keys = [] } ) insertModeTimeout :: wait | InsertMode, [ c1; c2 ] when c1 = insertModeEscapeFirstChar && c2 = insertModeEscapeSecondChar -> - [ run CancelFunc Nothing; switchMode NormalMode; run Move Left ] + [ run CancelFunc Nothing; switchMode NormalMode ] | InsertMode, [ c; _ ] when c = insertModeEscapeFirstChar -> [ run CancelFunc Nothing run (ChangeState { state with keys = [] }) Nothing typeChar (Key (char insertModeEscapeFirstChar)) ] - | _, [ Escape ] -> [ switchMode NormalMode; run Move Left ] | NotInsertMode, [ "G" ] -> match numericArgument with | Some lineNumber -> [ runOnce Move (Jump (StartOfLineNumber lineNumber)) ] @@ -1747,6 +1747,7 @@ module Vim = | NotInsertMode, _, ReplaceChar _ | NotInsertMode, Key 'a', _ | NotInsertMode, Key 'i', _ + | NotInsertMode, Key 'I', _ | NotInsertMode, Key 'o', _ | NotInsertMode, Key 'O', _ | NotInsertMode, Key 'A', _ -> { newState with lastAction = action }