Skip to content

Commit

Permalink
:q fixes #237
Browse files Browse the repository at this point in the history
  • Loading branch information
nosami committed Oct 30, 2018
1 parent f32a8db commit e552b5c
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 17 deletions.
18 changes: 7 additions & 11 deletions XSVim/Addin.fs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ open MonoDevelop.Ide
open MonoDevelop.Ide.Editor
open MonoDevelop.Ide.Editor.Extension
open MonoDevelop.Ide.FindInFiles
open MonoDevelop.Ide.Gui.Components
open Reflection

module Subscriptions =
Expand Down Expand Up @@ -74,11 +73,11 @@ type XSVim() as this =
KeyDescriptor.FromGtk(Enum.Parse(typeof<Gdk.Key>, c) :?> Gdk.Key, char c, Gdk.ModifierType.ControlMask)
|> this.KeyPress

member x.FileName = x.Editor.FileName.FullPath
let mutable fileName = FilePath.Empty

member x.State
with get() = Vim.editorStates.[x.FileName]
and set(value) = Vim.editorStates.[x.FileName] <- value
with get() = Vim.editorStates.[fileName]
and set(value) = Vim.editorStates.[fileName] <- value


override x.IsValidInContext documentContext =
Expand All @@ -87,18 +86,18 @@ type XSVim() as this =
override x.Initialize() =
treeViewPads.initialize()
x.Editor.FocusLost.Add(fun _ -> initializeSearchResultsPads())

LoggingService.LogDebug("XSVim initializing - " + string x.FileName)
fileName <- x.Editor.FileName.FullPath
LoggingService.LogDebug("XSVim initializing - " + string fileName)
initConfig()
if not (Vim.editorStates.ContainsKey x.FileName) then
if not (Vim.editorStates.ContainsKey fileName) then
let editor = x.Editor
let state =
match Vim.getCaretMode editor with
| Insert -> { VimState.Default with mode = InsertMode }
| Block -> VimState.Default

let initialState = Vim.switchToNormalMode editor state
Vim.editorStates.Add(x.FileName, initialState)
Vim.editorStates.Add(fileName, initialState)
editor.GrabFocus()
let caretChanged =
editor.CaretPositionChanged.Subscribe
Expand Down Expand Up @@ -147,9 +146,6 @@ type XSVim() as this =
x.Editor.ClearSelection()
false
| ModifierKeys.Command when descriptor.KeyChar <> 'z' && descriptor.KeyChar <> 'r' -> false
| _ when isNull x.Editor ->
// Seems like we can get into this state when closing a tab
false
| _ ->
let oldState = x.State

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.63.2"
let version = "0.63.3"

[<assembly: AssemblyTitle("XSVim")>]
// The assembly version has the format {Major}.{Minor}.{Build}.{Revision}
Expand Down
5 changes: 3 additions & 2 deletions XSVim/WindowManagement.fs
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,12 @@ module Window =
switchToNotebook notebooks.[1]

let closeTab() =
match tryActiveInactiveNoteBooks() with
let n = tryActiveInactiveNoteBooks()
match n with
| Some active, Some inactive when active.tabs.Length = 1 ->
dispatch FileCommands.CloseFile
switchToNotebook inactive
| Some active, _ when active.tabs.Length > 1 ->
| Some active, _ when active.activeTab > 0 ->
dispatch FileCommands.CloseFile
openDocument active.tabs.[active.activeTab-1]
| _ -> dispatch FileCommands.CloseFile
Expand Down
13 changes: 10 additions & 3 deletions XSVim/XSVim.fs
Original file line number Diff line number Diff line change
Expand Up @@ -856,7 +856,12 @@ module Vim =
if editor.SelectionMode = SelectionMode.Normal then EditActions.ToggleBlockSelectionMode editor
switchToInsertMode editor vimState isInitial

let start, finish = VimHelpers.getRange vimState editor command
let start, finish =
if editor.Length > 0 then
VimHelpers.getRange vimState editor command
else
// editor can have zero length when a tab containing it has just been closed
0, 0

let newState =
match command.commandType with
Expand Down Expand Up @@ -1702,7 +1707,8 @@ module Vim =
| SpecialKey.Delete -> VimKey.Delete
| _ -> Key keyPress.KeyChar

let handleKeyPress state (keyPress:KeyDescriptor) editor config =
let handleKeyPress state (keyPress:KeyDescriptor) (editor:TextEditor) config =
let fileName = editor.FileName
let vimKey =
match state.mode, keyPress.KeyChar, config.insertModeEscapeKey with
| InsertMode, c, Some combo when (string c) = combo.insertModeEscapeKey1 ->
Expand Down Expand Up @@ -1769,5 +1775,6 @@ module Vim =
| NotInsertMode, Key 'O', _
| NotInsertMode, Key 'A', _ -> { newState with lastAction = action }
| _ -> newState
editorStates.[editor.FileName] <- newState

editorStates.[fileName] <- newState
newState, handled

0 comments on commit e552b5c

Please sign in to comment.