-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #368 from rebornix/Tabs
Tabs
- Loading branch information
Showing
4 changed files
with
195 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
"use strict"; | ||
|
||
import * as vscode from "vscode"; | ||
import * as node from "../node"; | ||
|
||
export enum Tab { | ||
Next, | ||
Previous, | ||
First, | ||
Last, | ||
New, | ||
Close, | ||
Only | ||
} | ||
|
||
export interface ITabCommandArguments extends node.ICommandArgs { | ||
tab: Tab; | ||
count?: number; | ||
} | ||
|
||
// | ||
// Implements tab | ||
// http://vimdoc.sourceforge.net/htmldoc/tabpage.html | ||
// | ||
export class TabCommand extends node.CommandBase { | ||
protected _arguments : ITabCommandArguments; | ||
|
||
constructor(args : ITabCommandArguments) { | ||
super(); | ||
this._name = 'tab'; | ||
this._shortName = 'tab'; | ||
this._arguments = args; | ||
} | ||
|
||
get arguments() : ITabCommandArguments { | ||
return this._arguments; | ||
} | ||
|
||
private executeCommandWithCount(count: number, command: string) { | ||
if (!count) { | ||
count = 1; | ||
} | ||
|
||
for (let i = 0; i < count; i++) { | ||
vscode.commands.executeCommand(command); | ||
} | ||
} | ||
|
||
execute() : void { | ||
switch (this._arguments.tab) { | ||
case Tab.Next: | ||
this.executeCommandWithCount(this._arguments.count, "workbench.action.nextEditor"); | ||
break; | ||
case Tab.Previous: | ||
this.executeCommandWithCount(this._arguments.count, "workbench.action.previousEditor"); | ||
break; | ||
case Tab.First: | ||
this.executeCommandWithCount(this._arguments.count, "workbench.action.openEditorAtIndex1"); | ||
break; | ||
case Tab.Last: | ||
this.executeCommandWithCount(this._arguments.count, "workbench.action.openLastEditorInGroup"); | ||
break; | ||
case Tab.New: | ||
this.executeCommandWithCount(this._arguments.count, "workbench.action.files.newUntitledFile"); | ||
break; | ||
case Tab.Close: | ||
this.executeCommandWithCount(this._arguments.count, "workbench.action.closeActiveEditor"); | ||
break; | ||
case Tab.Only: | ||
this.executeCommandWithCount(this._arguments.count, "workbench.action.closeOtherEditors"); | ||
break; | ||
|
||
default: | ||
break; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
"use strict"; | ||
|
||
import * as node from "../commands/tab"; | ||
import {Scanner} from '../scanner'; | ||
|
||
function parseCount(args: string): number { | ||
if (!args) { | ||
return 1; | ||
} | ||
|
||
let scanner = new Scanner(args); | ||
scanner.skipWhiteSpace(); | ||
|
||
if (scanner.isAtEof) { | ||
return 1; | ||
} | ||
|
||
let c = scanner.next(); | ||
let count = Number.parseInt(c); | ||
|
||
if (Number.isInteger(count) && count > 0 ) { | ||
if (count > 999) { | ||
count = 999; | ||
} | ||
|
||
return count; | ||
} else { | ||
throw new Error(`Invalid tab number: ${c}!`); | ||
} | ||
} | ||
|
||
export function parseTabNCommandArgs(args : string) : node.TabCommand { | ||
return new node.TabCommand({ | ||
tab: node.Tab.Next, | ||
count: parseCount(args) | ||
}); | ||
} | ||
|
||
export function parseTabPCommandArgs(args : string) : node.TabCommand { | ||
return new node.TabCommand({ | ||
tab: node.Tab.Previous, | ||
count: parseCount(args) | ||
}); | ||
} | ||
|
||
export function parseTabFirstCommandArgs(args : string) : node.TabCommand { | ||
return new node.TabCommand({ | ||
tab: node.Tab.First | ||
}); | ||
} | ||
|
||
export function parseTabLastCommandArgs(args : string) : node.TabCommand { | ||
return new node.TabCommand({ | ||
tab: node.Tab.Last | ||
}); | ||
} | ||
|
||
export function parseTabNewCommandArgs(args: string) : node.TabCommand { | ||
// New Tab command should support `count` | ||
// And the new created Tab's position depends on `count` | ||
// For now VS Code only allows open tab next to current Tab | ||
// So `count == 0` is not possible. But we can workaround this once we can move tabs through API. | ||
return new node.TabCommand({ | ||
tab: node.Tab.New | ||
}); | ||
} | ||
|
||
export function parseTabCloseCommandArgs(args: string) : node.TabCommand { | ||
return new node.TabCommand({ | ||
tab: node.Tab.Close | ||
}); | ||
} | ||
|
||
export function parseTabOnlyCommandArgs(args: string) : node.TabCommand { | ||
return new node.TabCommand({ | ||
tab: node.Tab.Only | ||
}); | ||
} |