Skip to content

Commit

Permalink
More marker fixes
Browse files Browse the repository at this point in the history
d'a, v'a and :'a,'bd all now work

re: #68
  • Loading branch information
nosami committed May 14, 2018
1 parent 6aa1519 commit 849a020
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 21 deletions.
30 changes: 30 additions & 0 deletions XSVim.Tests/MarkerTests.fs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
namespace XSVim.Tests
open NUnit.Framework
open XSVim

[<TestFixture>]
module ``Marker tests`` =
Expand All @@ -18,3 +19,32 @@ module ``Marker tests`` =
[<Test>]
let ``'' jumps to last jump location line``() =
assertText "ab$c\ndef" "G''" "a$bc\ndef"

[<Test>]
let ``Deletes from 4 up to marker a``() =
assertText "1234XXXXXXXa$5678" "maF4d`a" "123a$5678"

[<Test>]
let ``Selects from 4 up to marker a``() =
let _ = test "1234XXXXXXXa$5678" "maF4v`ay"
Vim.registers.[EmptyRegister].content
|> should equal "4XXXXXXXa"

[<Test>]
let ``Deletes linewise between marker a and marker b``() =
assertText
"""
.........
aaaaa$aaaa
.........
.........
bbbbbbbbb
.........
"""

"ma/b<ret>mb:'a,'bd<ret>"

"""
.........
.$........
"""
14 changes: 14 additions & 0 deletions XSVim/ExMode.fs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
namespace XSVim
open System
open System.Text.RegularExpressions
open MonoDevelop.Ide
open MonoDevelop.Ide.Commands
open MonoDevelop.Ide.Editor.Extension
Expand All @@ -17,6 +18,14 @@ module exMode =
let save() = IdeApp.Workbench.ActiveDocument.Save() |> Async.AwaitTask
let forceClose() = IdeApp.Workbench.ActiveDocument.Window.CloseWindow true |> Async.AwaitTask |> Async.Ignore

let (|DeleteBetweenMarks|_|) input =
let matches = Regex.Matches(input, "'([a-z]),'([a-z])d", RegexOptions.Compiled)
if matches.Count = 1 then
let m = matches.[0]
Some (m.Groups.[1].Value, m.Groups.[2].Value)
else
None

let processKey (state:VimState) (key:KeyDescriptor) =
let setMessage message = { state with statusMessage = message }
let normalMode = { state with statusMessage = None; mode = NormalMode }
Expand Down Expand Up @@ -105,6 +114,11 @@ module exMode =
if notebooks.Length < 2 then
dispatchCommand "MonoDevelop.Ide.Commands.ViewCommands.SideBySideMode"
normalMode, resetKeys
| DeleteBetweenMarks (startMarker, endMarker) ->
let actions =
[ runOnce Move (Jump (ToMark (startMarker, MarkerJumpType.StartOfLine)))
runOnce DeleteWholeLines (Jump (ToMark (endMarker, MarkerJumpType.StartOfLine))) ]
normalMode, actions
| _ ->
{ state with statusMessage = sprintf "Could not parse :%s" rest |> Some; mode = NormalMode; }
, resetKeys
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.57.0"
let version = "0.58.0"

[<assembly: AssemblyTitle("XSVim")>]
// The assembly version has the format {Major}.{Minor}.{Build}.{Revision}
Expand Down
8 changes: 6 additions & 2 deletions XSVim/Types.fs
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,12 @@ type VimMode =

type MoveRightBehaviour = StopAtEndOfLine | MoveToNextLineAtEnd | IncludeDelimiter

type MarkerJumpType = Offset | StartOfLine

type Jump =
| StartOfLineNumber of int
| StartOfDocument
| ToMark of Marker
| ToMark of string * MarkerJumpType
| ToSearch of string
| ToSearchBackwards of string
| SearchAgain
Expand Down Expand Up @@ -89,6 +91,7 @@ type VimKey =
| Key c -> string c

type Repeat = int
type Offset = int

type TextObject =
| Jump of Jump
Expand Down Expand Up @@ -139,7 +142,8 @@ type TextObject =
| NextUnmatchedBrace
| PrevUnmatchedParen
| NextUnmatchedParen
| Offset of int
| Offset of Offset
| Range of Offset * Offset

type CommandType =
| Move
Expand Down
50 changes: 32 additions & 18 deletions XSVim/XSVim.fs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ module VimHelpers =
let closingBraces = [')'; '}'; ']'] |> set
let openingbraces = ['('; '{'; '[' ] |> set

let markDict = Dictionary<string, Marker>()

let findNextBraceForwardsOnLine (editor:TextEditor) (line:IDocumentLine) =
if closingBraces.Contains(editor.[editor.CaretOffset]) then
Some editor.CaretOffset
Expand Down Expand Up @@ -568,15 +570,26 @@ module VimHelpers =
match findUnmatchedBlockEndDelimiter editor editor.CaretOffset "(" ")" with
| Some jumpPos -> editor.CaretOffset, jumpPos
| None -> noOp
| Jump (ToMark mark) ->
if editor.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
| Jump (ToMark (c, jumpType)) ->
match markDict.TryGetValue c with
| true, mark ->
let offset =
match jumpType with
| MarkerJumpType.Offset -> mark.Offset
| MarkerJumpType.StartOfLine ->
let line = editor.GetLineByOffset mark.Offset
line.Offset + editor.GetLineIndent(line).Length

if editor.FileName.FullPath.ToString() = mark.FileName then
editor.CaretOffset, 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, offset
| _ -> editor.CaretOffset, editor.CaretOffset
| Offset offset -> editor.CaretOffset, offset
| Range (startOffset, endOffset) -> startOffset, endOffset
| Jump (ToSearch search) ->
let startOffset =
match vimState.keys with
Expand Down Expand Up @@ -609,7 +622,6 @@ module Vim =

registers.[EmptyRegister] <- { linewise=false; content="" }

let markDict = Dictionary<string, Marker>()
let macros = Dictionary<char, VimAction list>()

let (|VisualModes|_|) = function
Expand Down Expand Up @@ -658,6 +670,7 @@ module Vim =
let (|LineWise|_|) = function
| WholeLine
| WholeLineIncludingDelimiter
| Jump (ToMark (_, MarkerJumpType.StartOfLine))
| Jump LastLine -> Some LineWise
| _ -> None

Expand Down Expand Up @@ -1292,6 +1305,8 @@ module Vim =
| ["<C-b>"] -> Some (Jump PageUp)
| ["n"] -> Some (Jump SearchAgain)
| ["N"] -> Some (Jump SearchAgainBackwards)
| ["'"; c] -> Some (Jump (ToMark (c, MarkerJumpType.StartOfLine)))
| ["`"; c] -> Some (Jump (ToMark (c, MarkerJumpType.Offset)))
| _ -> None

let unfinishedMovements = [ "g"; "["; "]"; "@"; "m"; "`"; "'" ] |> set
Expand Down Expand Up @@ -1489,15 +1504,14 @@ module Vim =
| NormalMode, [ "r"; "<ret>" ] -> [ run (ReplaceChar "\n" ) Nothing ]
| NormalMode, [ "r"; c ] -> [ run (ReplaceChar c) Nothing ]
| NormalMode, [ "m"; c ] -> [ run (SetMark c) Nothing ]
| NotInsertMode, [ "`"; c] ->
match markDict.TryGetValue c with
| true, mark -> [ runOnce Move (Jump (ToMark mark))]
| _ -> [ run ResetKeys Nothing]
| NotInsertMode, [ "'"; c] ->
match markDict.TryGetValue c with
| true, mark -> [ runOnce Move (Jump (ToMark mark)); runOnce Move FirstNonWhitespace ]
| _ -> [ run ResetKeys Nothing]
| NotInsertMode, [ Action action; FindChar m; c ] -> [ run action (m c) ]
//| NotInsertMode, [ "`"; c] ->
//match markDict.TryGetValue c with
//| true, mark -> [ runOnce Move (Jump (ToMark mark))]
//| _ -> [ run ResetKeys Nothing]
//| NotInsertMode, [ "'"; c] ->
//match markDict.TryGetValue c with
//| true, mark -> [ runOnce Move (Jump (ToMark mark)); runOnce Move FirstNonWhitespace ]
//| _ -> [ 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 849a020

Please sign in to comment.