提交 9582aef3 编写于 作者: A Alex Dima

Reduce usage of EditorAction.isSupported()

上级 2ee0412b
......@@ -601,6 +601,10 @@ export class DiffEditorWidget extends EventEmitter implements editorBrowser.IDif
return this.modifiedEditor.getActions();
}
public getSupportedActions(): IAction[] {
return this.modifiedEditor.getSupportedActions();
}
public getAction(id:string): IAction {
return this.modifiedEditor.getAction(id);
}
......
......@@ -24,7 +24,7 @@ import {EditorState} from 'vs/editor/common/core/editorState';
import {Position} from 'vs/editor/common/core/position';
import {Range} from 'vs/editor/common/core/range';
import {Selection} from 'vs/editor/common/core/selection';
import {DynamicEditorAction} from 'vs/editor/common/editorAction';
import {EditorAction, DynamicEditorAction} from 'vs/editor/common/editorAction';
import * as editorCommon from 'vs/editor/common/editorCommon';
import {ICodeEditorService} from 'vs/editor/common/services/codeEditorService';
import {CharacterHardWrappingLineMapperFactory} from 'vs/editor/common/viewModel/characterHardWrappingLineMapper';
......@@ -576,6 +576,13 @@ export abstract class CommonCodeEditor extends EventEmitter implements editorCom
return result;
}
public getSupportedActions(): IAction[] {
let result = this.getActions();
result = result.filter(action => (<EditorAction>action).isSupported());
return result;
}
public getAction(id:string): IAction {
var contribution = <any>this.contributions[id];
if (contribution) {
......
......@@ -12,7 +12,6 @@ export enum Behaviour {
WidgetFocus = 1 << 1,
Writeable = 1 << 2,
UpdateOnModelChange = 1 << 3,
UpdateOnConfigurationChange = 1 << 4,
UpdateOnCursorPositionChange = 1 << 6
}
......
......@@ -3588,6 +3588,11 @@ export interface IEditor {
*/
getActions(): IAction[];
/**
* Returns all actions associated with this editor.
*/
getSupportedActions(): IAction[];
/**
* Saves current view state of the editor in a serializable object.
*/
......
......@@ -12,7 +12,6 @@ import {TPromise} from 'vs/base/common/winjs.base';
import {IContext, IHighlight, QuickOpenEntryGroup, QuickOpenModel} from 'vs/base/parts/quickopen/browser/quickOpenModel';
import {IAutoFocus, Mode} from 'vs/base/parts/quickopen/common/quickOpen';
import {IKeybindingService} from 'vs/platform/keybinding/common/keybinding';
import {EditorAction} from 'vs/editor/common/editorAction';
import {ICommonCodeEditor, IEditor, IEditorActionDescriptorData} from 'vs/editor/common/editorCommon';
import {BaseEditorQuickOpenAction} from './editorQuickOpen';
......@@ -80,7 +79,7 @@ export class QuickCommandAction extends BaseEditorQuickOpenAction {
}
_getModel(value: string): QuickOpenModel {
return new QuickOpenModel(this._editorActionsToEntries(this.editor.getActions(), value));
return new QuickOpenModel(this._editorActionsToEntries(this.editor.getSupportedActions(), value));
}
_sort(elementA: QuickOpenEntryGroup, elementB: QuickOpenEntryGroup): number {
......@@ -96,13 +95,7 @@ export class QuickCommandAction extends BaseEditorQuickOpenAction {
for (let i = 0; i < actions.length; i++) {
let action = actions[i];
let editorAction = <EditorAction>action;
if (!editorAction.isSupported()) {
continue; // do not show actions that are not supported in this context
}
let keys = this._keybindingService.lookupKeybindings(editorAction.id).map(k => this._keybindingService.getLabelFor(k));
let keys = this._keybindingService.lookupKeybindings(action.id).map(k => this._keybindingService.getLabelFor(k));
if (action.label) {
let highlights = matchesFuzzy(searchValue, action.label);
......
......@@ -2888,6 +2888,10 @@ declare module monaco.editor {
* Returns all actions associated with this editor.
*/
getActions(): IAction[];
/**
* Returns all actions associated with this editor.
*/
getSupportedActions(): IAction[];
/**
* Saves current view state of the editor in a serializable object.
*/
......
......@@ -256,8 +256,8 @@ export class CommandsHandler extends QuickOpenHandler {
let activeEditorControl = <any>(activeEditor ? activeEditor.getControl() : null);
let editorActions: EditorAction[] = [];
if (activeEditorControl && types.isFunction(activeEditorControl.getActions)) {
editorActions = activeEditorControl.getActions();
if (activeEditorControl && types.isFunction(activeEditorControl.getSupportedActions)) {
editorActions = activeEditorControl.getSupportedActions();
}
let editorEntries = this.editorActionsToEntries(editorActions, searchValue);
......@@ -319,12 +319,7 @@ export class CommandsHandler extends QuickOpenHandler {
for (let i = 0; i < actions.length; i++) {
let action = actions[i];
let editorAction = <EditorAction>action;
if (!editorAction.isSupported()) {
continue; // do not show actions that are not supported in this context
}
let keys = this.keybindingService.lookupKeybindings(editorAction.id);
let keys = this.keybindingService.lookupKeybindings(action.id);
let keyLabel = keys.map(k => this.keybindingService.getLabelFor(k));
let keyAriaLabel = keys.map(k => this.keybindingService.getAriaLabelFor(k));
let label = action.label;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册