Skip to content

Commit

Permalink
Merge branch 'main' into meogge/accessibleWidget
Browse files Browse the repository at this point in the history
  • Loading branch information
meganrogge committed Apr 7, 2023
2 parents 64f7de0 + e2614f0 commit 17dda54
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { overviewRulerRangeHighlight } from 'vs/editor/common/core/editorColorRe
import { IQuickAccessProvider } from 'vs/platform/quickinput/common/quickAccess';
import { IKeyMods, IQuickPick, IQuickPickItem } from 'vs/platform/quickinput/common/quickInput';
import { themeColorFromId } from 'vs/platform/theme/common/themeService';
import { alert } from 'vs/base/browser/ui/aria/aria';

interface IEditorLineDecoration {
rangeHighlightId: string;
Expand Down Expand Up @@ -146,6 +147,10 @@ export abstract class AbstractEditorNavigationQuickAccessProvider implements IQu
if (!options.preserveFocus) {
editor.focus();
}
const model = editor.getModel();
if (model && 'getLineContent' in model) {
alert(`${model.getLineContent(options.range.startLineNumber)}`);
}
}

protected getModel(editor: IEditor | IDiffEditor): ITextModel | undefined {
Expand Down
2 changes: 2 additions & 0 deletions src/vs/workbench/contrib/terminal/common/terminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,8 @@ export const enum TerminalCommandId {
RunRecentCommand = 'workbench.action.terminal.runRecentCommand',
FocusAccessibleBuffer = 'workbench.action.terminal.focusAccessibleBuffer',
NavigateAccessibleBuffer = 'workbench.action.terminal.navigateAccessibleBuffer',
AccessibleBufferGoToNextCommand = 'workbench.action.terminal.accessibleBufferGoToNextCommand',
AccessibleBufferGoToPreviousCommand = 'workbench.action.terminal.accessibleBufferGoToPreviousCommand',
CopyLastCommandOutput = 'workbench.action.terminal.copyLastCommandOutput',
GoToRecentDirectory = 'workbench.action.terminal.goToRecentDirectory',
CopyAndClearSelection = 'workbench.action.terminal.copyAndClearSelection',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,10 @@ import { registerTerminalContribution } from 'vs/workbench/contrib/terminal/brow
import { TerminalWidgetManager } from 'vs/workbench/contrib/terminal/browser/widgets/widgetManager';
import { ITerminalProcessManager, TerminalCommandId } from 'vs/workbench/contrib/terminal/common/terminal';
import { TerminalContextKeys } from 'vs/workbench/contrib/terminal/common/terminalContextKey';
import { terminalStrings } from 'vs/workbench/contrib/terminal/common/terminalStrings';
import { AccessibilityHelpWidget } from 'vs/workbench/contrib/terminalContrib/accessibility/browser/terminalAccessibilityHelp';
import { AccessibleBufferWidget } from 'vs/workbench/contrib/terminalContrib/accessibility/browser/terminalAccessibleBuffer';
import { AccessibleBufferWidget, NavigationType } from 'vs/workbench/contrib/terminalContrib/accessibility/browser/terminalAccessibleBuffer';
import { Terminal } from 'xterm';

const category = terminalStrings.actionCategory;

class AccessibleBufferContribution extends DisposableStore implements ITerminalContribution {
static readonly ID: 'terminal.accessible-buffer';
static get(instance: ITerminalInstance): AccessibleBufferContribution | null {
Expand Down Expand Up @@ -53,6 +50,10 @@ class AccessibleBufferContribution extends DisposableStore implements ITerminalC
async createCommandQuickPick(): Promise<IQuickPick<IQuickPickItem> | undefined> {
return this._accessibleBufferWidget?.createQuickPick();
}

navigateToCommand(type: NavigationType): void {
return this._accessibleBufferWidget?.navigateToCommand(type);
}
}
registerTerminalContribution(AccessibleBufferContribution.ID, AccessibleBufferContribution);

Expand Down Expand Up @@ -83,8 +84,6 @@ registerTerminalAction({
registerTerminalAction({
id: TerminalCommandId.FocusAccessibleBuffer,
title: { value: localize('workbench.action.terminal.focusAccessibleBuffer', 'Focus Accessible Buffer'), original: 'Focus Accessible Buffer' },
f1: true,
category,
precondition: ContextKeyExpr.or(TerminalContextKeys.processSupported, TerminalContextKeys.terminalHasBeenCreated),
keybinding: [
{
Expand All @@ -106,8 +105,6 @@ registerTerminalAction({
registerTerminalAction({
id: TerminalCommandId.NavigateAccessibleBuffer,
title: { value: localize('workbench.action.terminal.navigateAccessibleBuffer', 'Navigate Accessible Buffer'), original: 'Navigate Accessible Buffer' },
f1: true,
category,
precondition: ContextKeyExpr.or(TerminalContextKeys.processSupported, TerminalContextKeys.terminalHasBeenCreated),
keybinding: [
{
Expand All @@ -126,3 +123,46 @@ registerTerminalAction({
quickPick?.show();
}
});

registerTerminalAction({
id: TerminalCommandId.AccessibleBufferGoToNextCommand,
title: { value: localize('workbench.action.terminal.accessibleBufferGoToNextCommand', 'Accessible Buffer Go to Next Command'), original: 'Accessible Buffer Go to Next Command' },
precondition: ContextKeyExpr.or(TerminalContextKeys.processSupported, TerminalContextKeys.terminalHasBeenCreated, TerminalContextKeys.accessibleBufferFocus),
keybinding: [
{
primary: KeyMod.CtrlCmd | KeyCode.DownArrow,
weight: KeybindingWeight.WorkbenchContrib + 2,
when: TerminalContextKeys.accessibleBufferFocus
}
],
run: async (c) => {
const instance = await c.service.getActiveOrCreateInstance();
await revealActiveTerminal(instance, c);
if (!instance) {
return;
}
await AccessibleBufferContribution.get(instance)?.navigateToCommand(NavigationType.Next);
}
});


registerTerminalAction({
id: TerminalCommandId.AccessibleBufferGoToPreviousCommand,
title: { value: localize('workbench.action.terminal.accessibleBufferGoToPreviousCommand', 'Accessible Buffer Go to Previous Command'), original: 'Accessible Buffer Go to Previous Command' },
precondition: ContextKeyExpr.and(ContextKeyExpr.or(TerminalContextKeys.processSupported, TerminalContextKeys.terminalHasBeenCreated), TerminalContextKeys.accessibleBufferFocus),
keybinding: [
{
primary: KeyMod.CtrlCmd | KeyCode.UpArrow,
weight: KeybindingWeight.WorkbenchContrib + 2,
when: TerminalContextKeys.accessibleBufferFocus
}
],
run: async (c) => {
const instance = await c.service.getActiveOrCreateInstance();
await revealActiveTerminal(instance, c);
if (!instance) {
return;
}
await AccessibleBufferContribution.get(instance)?.navigateToCommand(NavigationType.Previous);
}
});
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { IConfigurationService } from 'vs/platform/configuration/common/configur
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { ITerminalInstance, ITerminalService, IXtermTerminal } from 'vs/workbench/contrib/terminal/browser/terminal';
import type { Terminal } from 'xterm';
import { TerminalCapability } from 'vs/platform/terminal/common/capabilities/capabilities';
import { ITerminalCommand, TerminalCapability } from 'vs/platform/terminal/common/capabilities/capabilities';
import { IQuickInputService, IQuickPick, IQuickPickItem } from 'vs/platform/quickinput/common/quickInput';
import { AudioCue, IAudioCueService } from 'vs/platform/audioCues/browser/audioCueService';
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
Expand All @@ -22,6 +22,11 @@ import { IEditorViewState } from 'vs/editor/common/editorCommon';
import { TerminalAccessibleWidget } from 'vs/workbench/contrib/terminalContrib/accessibility/browser/terminalAccessibleWidget';
import { TerminalContextKeys } from 'vs/workbench/contrib/terminal/common/terminalContextKey';

export const enum NavigationType {
Next = 'next',
Previous = 'previous'
}

interface IAccessibleBufferQuickPickItem extends IQuickPickItem {
lineNumber: number;
exitCode?: number;
Expand Down Expand Up @@ -70,33 +75,75 @@ export class AccessibleBufferWidget extends TerminalAccessibleWidget {
}));
}

async createQuickPick(): Promise<IQuickPick<IAccessibleBufferQuickPickItem> | undefined> {
this._cursorPosition = withNullAsUndefined(this.editorWidget.getPosition());
navigateToCommand(type: NavigationType): void {
const currentLine = this.editorWidget.getPosition()?.lineNumber || this._getDefaultCursorPosition()?.lineNumber;
const commands = this._getCommandsWithEditorLine();
if (!commands?.length || !currentLine) {
return;
}

const filteredCommands = type === NavigationType.Previous ? commands.filter(c => c.lineNumber < currentLine).sort((a, b) => b.lineNumber - a.lineNumber) : commands.filter(c => c.lineNumber > currentLine).sort((a, b) => a.lineNumber - b.lineNumber);
if (!filteredCommands.length) {
return;
}
this._cursorPosition = { lineNumber: filteredCommands[0].lineNumber, column: 1 };
this._resetPosition();
}

private _getEditorLineForCommand(command: ITerminalCommand): number | undefined {
let line = command.marker?.line;
if (line === undefined || !command.command.length || line < 0) {
return;
}
line = this._bufferTracker.bufferToEditorLineMapping.get(line);
if (!line) {
return;
}
return line + 1;
}

private _getCommandsWithEditorLine(): ICommandWithEditorLine[] | undefined {
const commands = this._instance.capabilities.get(TerminalCapability.CommandDetection)?.commands;
if (!commands?.length) {
return;
}
const quickPickItems: IAccessibleBufferQuickPickItem[] = [];
const result: ICommandWithEditorLine[] = [];
for (const command of commands) {
let line = command.marker?.line;
if (line === undefined || !command.command.length || line < 0) {
const lineNumber = this._getEditorLineForCommand(command);
if (!lineNumber) {
continue;
}
line = this._bufferTracker.bufferToEditorLineMapping.get(line);
result.push({ command, lineNumber });
}
return result;
}

async createQuickPick(): Promise<IQuickPick<IAccessibleBufferQuickPickItem> | undefined> {
this._cursorPosition = withNullAsUndefined(this.editorWidget.getPosition());
const commands = this._getCommandsWithEditorLine();
if (!commands) {
return;
}
const quickPickItems: IAccessibleBufferQuickPickItem[] = [];
for (const { command, lineNumber } of commands) {
const line = this._getEditorLineForCommand(command);
if (!line) {
continue;
}
quickPickItems.push(
{
label: localize('terminal.integrated.symbolQuickPick.labelNoExitCode', '{0}', command.command),
lineNumber: line + 1,
lineNumber,
exitCode: command.exitCode
});
}
const quickPick = this._quickInputService.createQuickPick<IAccessibleBufferQuickPickItem>();
quickPick.canSelectMany = false;
quickPick.onDidChangeActive(() => {
const activeItem = quickPick.activeItems[0];
if (!activeItem) {
return;
}
if (activeItem.exitCode) {
this._audioCueService.playAudioCue(AudioCue.error, true);
}
Expand Down Expand Up @@ -211,3 +258,6 @@ export class AccessibleBufferWidget extends TerminalAccessibleWidget {
return model!;
}
}

interface ICommandWithEditorLine { command: ITerminalCommand; lineNumber: number }

This file was deleted.

0 comments on commit 17dda54

Please sign in to comment.