Skip to content

Commit

Permalink
Add support for # and £. Fixes #40
Browse files Browse the repository at this point in the history
  • Loading branch information
nosami committed May 13, 2017
1 parent c5227b8 commit c8ad990
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 10 deletions.
8 changes: 8 additions & 0 deletions XSVim.Tests/MiscTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,11 @@ module ``Miscellaneous tests`` =
[<Test>]
let ``* finds next word at EOF``() =
assertText "abc abc$" "*" "a$bc abc"

[<Test>]
let ``# finds previous word at caret``() =
assertText "abc abc a$bc" "#" "abc a$bc abc"

[<Test>]
let ``£ wraps to end``() =
assertText "a$bc abc" "£" "abc a$bc"
38 changes: 28 additions & 10 deletions XSVim/XSVim.fs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ type CommandType =
| ReplaceChar of string
| ResetKeys
| DoNothing
| Star
| Star of BeforeOrAfter

type TextObject =
| Character
Expand Down Expand Up @@ -226,6 +226,15 @@ module VimHelpers =
//bottomVisibleLine - topVisibleLine
40

let wordAtCaret (editor:TextEditor) =
if isWordChar (editor.GetCharAt editor.CaretOffset) then
let start = findCurrentWordStart editor
let finish = findWordEnd editor
let word = editor.GetTextAt(start, finish - start)
Some word
else
None

let eofOnLine (line: IDocumentLine) =
line.EndOffset = line.EndOffsetIncludingDelimiter

Expand Down Expand Up @@ -568,7 +577,7 @@ module Vim =
switchToInsertMode editor vimState
| SwitchMode mode ->
match mode with
| NormalMode ->
| NormalMode ->
editor.ClearSelection()
setCaretMode Block
vimState.undoGroup |> Option.iter(fun d -> d.Dispose())
Expand All @@ -585,20 +594,27 @@ module Vim =
newState
| InsertMode ->
switchToInsertMode editor vimState
| Star ->
if isWordChar (editor.GetCharAt editor.CaretOffset) then
let start = findCurrentWordStart editor
let finish = findWordEnd editor
let word = editor.GetTextAt(start, finish - start)
| Star After ->
match wordAtCaret editor with
| Some word ->
let offset = editor.Text.IndexOf(word, editor.CaretOffset+1)
if offset <> -1 then
editor.CaretOffset <- offset
else
editor.CaretOffset <- editor.Text.IndexOf word
vimState
else
| None ->
processCommands 1 vimState (runOnce Move WordForwards)

| Star Before ->
match wordAtCaret editor with
| Some word ->
let offset = editor.Text.LastIndexOf(word, editor.CaretOffset)
if offset <> -1 then
editor.CaretOffset <- offset
else
editor.CaretOffset <- editor.Text.LastIndexOf word
vimState
| None -> vimState
| _ -> vimState
if count = 1 then newState else processCommands (count-1) newState command
let count =
Expand Down Expand Up @@ -757,7 +773,9 @@ module Vim =
| VisualModes, [ "p" ] -> [ run (Put OverSelection) Nothing ]
| VisualModes, [ "P" ] -> [ run (Put OverSelection) Nothing ]
| NormalMode, [ "J" ] -> [ run JoinLines Nothing ]
| NotInsertMode, [ "*" ] -> [ run Star Nothing ]
| NotInsertMode, [ "*" ] -> [ run (Star After) Nothing ]
| NotInsertMode, [ "#" ] -> [ run (Star Before) Nothing ]
| NotInsertMode, [ "£" ] -> [ run (Star Before) Nothing ]
| NormalMode, [ "/" ] -> [ dispatch SearchCommands.Find ]
| NormalMode, [ "n" ] -> [ dispatch SearchCommands.FindNext ]
| NormalMode, [ "N" ] -> [ dispatch SearchCommands.FindPrevious ]
Expand Down

0 comments on commit c8ad990

Please sign in to comment.