Skip to content

Commit

Permalink
Adds . mark for last edit location. Fixes #72 and #68
Browse files Browse the repository at this point in the history
  • Loading branch information
nosami committed Jun 16, 2017
1 parent 6fbdbc8 commit 2e17591
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 7 deletions.
16 changes: 16 additions & 0 deletions XSVim.Tests/MarkerTests.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
namespace XSVim.Tests
open NUnit.Framework

[<TestFixture>]
module ``Marker tests`` =
[<Test>]
let ``ma adds marker a``() =
assertText "a$bc" "mall`a" "a$bc"

[<Test>]
let ``'a moves to start of line of marker a``() =
assertText "123 a$bc" "mall'a" "1$23 abc"

[<Test>]
let ``'. jumps to last edit line``() =
assertText " 123 a$bc" "i<esc>'." " 1$23 abc"
2 changes: 1 addition & 1 deletion XSVim.Tests/MiscTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,4 @@ module ``Miscellaneous tests`` =

[<Test>]
let ``<C-x> decrements -1``() =
assertText "abc -1$ " "<C-x>" "abc -2$ "
assertText "abc -1$ " "<C-x>" "abc -2$ "
1 change: 1 addition & 0 deletions XSVim.Tests/XSVim.Tests.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
<Compile Include="ChangeTests.fs" />
<Compile Include="InsertionTests.fs" />
<Compile Include="TextObjectSelectionTests.fs" />
<Compile Include="MarkerTests.fs" />
</ItemGroup>
<Import Project="$(FSharpTargetsPath)" />
</Project>
22 changes: 16 additions & 6 deletions XSVim/XSVim.fs
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,11 @@ module VimHelpers =
let findQuoteTriplet (editor:TextEditor) line quoteChar =
let firstBackwards = findCharBackwardsOnLine editor.CaretOffset editor line ((=) quoteChar)
let firstForwards = findCharForwardsOnLine editor line editor.CaretOffset (string quoteChar)
let secondForwards = match firstForwards with
| Some offset when offset + 1 < editor.Text.Length ->
findCharForwardsOnLine editor line offset (string quoteChar)
| _ -> None
let secondForwards =
match firstForwards with
| Some offset when offset + 1 < editor.Text.Length ->
findCharForwardsOnLine editor line offset (string quoteChar)
| _ -> None
firstBackwards, firstForwards, secondForwards

let getRange (vimState:VimState) (editor:TextEditor) (command:VimAction) =
Expand Down Expand Up @@ -403,7 +404,7 @@ module VimHelpers =
startOffset, editor.CaretOffset
| _ -> editor.CaretOffset, editor.CaretOffset
| ToMark mark ->
if IdeApp.Workbench.ActiveDocument.FileName.FullPath.ToString() = mark.FileName then
if editor.FileName.FullPath.ToString() = mark.FileName then
editor.CaretOffset, mark.Offset
else
let document = IdeApp.Workbench.GetDocument(mark.FileName)
Expand Down Expand Up @@ -746,7 +747,11 @@ module Vim =
setCaretMode vimState Block

vimState.undoGroup |> Option.iter(fun d -> d.Dispose())

let vimState =
if vimState.mode = InsertMode then
processCommands 1 vimState (runOnce (SetMark ".") Nothing) false
else
vimState
{ vimState with mode = mode; lastSelection = lastSelection; undoGroup = None; statusMessage = None }
| VisualMode | VisualLineMode | VisualBlockMode ->
setCaretMode vimState Block
Expand Down Expand Up @@ -1015,6 +1020,10 @@ module Vim =
match markDict.TryGetValue c with
| true, mark -> [ runOnce Move (ToMark mark)]
| _ -> [ run ResetKeys Nothing]
| NotInsertMode, [ "'"; c] ->
match markDict.TryGetValue c with
| true, mark -> [ runOnce Move (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 All @@ -1041,6 +1050,7 @@ module Vim =
| NotInsertMode, [ "g" ] -> wait
| NotInsertMode, [ "m" ] -> wait
| NotInsertMode, [ "`" ] -> wait
| NotInsertMode, [ "'" ] -> wait
| NotInsertMode, [ "g"; "g" ] ->
let lineNumber = match numericArgument with Some n -> n | None -> 1
[ runOnce Move (StartOfLineNumber lineNumber) ]
Expand Down

0 comments on commit 2e17591

Please sign in to comment.