Skip to content

Commit

Permalink
Force close tabs and add ZZ
Browse files Browse the repository at this point in the history
  • Loading branch information
nosami committed Nov 16, 2018
1 parent e552b5c commit 2beb18b
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 12 deletions.
1 change: 1 addition & 0 deletions XSVim/Addin.fs
Original file line number Diff line number Diff line change
Expand Up @@ -215,5 +215,6 @@ type XSVim() as this =
member x.Escape() = ctrl "c"

override x.Dispose() =
Vim.editorStates.Remove(fileName) |> ignore;
base.Dispose()
disposables |> List.iter(fun d -> d.Dispose())
7 changes: 2 additions & 5 deletions XSVim/ExMode.fs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ module exMode =
| _ -> wait

let save() = IdeApp.Workbench.ActiveDocument.Save() |> Async.AwaitTask
let forceClose() = IdeApp.Workbench.ActiveDocument.Window.CloseWindow true |> Async.AwaitTask |> Async.Ignore

let (|DeleteBetweenMarks|_|) input =
let matches = Regex.Matches(input, "'([a-z]),'([a-z])d", RegexOptions.Compiled)
Expand Down Expand Up @@ -84,9 +83,7 @@ module exMode =
Window.closeTab()
normalMode, resetKeys
| "q!" ->
async {
do! forceClose()
} |> Async.StartImmediate
Window.forceCloseTab()
normalMode, resetKeys
| "w"
| "w!" ->
Expand Down Expand Up @@ -121,7 +118,7 @@ module exMode =
| "wq!" ->
async {
do! save()
do! forceClose()
Window.forceCloseTab()
} |> Async.StartImmediate
normalMode, resetKeys
| "vs"
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.3"
let version = "0.64.0"

[<assembly: AssemblyTitle("XSVim")>]
// The assembly version has the format {Major}.{Minor}.{Build}.{Revision}
Expand Down
24 changes: 18 additions & 6 deletions XSVim/WindowManagement.fs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ module Window =
let switchToNotebook notebook =
openDocument notebook.tabs.[notebook.activeTab]

let forceClose() = IdeApp.Workbench.ActiveDocument.Window.CloseWindow true |> Async.AwaitTask |> Async.Ignore

let getNotebooks() =
let (dockNotebookContainer: obj seq) = IdeApp.Workbench?RootWindow?TabControl?Container?GetNotebooks()
let getFiles notebook =
Expand Down Expand Up @@ -84,16 +86,26 @@ module Window =
if notebooks.Length = 2 && notebooks.[0].isActive then
switchToNotebook notebooks.[1]

let closeTab() =
let n = tryActiveInactiveNoteBooks()
match n with
let private closeTabWithForce force =
let closeFunc() =
match force with
| true -> forceClose() |> Async.RunSynchronously
| false -> dispatch FileCommands.CloseFile

match tryActiveInactiveNoteBooks() with
| Some active, Some inactive when active.tabs.Length = 1 ->
dispatch FileCommands.CloseFile
closeFunc()
switchToNotebook inactive
| Some active, _ when active.activeTab > 0 ->
dispatch FileCommands.CloseFile
closeFunc()
openDocument active.tabs.[active.activeTab-1]
| _ -> dispatch FileCommands.CloseFile
| Some active, _ when active.activeTab = 0 && active.tabs.Length > 1 ->
closeFunc()
openDocument active.tabs.[1]
| _ -> closeFunc()

let closeTab() = closeTabWithForce false
let forceCloseTab() = closeTabWithForce true

let gotoPad padId =
IdeApp.Workbench.Pads
Expand Down
2 changes: 2 additions & 0 deletions XSVim/XSVim.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1633,6 +1633,8 @@ module Vim =
| VisualModes, [ ">" ] -> [ run (EditorFunc EditActions.IndentSelection) Nothing; switchMode NormalMode ]
| VisualModes, [ "<" ] -> [ run (EditorFunc EditActions.UnIndentSelection) Nothing; switchMode NormalMode ]
| VisualModes, [ "=" ] -> [ run EqualIndent SelectedText; switchMode NormalMode ]
| NotInsertMode, [ "Z" ] -> wait
| NotInsertMode, [ "Z"; "Z" ] -> [ func Window.closeTab ]
| NotInsertMode, [ "<C-p>" ] -> [ dispatch SearchCommands.GotoFile ]
| NotInsertMode, [ "<C-w>" ] -> wait
| NotInsertMode, [ "<C-w>"; "w" ]
Expand Down

0 comments on commit 2beb18b

Please sign in to comment.