Skip to content

Commit

Permalink
* marks as movements working
Browse files Browse the repository at this point in the history
  • Loading branch information
tdfacer authored and nosami committed Jun 7, 2017
1 parent 9c7aed6 commit 4183238
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 38 deletions.
10 changes: 1 addition & 9 deletions XSVim.Tests/Movement.fs
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,4 @@ module ``Movement tests`` =

[<Test>]
let ``gE moves back to end of last WORD``() =
assertText "abc def.gh$i" "gE" "abc$ def.ghi"

[<Test>]
let ``mark returns to position on same line``() =
assertText "ab$c def" "malll`a" "ab$c def"

[<Test>]
let ``mark returns to position on new line``() =
assertText "ab$c\ndef\nghi" "mzjjl`z" "ab$c\ndef\nghi"
assertText "abc def.gh$i" "gE" "abc$ def.ghi"
15 changes: 7 additions & 8 deletions XSVim/Types.fs
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
namespace XSVim
namespace XSVim
open System

type BeforeOrAfter = Before | After | OverSelection

type CaretMode = Insert | Block

type MarkLocation = {
offset: int
fileName: string
}

type Register =
|Register of Char
|EmptyRegister
Expand Down Expand Up @@ -41,7 +46,6 @@ type CommandType =
| IncrementNumber
| DecrementNumber
| SetMark of string
| GoToMark of string

type TextObject =
| Character
Expand Down Expand Up @@ -93,18 +97,14 @@ type TextObject =
| SelectedText
| SelectionStart
| MatchingBrace
| ToMark of MarkLocation

type VimAction = {
repeat: int option
commandType: CommandType
textObject: TextObject
}

type MarkLocation = {
offset: int
fileName: string
}

type VimState = {
keys: string list
mode: VimMode
Expand All @@ -114,7 +114,6 @@ type VimState = {
desiredColumn: int option
undoGroup: IDisposable option
statusMessage: string option
markMap: System.Collections.Generic.Dictionary<string, MarkLocation>
}

// shim for the build server which runs Mono 4.6.1
Expand Down
39 changes: 18 additions & 21 deletions XSVim/XSVim.fs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace XSVim
namespace XSVim
open System
open System.Collections.Generic
open System.Text.RegularExpressions
Expand Down Expand Up @@ -328,13 +328,22 @@ module VimHelpers =
dispatch TextEditorCommands.GotoMatchingBrace
startOffset, editor.CaretOffset
| _ -> editor.CaretOffset, editor.CaretOffset
| ToMark mark ->
if IdeApp.Workbench.ActiveDocument.FileName.FullPath.ToString() = mark.fileName then
editor.CaretOffset, mark.offset
else
let document = IdeApp.Workbench.GetDocument(mark.fileName)
let fileInfo = new MonoDevelop.Ide.Gui.FileOpenInformation (document.FileName, document.Project)
IdeApp.Workbench.OpenDocument(fileInfo) |> ignore
editor.CaretOffset, editor.CaretOffset
| _ -> editor.CaretOffset, editor.CaretOffset

module Vim =
let registers = new Dictionary<Register, string>()
registers.[EmptyRegister] <- ""

let defaultState = { keys=[]; mode=NormalMode; visualStartOffset=0; findCharCommand=None; lastAction=[]; desiredColumn=None; undoGroup=None; statusMessage=None; markMap=System.Collections.Generic.Dictionary<string,MarkLocation>()}
let markDict = System.Collections.Generic.Dictionary<string,MarkLocation>()
let defaultState = { keys=[]; mode=NormalMode; visualStartOffset=0; findCharCommand=None; lastAction=[]; desiredColumn=None; undoGroup=None; statusMessage=None; }
let (|VisualModes|_|) = function
| VisualMode | VisualLineMode | VisualBlockMode -> Some VisualModes
| _ -> None
Expand Down Expand Up @@ -605,19 +614,10 @@ module Vim =
EditActions.MoveCaretLeft editor
vimState
| SetMark c ->
if vimState.markMap.ContainsKey c then
vimState.markMap.Remove c |> ignore
if markDict.ContainsKey c then
markDict.Remove c |> ignore
let location = { offset=editor.CaretOffset; fileName=editor.FileName.FullPath.ToString() }
vimState.markMap.Add (c, location) |> ignore
vimState
| GoToMark c ->
if vimState.markMap.ContainsKey c then
let name = (vimState.markMap.Item c).fileName
if IdeApp.Workbench.ActiveDocument.FileName.FullPath.ToString() <> name then
let document = IdeApp.Workbench.GetDocument(name)
let fileInfo = new MonoDevelop.Ide.Gui.FileOpenInformation (document.FileName, document.Project)
IdeApp.Workbench.OpenDocument(fileInfo) |> ignore
editor.CaretOffset <- (vimState.markMap.Item c).offset
markDict.Add (c, location) |> ignore
vimState
| InsertLine Before ->
EditActions.InsertNewLineAtEnd editor
Expand Down Expand Up @@ -804,11 +804,6 @@ module Vim =
| "<esc>" | "<C-c>" | "<C-[>" -> Some Escape
| _ -> None

let (|MarkChar|_|) = function
| "m" -> Some SetMark
| "`" -> Some GoToMark
| _ -> None

let wait = [ getCommand None DoNothing Nothing ]

let parseKeys (state:VimState) =
Expand All @@ -817,7 +812,6 @@ module Vim =
match keyList with
| "r" :: _ -> None, keyList
| FindChar _ :: _ -> None, keyList
| MarkChar _ :: _ -> None, keyList
// 2dw -> 2, dw
| OneToNine d1 :: Digit d2 :: Digit d3 :: Digit d4 :: t ->
Some (d1 * 1000 + d2 * 100 + d3 * 10 + d4), t
Expand Down Expand Up @@ -908,7 +902,10 @@ module Vim =
| NormalMode, [ "r" ] -> wait
| NormalMode, [ "r"; c ] -> [ run (ReplaceChar c) Nothing ]
| NormalMode, [ "m"; c ] -> [ run (SetMark c) Nothing ]
| NormalMode, [ "`"; c ] -> [ run (GoToMark c) Nothing ]
| NotInsertMode, [ "`"; c] ->
match markDict.TryGetValue c with
| true, mark -> [ runOnce Move (ToMark mark)]
| _ -> [ run ResetKeys Nothing]
| NotInsertMode, [ Action action; FindChar m; c ] -> [ run action (m c) ]
| NotInsertMode, [ Action action; "i"; BlockDelimiter c ] -> [ run action (InnerBlock c) ]
| NotInsertMode, [ Action action; "a"; BlockDelimiter c ] -> [ run action (ABlock c) ]
Expand Down

0 comments on commit 4183238

Please sign in to comment.