提交 9f53cc4f 编写于 作者: A Alex Dima

Editor Action kbOpts are and`ed with _precondition

上级 60276551
......@@ -55,6 +55,9 @@ function analyze() {
// console.warn('MISSING PRECONDITION FOR ' + desc.id + desc.callsite);
// } else {
// let prec = desc._precondition ? desc._precondition.serialize() : 'null';
// if (prec.indexOf('editorTextFocus') >= 0 || prec.indexOf('editorFocus') >= 0) {
// console.warn('BELOW COMMAND WANTS FOCUS!!!');
// }
// if (desc._needsWritableEditor && prec.indexOf('!editorReadonly') === -1) {
// console.warn('BELOW COMMAND DOES NOT PRECONDITION CORRECTLY WRITABLE!');
// }
......@@ -67,6 +70,9 @@ function analyze() {
export module CommonEditorRegistry {
export function registerEditorAction(desc:EditorAction) {
if (desc.kbOpts && desc.kbOpts.kbExpr && desc._precondition) {
desc.kbOpts.kbExpr = KbExpr.and(desc.kbOpts.kbExpr, desc._precondition);
}
record(desc);
(<EditorContributionRegistry>Registry.as(Extensions.EditorCommonContributions)).registerEditorAction(desc);
}
......
......@@ -8,7 +8,6 @@ import * as nls from 'vs/nls';
import {ICommand, ICommonCodeEditor, EditorContextKeys} from 'vs/editor/common/editorCommon';
import {EditorAction, CommonEditorRegistry, ServicesAccessor} from 'vs/editor/common/editorCommonExtensions';
import {MoveCarretCommand} from './moveCarretCommand';
import {KbExpr} from 'vs/platform/keybinding/common/keybinding';
class MoveCarretAction extends EditorAction {
......@@ -17,7 +16,7 @@ class MoveCarretAction extends EditorAction {
constructor(id:string, label:string, alias:string, left:boolean) {
super(id, label, alias, true);
this._precondition = KbExpr.and(EditorContextKeys.Writable);
this._precondition = EditorContextKeys.Writable;
this.left = left;
}
......
......@@ -10,7 +10,6 @@ import * as nls from 'vs/nls';
import {KeyCode, KeyMod} from 'vs/base/common/keyCodes';
import * as browser from 'vs/base/browser/browser';
import {ServicesAccessor} from 'vs/platform/instantiation/common/instantiation';
import {KbExpr} from 'vs/platform/keybinding/common/keybinding';
import {findFocusedEditor} from 'vs/editor/common/config/config';
import * as editorCommon from 'vs/editor/common/editorCommon';
import {EditorAction, CommonEditorRegistry} from 'vs/editor/common/editorCommonExtensions';
......@@ -57,10 +56,10 @@ class ExecCommandCutAction extends ExecCommandAction {
'cut'
);
this._precondition = KbExpr.and(EditorContextKeys.Writable);
this._precondition = EditorContextKeys.Writable;
this.kbOpts = {
kbExpr: KbExpr.and(EditorContextKeys.TextFocus, EditorContextKeys.Writable),
kbExpr: EditorContextKeys.TextFocus,
primary: KeyMod.CtrlCmd | KeyCode.KEY_X,
win: { primary: KeyMod.CtrlCmd | KeyCode.KEY_X, secondary: [KeyMod.Shift | KeyCode.Delete] }
};
......@@ -132,7 +131,7 @@ class ExecCommandPasteAction extends ExecCommandAction {
this._precondition = EditorContextKeys.Writable;
this.kbOpts = {
kbExpr: KbExpr.and(EditorContextKeys.TextFocus, EditorContextKeys.Writable),
kbExpr: EditorContextKeys.TextFocus,
primary: KeyMod.CtrlCmd | KeyCode.KEY_V,
win: { primary: KeyMod.CtrlCmd | KeyCode.KEY_V, secondary: [KeyMod.Shift | KeyCode.Insert] }
};
......
......@@ -10,7 +10,6 @@ import {ICommand, ICommonCodeEditor, EditorContextKeys} from 'vs/editor/common/e
import {EditorAction, CommonEditorRegistry, ServicesAccessor} from 'vs/editor/common/editorCommonExtensions';
import {BlockCommentCommand} from './blockCommentCommand';
import {LineCommentCommand, Type} from './lineCommentCommand';
import {KbExpr} from 'vs/platform/keybinding/common/keybinding';
abstract class CommentLineAction extends EditorAction {
......@@ -53,7 +52,7 @@ class ToggleCommentLineAction extends CommentLineAction {
this._precondition = EditorContextKeys.Writable;
this.kbOpts = {
kbExpr: KbExpr.and(EditorContextKeys.TextFocus, EditorContextKeys.Writable),
kbExpr: EditorContextKeys.TextFocus,
primary: KeyMod.CtrlCmd | KeyCode.US_SLASH
};
}
......@@ -72,7 +71,7 @@ class AddLineCommentAction extends CommentLineAction {
this._precondition = EditorContextKeys.Writable;
this.kbOpts = {
kbExpr: KbExpr.and(EditorContextKeys.TextFocus, EditorContextKeys.Writable),
kbExpr: EditorContextKeys.TextFocus,
primary: KeyMod.chord(KeyMod.CtrlCmd | KeyCode.KEY_K, KeyMod.CtrlCmd | KeyCode.KEY_C)
};
}
......@@ -91,7 +90,7 @@ class RemoveLineCommentAction extends CommentLineAction {
this._precondition = EditorContextKeys.Writable;
this.kbOpts = {
kbExpr: KbExpr.and(EditorContextKeys.TextFocus, EditorContextKeys.Writable),
kbExpr: EditorContextKeys.TextFocus,
primary: KeyMod.chord(KeyMod.CtrlCmd | KeyCode.KEY_K, KeyMod.CtrlCmd | KeyCode.KEY_U)
};
}
......@@ -110,7 +109,7 @@ class BlockCommentAction extends EditorAction {
this._precondition = EditorContextKeys.Writable;
this.kbOpts = {
kbExpr: KbExpr.and(EditorContextKeys.TextFocus, EditorContextKeys.Writable),
kbExpr: EditorContextKeys.TextFocus,
primary: KeyMod.Shift | KeyMod.Alt | KeyCode.KEY_A,
linux: { primary: KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.KEY_A }
};
......
......@@ -419,6 +419,10 @@ export class StartFindReplaceAction extends EditorAction {
}
public run(accessor:ServicesAccessor, editor:editorCommon.ICommonCodeEditor): void {
if (editor.getConfiguration().readOnly) {
return;
}
let controller = CommonFindController.getFindController(editor);
controller.start({
forceRevealReplace: true,
......
......@@ -148,7 +148,7 @@ export class FormatAction extends EditorAction {
this._precondition = KbExpr.and(EditorContextKeys.Writable, ModeContextKeys.hasFormattingProvider);
this.kbOpts = {
kbExpr: KbExpr.and(EditorContextKeys.TextFocus, EditorContextKeys.Writable),
kbExpr: EditorContextKeys.TextFocus,
primary: KeyMod.Shift | KeyMod.Alt | KeyCode.KEY_F,
linux: { primary: KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.KEY_I }
};
......
......@@ -702,7 +702,7 @@ export class ShowDebugHoverAction extends EditorAction {
this._precondition = debug.CONTEXT_IN_DEBUG_MODE;
this.kbOpts = {
kbExpr: KbExpr.and(debug.CONTEXT_IN_DEBUG_MODE, EditorContextKeys.TextFocus),
kbExpr: EditorContextKeys.TextFocus,
primary: KeyMod.chord(KeyMod.CtrlCmd | KeyCode.KEY_K, KeyMod.CtrlCmd | KeyCode.KEY_I)
};
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册