Skip to content

Commit

Permalink
Fix for 2272 - <f12> opens in current tab (onivim#2504)
Browse files Browse the repository at this point in the history
  • Loading branch information
psxpaul authored and akinsho committed Aug 19, 2018
1 parent 127a2bc commit dd4b33d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 18 deletions.
20 changes: 4 additions & 16 deletions browser/src/Editor/NeovimEditor/Definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export enum OpenType {
export class Definition {
constructor(private _editor: Oni.Editor, private _store: Store<State.IState>) {}

public async gotoDefinitionUnderCursor(openType: OpenType = OpenType.NewTab): Promise<void> {
public async gotoDefinitionUnderCursor(openOptions?: Oni.FileOpenOptions): Promise<void> {
const activeDefinition = this._store.getState().definition

if (!activeDefinition) {
Expand All @@ -31,33 +31,21 @@ export class Definition {
const line = range.start.line
const column = range.start.character

await this.gotoPositionInUri(uri, line, column, openType)
await this.gotoPositionInUri(uri, line, column, openOptions)
}

public async gotoPositionInUri(
uri: string,
line: number,
column: number,
openType: OpenType = OpenType.NewTab,
openOptions?: Oni.FileOpenOptions,
): Promise<void> {
const filePath = Helpers.unwrapFileUriPath(uri)

const activeEditor = this._editor
const command = this._getCommandFromOpenType(openType)

await activeEditor.neovim.command(`${command} ${filePath}`)
await this._editor.openFile(filePath, openOptions)
await activeEditor.neovim.command(`cal cursor(${line + 1}, ${column + 1})`)
await activeEditor.neovim.command("norm zz")
}

private _getCommandFromOpenType(openType: OpenType) {
switch (openType) {
case OpenType.SplitVertical:
return "vsp"
case OpenType.SplitHorizontal:
return "sp"
default:
return "e"
}
}
}
19 changes: 17 additions & 2 deletions browser/src/Editor/NeovimEditor/NeovimEditorCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,25 @@ export class NeovimEditorCommands {
() => this._definition.gotoDefinitionUnderCursor(),
),
new CallbackCommand("language.gotoDefinition.openVertical", null, null, () =>
this._definition.gotoDefinitionUnderCursor(1),
this._definition.gotoDefinitionUnderCursor({
openMode: Oni.FileOpenMode.VerticalSplit,
}),
),
new CallbackCommand("language.gotoDefinition.openHorizontal", null, null, () =>
this._definition.gotoDefinitionUnderCursor(2),
this._definition.gotoDefinitionUnderCursor({
openMode: Oni.FileOpenMode.HorizontalSplit,
}),
),
new CallbackCommand("language.gotoDefinition.openNewTab", null, null, () =>
this._definition.gotoDefinitionUnderCursor({ openMode: Oni.FileOpenMode.NewTab }),
),
new CallbackCommand("language.gotoDefinition.openEdit", null, null, () =>
this._definition.gotoDefinitionUnderCursor({ openMode: Oni.FileOpenMode.Edit }),
),
new CallbackCommand("language.gotoDefinition.openExistingTab", null, null, () =>
this._definition.gotoDefinitionUnderCursor({
openMode: Oni.FileOpenMode.ExistingTab,
}),
),

new CallbackCommand("editor.rename", "Rename", "Rename an item", () =>
Expand Down

0 comments on commit dd4b33d

Please sign in to comment.