Skip to content

Commit

Permalink
Add --INSERT-- status message
Browse files Browse the repository at this point in the history
  • Loading branch information
nosami committed May 13, 2017
1 parent c8ad990 commit 2f36130
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion XSVim.Tests/KeyParsing.fs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ open NUnit.Framework
module ``Key parsing tests`` =
let test keys =
let keys = [for c in keys -> c.ToString()]
let state = { keys=keys; mode=NormalMode; visualStartOffset=0; findCharCommand=None; lastAction=[]; desiredColumn=None; undoGroup=None }
let state = Vim.defaultState
let action, _state = Vim.parseKeys state
let first = action.Head
first.repeat, first.commandType, first.textObject
Expand Down
2 changes: 1 addition & 1 deletion XSVim.Tests/TestHelpers.fs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ module TestHelpers =
editor.CaretOffset <- caret-1

let plugin = new XSVim()
let state = { keys=[]; mode=NormalMode; visualStartOffset=0; findCharCommand=None; lastAction=[]; desiredColumn=None; undoGroup=None }
let state = Vim.defaultState
let keyDescriptors = parseKeys keys
let newState =
keyDescriptors
Expand Down
13 changes: 9 additions & 4 deletions XSVim/XSVim.fs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ type VimState = {
lastAction: VimAction list // used by . command to repeat the last action
desiredColumn: int option
undoGroup: IDisposable option
statusMessage: string option
}

[<AutoOpen>]
Expand Down Expand Up @@ -383,6 +384,7 @@ module VimHelpers =

module Vim =
let mutable clipboard = ""
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 @@ -451,7 +453,7 @@ module Vim =
let switchToInsertMode (editor:TextEditor) state =
let group = editor.OpenUndoGroup()
setCaretMode Insert
{ state with mode = InsertMode; keys = []; undoGroup = Some group }
{ state with mode = InsertMode; statusMessage = "-- INSERT --" |> Some; keys = []; undoGroup = Some group }

let rec processCommands count vimState command =
let start, finish = VimHelpers.getRange vimState editor command.textObject
Expand Down Expand Up @@ -581,11 +583,11 @@ module Vim =
editor.ClearSelection()
setCaretMode Block
vimState.undoGroup |> Option.iter(fun d -> d.Dispose())
{ vimState with mode = mode; undoGroup = None }
{ vimState with mode = mode; undoGroup = None; statusMessage = None }
| VisualMode | VisualLineMode | VisualBlockMode ->
setCaretMode Block
let start, finish = VimHelpers.getRange vimState editor command.textObject
let newState = { vimState with mode = mode; visualStartOffset = editor.CaretOffset }
let newState = { vimState with mode = mode; visualStartOffset = editor.CaretOffset; statusMessage = None }
setSelection newState editor command start finish
match mode, editor.SelectionMode with
| VisualBlockMode, SelectionMode.Normal -> dispatch TextEditorCommands.ToggleBlockSelectionMode
Expand Down Expand Up @@ -871,6 +873,9 @@ module Vim =
performActions t { newState with keys = [] } true

let newState, handled = performActions action newState false
match newState.statusMessage with
| Some m -> IdeApp.Workbench.StatusBar.ShowMessage m
| _ -> IdeApp.Workbench.StatusBar.ShowReady()
{ newState with lastAction = action }, handled

type XSVim() =
Expand All @@ -882,7 +887,7 @@ type XSVim() =

override x.Initialize() =
if not (editorStates.ContainsKey x.FileName) then
editorStates.Add(x.FileName, { keys=[]; mode=NormalMode; visualStartOffset=0; findCharCommand=None; lastAction=[]; desiredColumn=None; undoGroup=None })
editorStates.Add(x.FileName, Vim.defaultState )
EditActions.SwitchCaretMode x.Editor
disposable <- Some (IdeApp.Workbench.DocumentClosed.Subscribe
(fun e -> let documentName = e.Document.Name
Expand Down

0 comments on commit 2f36130

Please sign in to comment.