mirror of
https://github.com/ckaczor/vscode-gitlens.git
synced 2026-02-16 10:58:34 -05:00
Exposes Keys
Adds keyboard logging
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
import { commands } from 'vscode';
|
import { commands } from 'vscode';
|
||||||
import { BuiltInCommands } from './constants';
|
import { BuiltInCommands } from './constants';
|
||||||
|
|
||||||
export { Keyboard } from './commands/keyboard';
|
export { Keyboard, Keys } from './commands/keyboard';
|
||||||
|
|
||||||
export { ActiveEditorCommand, Command, Commands, EditorCommand, openEditor } from './commands/commands';
|
export { ActiveEditorCommand, Command, Commands, EditorCommand, openEditor } from './commands/commands';
|
||||||
export { CloseUnchangedFilesCommand } from './commands/closeUnchangedFiles';
|
export { CloseUnchangedFilesCommand } from './commands/closeUnchangedFiles';
|
||||||
|
|||||||
@@ -2,10 +2,10 @@
|
|||||||
import { commands, Disposable, ExtensionContext, QuickPickItem } from 'vscode';
|
import { commands, Disposable, ExtensionContext, QuickPickItem } from 'vscode';
|
||||||
import { CommandContext, setCommandContext } from '../commands';
|
import { CommandContext, setCommandContext } from '../commands';
|
||||||
import { CommandQuickPickItem, OpenFileCommandQuickPickItem } from '../quickPicks/quickPicks';
|
import { CommandQuickPickItem, OpenFileCommandQuickPickItem } from '../quickPicks/quickPicks';
|
||||||
//import { Logger } from '../logger';
|
import { Logger } from '../logger';
|
||||||
|
|
||||||
declare type Keys = 'left' | 'right';
|
export declare type Keys = 'left' | 'right';
|
||||||
const keys: Keys[] = [
|
export const keys: Keys[] = [
|
||||||
'left',
|
'left',
|
||||||
'right'
|
'right'
|
||||||
];
|
];
|
||||||
@@ -40,19 +40,22 @@ export class Keyboard extends Disposable {
|
|||||||
this._disposable && this._disposable.dispose();
|
this._disposable && this._disposable.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
execute(key: Keys): any {
|
async execute(key: Keys): Promise<{}> {
|
||||||
const command = this.context.globalState.get(`gitlens:key:${key}`) as CommandQuickPickItem;
|
const command = this.context.globalState.get(`gitlens:key:${key}`) as CommandQuickPickItem;
|
||||||
if (!command || !(command instanceof CommandQuickPickItem)) return undefined;
|
if (!command || !(command instanceof CommandQuickPickItem)) return undefined;
|
||||||
|
|
||||||
|
Logger.log('Keyboard.execute', key);
|
||||||
|
|
||||||
if (command instanceof OpenFileCommandQuickPickItem) {
|
if (command instanceof OpenFileCommandQuickPickItem) {
|
||||||
// Have to open this pinned right now, because vscode doesn't have a way to open a unpinned, but unfocused editor
|
// Have to open this pinned right now, because vscode doesn't have a way to open a unpinned, but unfocused editor
|
||||||
return command.execute(true);
|
return await command.execute(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
return command.execute();
|
return await command.execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
async enterScope(...keyCommands: [Keys, QuickPickItem][]) {
|
async enterScope(...keyCommands: [Keys, QuickPickItem][]) {
|
||||||
|
Logger.log('Keyboard.enterScope', scopeCount);
|
||||||
await setCommandContext(CommandContext.Key, ++scopeCount);
|
await setCommandContext(CommandContext.Key, ++scopeCount);
|
||||||
if (keyCommands && Array.isArray(keyCommands) && keyCommands.length) {
|
if (keyCommands && Array.isArray(keyCommands) && keyCommands.length) {
|
||||||
for (const [key, command] of keyCommands) {
|
for (const [key, command] of keyCommands) {
|
||||||
@@ -62,6 +65,7 @@ export class Keyboard extends Disposable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async exitScope(clear: boolean = true) {
|
async exitScope(clear: boolean = true) {
|
||||||
|
Logger.log('Keyboard.exitScope', scopeCount);
|
||||||
await setCommandContext(CommandContext.Key, --scopeCount);
|
await setCommandContext(CommandContext.Key, --scopeCount);
|
||||||
if (clear && !scopeCount) {
|
if (clear && !scopeCount) {
|
||||||
for (const key of keys) {
|
for (const key of keys) {
|
||||||
@@ -71,10 +75,12 @@ export class Keyboard extends Disposable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async clearKeyCommand(key: Keys) {
|
async clearKeyCommand(key: Keys) {
|
||||||
|
Logger.log('Keyboard.clearKeyCommand', key);
|
||||||
await this.context.globalState.update(`gitlens:key:${key}`, undefined);
|
await this.context.globalState.update(`gitlens:key:${key}`, undefined);
|
||||||
}
|
}
|
||||||
|
|
||||||
async setKeyCommand(key: Keys, command: QuickPickItem) {
|
async setKeyCommand(key: Keys, command: QuickPickItem) {
|
||||||
|
Logger.log('Keyboard.setKeyCommand', key);
|
||||||
await this.context.globalState.update(`gitlens:key:${key}`, command);
|
await this.context.globalState.update(`gitlens:key:${key}`, command);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user