Skip to content
This repository has been archived by the owner on Apr 1, 2020. It is now read-only.

Closing splits with 'editor.splits.mode' === 'oni' #1703

Merged
merged 32 commits into from
Mar 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
05916d9
Add split bindings
bryphe Mar 1, 2018
9df5af6
Get tests green again
bryphe Mar 1, 2018
d3c44c2
Get split tests green
bryphe Mar 1, 2018
c8356d9
Add layout logic plus testc ases
bryphe Mar 1, 2018
a41e8f7
Fix lint issues
bryphe Mar 1, 2018
40ad37a
Get oni-splits working end-to-end
bryphe Mar 1, 2018
1d27104
Tweak positioning of splits
bryphe Mar 1, 2018
e45fff1
Add basic window layout algorithm
bryphe Mar 1, 2018
9298188
Fix lint issue
bryphe Mar 1, 2018
c94505a
Fix test issues
bryphe Mar 1, 2018
a5d3ab4
Fix window click behavior
bryphe Mar 1, 2018
0cd19eb
Merge branch 'master' into bryphe/feature/window-splits-integration
bryphe Mar 1, 2018
61997b3
Merge branch 'master' into bryphe/feature/window-splits-integration
bryphe Mar 2, 2018
9cd39a9
Fix compilation issue
bryphe Mar 2, 2018
c60b645
Merge branch 'master' into bryphe/feature/window-splits-integration
bryphe Mar 2, 2018
e63dfcb
Merge branch 'master' into bryphe/feature/window-splits-integration
bryphe Mar 2, 2018
d2d7958
Merge branch 'master' into bryphe/feature/window-splits-integration
bryphe Mar 2, 2018
658e770
Fix split direction issue
bryphe Mar 2, 2018
4658ae5
Merge branch 'master' into bryphe/feature/window-splits-integration
bryphe Mar 2, 2018
d1fe572
Fix lint issue
bryphe Mar 3, 2018
0cefa20
Hook up <C-w>s/<C-w>v bindings for oni.tabs.mode
bryphe Mar 3, 2018
1a85344
Fall back to native splits if editor.split.mode isn't set to oni
bryphe Mar 3, 2018
2bfac82
Merge branch 'master' into bryphe/feature/window-splits-integration
bryphe Mar 3, 2018
88f8b0b
Remove todo
bryphe Mar 3, 2018
b32d8ae
Fix class name for editor
bryphe Mar 3, 2018
25d8d5a
Merge branch 'bryphe/feature/window-splits-integration' into bryphe/f…
bryphe Mar 3, 2018
fbe3e62
Handle closing instances in splits
bryphe Mar 3, 2018
0cd28b4
Merge branch 'master' into bryphe/feature/oni-splits-close-window
bryphe Mar 7, 2018
7631384
Merge branch 'master' into bryphe/feature/oni-splits-close-window
bryphe Mar 13, 2018
0383172
Rewire quit command to close window
bryphe Mar 13, 2018
451a1ce
Revise close logic
bryphe Mar 13, 2018
e40ca1a
Add dispose to NeovimInstance and Session objects
bryphe Mar 13, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions browser/src/Editor/NeovimEditor/NeovimEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { bindActionCreators, Store } from "redux"
import { clipboard, ipcRenderer, remote } from "electron"

import * as Oni from "oni-api"
import { Event } from "oni-types"
import { Event, IEvent } from "oni-types"

import * as Log from "./../../Log"

Expand All @@ -42,7 +42,6 @@ import { commandManager } from "./../../Services/CommandManager"
import { Completion, CompletionProviders } from "./../../Services/Completion"
import { Configuration, IConfigurationValues } from "./../../Services/Configuration"
import { IDiagnosticsDataSource } from "./../../Services/Diagnostics"
import { editorManager } from "./../../Services/EditorManager"
import { Errors } from "./../../Services/Errors"
import { Overlay, OverlayManager } from "./../../Services/Overlay"
import { SnippetManager } from "./../../Services/Snippets"
Expand Down Expand Up @@ -140,9 +139,14 @@ export class NeovimEditor extends Editor implements IEditor {
private _toolTipsProvider: IToolTipsProvider
private _commands: NeovimEditorCommands
private _externalMenuOverlay: Overlay

private _bufferLayerManager: BufferLayerManager

private _onNeovimQuit: Event<void> = new Event<void>()

public get onNeovimQuit(): IEvent<void> {
return this._onNeovimQuit
}

public get /* override */ activeBuffer(): Oni.Buffer {
return this._bufferManager.getBufferById(this._lastBufferId)
}
Expand Down Expand Up @@ -375,10 +379,7 @@ export class NeovimEditor extends Editor implements IEditor {
})

this._neovimInstance.onLeave.subscribe(() => {
// TODO: Only leave if all editors are closed...
if (!this._configuration.getValue("debug.persistOnNeovimExit")) {
remote.getCurrentWindow().close()
}
this._onNeovimQuit.dispatch()
})

this._neovimInstance.onOniCommand.subscribe(command => {
Expand Down Expand Up @@ -664,6 +665,11 @@ export class NeovimEditor extends Editor implements IEditor {
}

public dispose(): void {
if (this._neovimInstance) {
this._neovimInstance.dispose()
this._neovimInstance = null
}

if (this._syntaxHighlighter) {
this._syntaxHighlighter.dispose()
this._syntaxHighlighter = null
Expand All @@ -688,7 +694,6 @@ export class NeovimEditor extends Editor implements IEditor {
}

public enter(): void {
editorManager.setActiveEditor(this)
Log.info("[NeovimEditor::enter]")
this._onEnterEvent.dispatch()
this._actions.setHasFocus(true)
Expand Down
18 changes: 18 additions & 0 deletions browser/src/Editor/OniEditor/OniEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import * as types from "vscode-languageserver-types"
import * as Oni from "oni-api"
import { IEvent } from "oni-types"

import { remote } from "electron"

import * as Log from "./../../Log"

import { PluginManager } from "./../../Plugins/PluginManager"
Expand Down Expand Up @@ -137,6 +139,22 @@ export class OniEditor implements IEditor {
this._workspace,
)

editorManager.registerEditor(this)

this._neovimEditor.onNeovimQuit.subscribe(() => {
const isSplitModeOni = this._configuration.getValue("editor.split.mode") === "oni"

if (!this._configuration.getValue("debug.persistOnNeovimExit") && !isSplitModeOni) {
remote.getCurrentWindow().close()
} else if (isSplitModeOni) {
const handle = windowManager.getSplitHandle(this)
handle.close()
editorManager.unregisterEditor(this)

this.dispose()
}
})

this._neovimEditor.bufferLayers.addBufferLayer("*", buf =>
wrapReactComponentWithLayer("oni.layer.scrollbar", <BufferScrollBarContainer />),
)
Expand Down
20 changes: 19 additions & 1 deletion browser/src/Services/EditorManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,16 @@
import * as Oni from "oni-api"
import { Event, IDisposable, IEvent } from "oni-types"

import { remote } from "electron"

export class EditorManager implements Oni.EditorManager {
private _allEditors: Oni.Editor[] = []
private _activeEditor: Oni.Editor = null
private _anyEditorProxy: AnyEditorProxy = new AnyEditorProxy()
private _onActiveEditorChanged: Event<Oni.Editor> = new Event<Oni.Editor>()

public get allEditors(): Oni.Editor[] {
return []
return this._allEditors
}

/**
Expand All @@ -42,6 +45,21 @@ export class EditorManager implements Oni.EditorManager {
return this._activeEditor.openFile(filePath, openOptions)
}

public registerEditor(editor: Oni.Editor) {
if (this._allEditors.indexOf(editor) === -1) {
this._allEditors.push(editor)
}
}

public unregisterEditor(editor: Oni.Editor): void {
this._allEditors = this._allEditors.filter(ed => ed !== editor)

if (this._allEditors.length === 0) {
// Quit?
remote.getCurrentWindow().close()
}
}

/**
* Internal Methods
*/
Expand Down
13 changes: 13 additions & 0 deletions browser/src/neovim/NeovimInstance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ export interface INeovimInstance {
*/
export class NeovimInstance extends EventEmitter implements INeovimInstance {
private _neovim: Session
private _isDisposed: boolean = false
private _initPromise: Promise<void>
private _isLeaving: boolean
private _currentVimDirectory: string
Expand Down Expand Up @@ -368,6 +369,13 @@ export class NeovimInstance extends EventEmitter implements INeovimInstance {
})
}

public dispose(): void {
if (this._neovim) {
this._neovim.dispose()
this._neovim = null
}
}

public async chdir(directoryPath: string): Promise<void> {
await this.command(`cd! ${directoryPath}`)
}
Expand Down Expand Up @@ -662,6 +670,11 @@ export class NeovimInstance extends EventEmitter implements INeovimInstance {
}

private _handleNotification(_method: any, args: any): void {
if (this._isDisposed) {
Log.warn(`[NeovimInstance] - ignoring ${_method} because disposed`)
return
}

args.forEach((a: any[]) => {
const command = a[0]
a = a.slice(1)
Expand Down
19 changes: 19 additions & 0 deletions browser/src/neovim/Session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const log = (msg: string) => {
* Session is responsible for the Neovim msgpack session
*/
export class Session extends EventEmitter {
private _isDisposed: boolean = false
private _encoder: msgpackLite.EncodeStream
private _decoder: msgpackLite.DecodeStream
private _requestId: number = 0
Expand Down Expand Up @@ -80,7 +81,25 @@ export class Session extends EventEmitter {
})
}

public dispose(): void {
if (this._encoder) {
this._encoder.destroy()
this._encoder = null
}

if (this._decoder) {
this._decoder.destroy()
this._decoder = null
}

this._isDisposed = true
}

public request<T>(methodName: string, args: any): Promise<T> {
if (this._isDisposed) {
Log.warn(`[Session] Ignoring request: ${methodName} because session is disposed.`)
}

this._requestId++
let r = null
const promise = new Promise<T>(resolve => {
Expand Down