Skip to content

Commit

Permalink
Fix I with dot. Fixes #215
Browse files Browse the repository at this point in the history
  • Loading branch information
nosami committed May 1, 2018
1 parent 997c9d5 commit 27c9c02
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 17 deletions.
36 changes: 33 additions & 3 deletions XSVim.Tests/MiscTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ module ``Miscellaneous tests`` =

[<Test>]
let ``Repeat typed chars``() =
assertText " $" "iabc <esc>." "abcabc $ "
assertText "d$" "iabc <esc>." "abcabc $ d"

[<Test>]
let ``backspace is repeated``() =
assertText " $" "iabc<bs> <esc>." "abab $ "
assertText "d$" "iabc<bs> <esc>." "abab $ d"

[<Test>]
let ``delete key is repeated``() =
Expand All @@ -52,13 +52,43 @@ module ``Miscellaneous tests`` =
let ``<C-[> escapes``() =
assertText " abc$" "i<C-[>" " ab$c"

[<Test>]
let ``dot repeats at start of line``() =
assertText
"""
def$
def
"""

"Iabc<esc>j."

"""
abcdef
abc$def
"""

[<Test>]
let ``dot repeats at end of line``() =
assertText
"""
a$bc
a$bc
"""

"Adef<esc>j."

"""
abcdef
abcdef$
"""

[<Test>]
let ``Repeat delete word``() =
assertText "a$bc de fgh" "dww." "de $"

[<Test>]
let ``Repeat change word``() =
assertText "a$bc de fgz " "cwxxx<esc>ww." "xxx de xxx $"
assertText "a$bc de fgz " "cwxxx<esc>ww." "xxx de xxx$ "

[<Test>]
let ``r should be repeatable``() =
Expand Down
20 changes: 11 additions & 9 deletions XSVim.Tests/TestHelpers.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand All @@ -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"
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.5"
let version = "0.54.6"

[<assembly: AssemblyTitle("XSVim")>]
// The assembly version has the format {Major}.{Minor}.{Build}.{Revision}
Expand Down
9 changes: 5 additions & 4 deletions XSVim/XSVim.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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) =
Expand Down Expand Up @@ -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)) ]
Expand Down Expand Up @@ -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 }
Expand Down

0 comments on commit 27c9c02

Please sign in to comment.