diff --git a/XSVim/Addin.fs b/XSVim/Addin.fs index e448f47..d0e147e 100644 --- a/XSVim/Addin.fs +++ b/XSVim/Addin.fs @@ -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 = @@ -74,11 +73,11 @@ type XSVim() as this = KeyDescriptor.FromGtk(Enum.Parse(typeof, 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 = @@ -87,10 +86,10 @@ 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 @@ -98,7 +97,7 @@ type XSVim() as this = | 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 @@ -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 diff --git a/XSVim/Properties/AssemblyInfo.fs b/XSVim/Properties/AssemblyInfo.fs index 733c06e..d5ed864 100644 --- a/XSVim/Properties/AssemblyInfo.fs +++ b/XSVim/Properties/AssemblyInfo.fs @@ -5,7 +5,7 @@ open System.Runtime.CompilerServices [] module AddinVersion = [] - let version = "0.63.2" + let version = "0.63.3" [] // The assembly version has the format {Major}.{Minor}.{Build}.{Revision} diff --git a/XSVim/WindowManagement.fs b/XSVim/WindowManagement.fs index 671f87f..05e3584 100644 --- a/XSVim/WindowManagement.fs +++ b/XSVim/WindowManagement.fs @@ -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 diff --git a/XSVim/XSVim.fs b/XSVim/XSVim.fs index 8246d19..14f539f 100755 --- a/XSVim/XSVim.fs +++ b/XSVim/XSVim.fs @@ -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 @@ -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 -> @@ -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