Skip to content

Commit

Permalink
Reduce usages of editorCommonExtensions in /common/ (#37834)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexdima committed Nov 9, 2017
1 parent b0e058e commit 3d1ccaa
Show file tree
Hide file tree
Showing 16 changed files with 81 additions and 77 deletions.
2 changes: 1 addition & 1 deletion src/vs/editor/browser/view/viewController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { IEditorMouseEvent } from 'vs/editor/browser/editorBrowser';
import { ICommandService } from 'vs/platform/commands/common/commands';
import { IViewModel } from 'vs/editor/common/viewModel/viewModel';
import { ViewOutgoingEvents } from 'vs/editor/browser/view/viewOutgoingEvents';
import { CoreNavigationCommands, CoreEditorCommand } from 'vs/editor/common/controller/coreCommands';
import { CoreNavigationCommands, CoreEditorCommand } from 'vs/editor/browser/controller/coreCommands';
import { Configuration } from 'vs/editor/browser/config/configuration';

export interface ExecCoreEditorCommandFunc {
Expand Down
2 changes: 1 addition & 1 deletion src/vs/editor/browser/widget/codeEditorWidget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { IKeyboardEvent } from 'vs/base/browser/keyboardEvent';
import { InternalEditorAction } from 'vs/editor/common/editorAction';
import { IEditorOptions } from 'vs/editor/common/config/editorOptions';
import { IPosition } from 'vs/editor/common/core/position';
import { CoreEditorCommand } from 'vs/editor/common/controller/coreCommands';
import { CoreEditorCommand } from 'vs/editor/browser/controller/coreCommands';
import { IThemeService, registerThemingParticipant } from 'vs/platform/theme/common/themeService';
import { editorErrorForeground, editorErrorBorder, editorWarningForeground, editorWarningBorder, editorInfoBorder, editorInfoForeground } from 'vs/editor/common/view/editorColorRegistry';
import { Color } from 'vs/base/common/color';
Expand Down
2 changes: 1 addition & 1 deletion src/vs/editor/contrib/find/test/findModel.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { ICommonCodeEditor } from 'vs/editor/common/editorCommon';
import { FindModelBoundToEditorModel } from 'vs/editor/contrib/find/findModel';
import { FindReplaceState } from 'vs/editor/contrib/find/findState';
import { withTestCodeEditor } from 'vs/editor/test/browser/testCodeEditor';
import { CoreNavigationCommands } from 'vs/editor/common/controller/coreCommands';
import { CoreNavigationCommands } from 'vs/editor/browser/controller/coreCommands';

suite('FindModel', () => {

Expand Down
2 changes: 1 addition & 1 deletion src/vs/editor/contrib/linesOperations/linesOperations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { CopyLinesCommand } from './copyLinesCommand';
import { DeleteLinesCommand } from './deleteLinesCommand';
import { MoveLinesCommand } from './moveLinesCommand';
import { TypeOperations } from 'vs/editor/common/controller/cursorTypeOperations';
import { CoreEditingCommands } from 'vs/editor/common/controller/coreCommands';
import { CoreEditingCommands } from 'vs/editor/browser/controller/coreCommands';

// copy lines

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { withTestCodeEditor } from 'vs/editor/test/browser/testCodeEditor';
import { DeleteAllLeftAction, JoinLinesAction, TransposeAction, UpperCaseAction, LowerCaseAction, DeleteAllRightAction, InsertLineBeforeAction, InsertLineAfterAction, IndentLinesAction } from 'vs/editor/contrib/linesOperations/linesOperations';
import { Cursor } from 'vs/editor/common/controller/cursor';
import { Model } from 'vs/editor/common/model/model';
import { CoreEditingCommands } from 'vs/editor/common/controller/coreCommands';
import { CoreEditingCommands } from 'vs/editor/browser/controller/coreCommands';

suite('Editor Contrib - Line Operations', () => {
suite('DeleteAllLeftAction', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/vs/editor/editor.all.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

'use strict';

import 'vs/editor/common/controller/coreCommands';
import 'vs/editor/browser/controller/coreCommands';
import 'vs/editor/browser/widget/codeEditorWidget';
import 'vs/editor/browser/widget/diffEditorWidget';
import 'vs/editor/browser/widget/diffNavigator';
Expand Down
2 changes: 1 addition & 1 deletion src/vs/editor/test/browser/controller/cursor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { TestConfiguration } from 'vs/editor/test/common/mocks/testConfiguration
import { MockMode } from 'vs/editor/test/common/mocks/mockMode';
import { LanguageIdentifier } from 'vs/editor/common/modes';
import { IEditorOptions } from 'vs/editor/common/config/editorOptions';
import { CoreNavigationCommands, CoreEditingCommands } from 'vs/editor/common/controller/coreCommands';
import { CoreNavigationCommands, CoreEditingCommands } from 'vs/editor/browser/controller/coreCommands';
import { withTestCodeEditor } from 'vs/editor/test/browser/testCodeEditor';
import { TextModel } from 'vs/editor/common/model/textModel';
import { ViewModel } from 'vs/editor/common/viewModel/viewModelImpl';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { TestConfiguration } from 'vs/editor/test/common/mocks/testConfiguration
import { CursorMove } from 'vs/editor/common/controller/cursorMoveCommands';
import { Range } from 'vs/editor/common/core/range';
import { Selection } from 'vs/editor/common/core/selection';
import { CoreNavigationCommands } from 'vs/editor/common/controller/coreCommands';
import { CoreNavigationCommands } from 'vs/editor/browser/controller/coreCommands';
import { ViewModel } from 'vs/editor/common/viewModel/viewModelImpl';

suite('Cursor move command test', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import { FloatingClickWidget } from 'vs/workbench/parts/preferences/browser/pref
import { IListService } from 'vs/platform/list/browser/listService';
import { IThemeService } from 'vs/platform/theme/common/themeService';
import { Position } from 'vs/editor/common/core/position';
import { CoreEditingCommands } from 'vs/editor/common/controller/coreCommands';
import { CoreEditingCommands } from 'vs/editor/browser/controller/coreCommands';
import { first } from 'vs/base/common/arrays';
import { IMarginData } from 'vs/editor/browser/controller/mouseTarget';

Expand Down
11 changes: 9 additions & 2 deletions src/vs/workbench/parts/preferences/browser/keybindingsEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import { KeyCode, ResolvedKeybinding } from 'vs/base/common/keyCodes';
import { attachListStyler } from 'vs/platform/theme/common/styler';
import { listHighlightForeground } from 'vs/platform/theme/common/colorRegistry';
import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService';
import { CommonEditorRegistry } from 'vs/editor/common/editorCommonExtensions';

let $ = DOM.$;

Expand Down Expand Up @@ -350,7 +351,13 @@ export class KeybindingsEditor extends BaseEditor implements IKeybindingsEditor
if (this.input) {
return this.input.resolve()
.then((keybindingsModel: KeybindingsEditorModel) => this.keybindingsEditorModel = keybindingsModel)
.then(() => this.keybindingsEditorModel.resolve())
.then(() => {
const editorActionsLabels: { [id: string]: string; } = CommonEditorRegistry.getEditorActions().reduce((editorActions, editorAction) => {
editorActions[editorAction.id] = editorAction.label;
return editorActions;
}, {});
return this.keybindingsEditorModel.resolve(editorActionsLabels);
})
.then(() => this.renderKeybindingsEntries(false));
}
return TPromise.as(null);
Expand Down Expand Up @@ -823,4 +830,4 @@ registerThemingParticipant((theme: ITheme, collector: ICssStyleCollector) => {
if (listHighlightForegroundColor) {
collector.addRule(`.keybindings-editor > .keybindings-body > .keybindings-list-container .monaco-list-row > .column .highlight { color: ${listHighlightForegroundColor}; }`);
}
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { IMatch, IFilter, or, matchesContiguousSubString, matchesPrefix, matches
import { Registry } from 'vs/platform/registry/common/platform';
import { ResolvedKeybinding, ResolvedKeybindingPart } from 'vs/base/common/keyCodes';
import { AriaLabelProvider, UserSettingsLabelProvider, UILabelProvider, ModifierLabels as ModLabels } from 'vs/base/common/keybindingLabels';
import { CommonEditorRegistry, EditorAction } from 'vs/editor/common/editorCommonExtensions';
import { MenuRegistry, ILocalizedString, ICommandAction } from 'vs/platform/actions/common/actions';
import { IWorkbenchActionRegistry, Extensions as ActionExtensions } from 'vs/workbench/common/actions';
import { EditorModel } from 'vs/workbench/common/editor';
Expand Down Expand Up @@ -144,28 +143,24 @@ export class KeybindingsEditorModel extends EditorModel {
return result;
}

public resolve(): TPromise<EditorModel> {
public resolve(editorActionsLabels: { [id: string]: string; }): TPromise<EditorModel> {
return this.extensionService.onReady()
.then(() => {
const workbenchActionsRegistry = Registry.as<IWorkbenchActionRegistry>(ActionExtensions.WorkbenchActions);
const editorActions = CommonEditorRegistry.getEditorActions().reduce((editorActions, editorAction) => {
editorActions[editorAction.id] = editorAction;
return editorActions;
}, {});

this._keybindingItemsSortedByPrecedence = [];
const boundCommands: Map<string, boolean> = new Map<string, boolean>();
for (const keybinding of this.keybindingsService.getKeybindings()) {
if (keybinding.command) { // Skip keybindings without commands
this._keybindingItemsSortedByPrecedence.push(KeybindingsEditorModel.toKeybindingEntry(keybinding.command, keybinding, workbenchActionsRegistry, editorActions));
this._keybindingItemsSortedByPrecedence.push(KeybindingsEditorModel.toKeybindingEntry(keybinding.command, keybinding, workbenchActionsRegistry, editorActionsLabels));
boundCommands.set(keybinding.command, true);
}
}

const commandsWithDefaultKeybindings = this.keybindingsService.getDefaultKeybindings().map(keybinding => keybinding.command);
for (const command of KeybindingResolver.getAllUnboundCommands(boundCommands)) {
const keybindingItem = new ResolvedKeybindingItem(null, command, null, null, commandsWithDefaultKeybindings.indexOf(command) === -1);
this._keybindingItemsSortedByPrecedence.push(KeybindingsEditorModel.toKeybindingEntry(command, keybindingItem, workbenchActionsRegistry, editorActions));
this._keybindingItemsSortedByPrecedence.push(KeybindingsEditorModel.toKeybindingEntry(command, keybindingItem, workbenchActionsRegistry, editorActionsLabels));
}
this._keybindingItems = this._keybindingItemsSortedByPrecedence.slice(0).sort((a, b) => KeybindingsEditorModel.compareKeybindingData(a, b));
return this;
Expand Down Expand Up @@ -200,14 +195,14 @@ export class KeybindingsEditorModel extends EditorModel {
return a.command.localeCompare(b.command);
}

private static toKeybindingEntry(command: string, keybindingItem: ResolvedKeybindingItem, workbenchActionsRegistry: IWorkbenchActionRegistry, editorActions: {}): IKeybindingItem {
private static toKeybindingEntry(command: string, keybindingItem: ResolvedKeybindingItem, workbenchActionsRegistry: IWorkbenchActionRegistry, editorActions: { [id: string]: string; }): IKeybindingItem {
const menuCommand = MenuRegistry.getCommand(command);
const editorAction: EditorAction = editorActions[command];
const editorActionLabel = editorActions[command];
return <IKeybindingItem>{
keybinding: keybindingItem.resolvedKeybinding,
keybindingItem,
command,
commandLabel: KeybindingsEditorModel.getCommandLabel(menuCommand, editorAction),
commandLabel: KeybindingsEditorModel.getCommandLabel(menuCommand, editorActionLabel),
commandDefaultLabel: KeybindingsEditorModel.getCommandDefaultLabel(menuCommand, workbenchActionsRegistry),
when: keybindingItem.when ? keybindingItem.when.serialize() : '',
source: keybindingItem.isDefault ? localize('default', "Default") : localize('user', "User")
Expand All @@ -223,13 +218,13 @@ export class KeybindingsEditorModel extends EditorModel {
return null;
}

private static getCommandLabel(menuCommand: ICommandAction, editorAction: EditorAction): string {
private static getCommandLabel(menuCommand: ICommandAction, editorActionLabel: string): string {
if (menuCommand) {
return typeof menuCommand.title === 'string' ? menuCommand.title : menuCommand.title.value;
}

if (editorAction) {
return editorAction.label;
if (editorActionLabel) {
return editorActionLabel;
}

return '';
Expand Down

0 comments on commit 3d1ccaa

Please sign in to comment.