From 5b25934bace96443d24687344aee96ae0432f348 Mon Sep 17 00:00:00 2001 From: Matt Bierner Date: Fri, 20 Jan 2017 15:12:44 -0800 Subject: [PATCH] Disable some commands while in the walkthrough --- src/vs/editor/common/editorCommon.ts | 4 ++++ .../editor/common/modes/editorModeContext.ts | 4 ++++ .../browser/goToDeclaration.ts | 21 ++++++++++++++----- .../browser/referenceSearch.ts | 5 ++++- 4 files changed, 28 insertions(+), 6 deletions(-) diff --git a/src/vs/editor/common/editorCommon.ts b/src/vs/editor/common/editorCommon.ts index c83b481fde0..3541039396a 100644 --- a/src/vs/editor/common/editorCommon.ts +++ b/src/vs/editor/common/editorCommon.ts @@ -3129,6 +3129,10 @@ export namespace ModeContextKeys { * @internal */ export const hasSignatureHelpProvider = new RawContextKey('editorHasSignatureHelpProvider', undefined); + /** + * @internal + */ + export const isInWalkThrough = new RawContextKey('isInWalkThrough', undefined); } diff --git a/src/vs/editor/common/modes/editorModeContext.ts b/src/vs/editor/common/modes/editorModeContext.ts index b406ca7c8d0..e71ad563f39 100644 --- a/src/vs/editor/common/modes/editorModeContext.ts +++ b/src/vs/editor/common/modes/editorModeContext.ts @@ -28,6 +28,7 @@ export class EditorModeContext { private _hasDocumentFormattingProvider: IContextKey; private _hasDocumentSelectionFormattingProvider: IContextKey; private _hasSignatureHelpProvider: IContextKey; + private _isInWalkThrough: IContextKey; constructor( editor: ICommonCodeEditor, @@ -49,6 +50,7 @@ export class EditorModeContext { this._hasDocumentFormattingProvider = ModeContextKeys.hasDocumentFormattingProvider.bindTo(contextKeyService); this._hasDocumentSelectionFormattingProvider = ModeContextKeys.hasDocumentSelectionFormattingProvider.bindTo(contextKeyService); this._hasSignatureHelpProvider = ModeContextKeys.hasSignatureHelpProvider.bindTo(contextKeyService); + this._isInWalkThrough = ModeContextKeys.isInWalkThrough.bindTo(contextKeyService); // update when model/mode changes this._disposables.push(editor.onDidChangeModel(() => this._update())); @@ -91,6 +93,7 @@ export class EditorModeContext { this._hasDocumentFormattingProvider.reset(); this._hasDocumentSelectionFormattingProvider.reset(); this._hasSignatureHelpProvider.reset(); + this._isInWalkThrough.reset(); } private _update() { @@ -113,5 +116,6 @@ export class EditorModeContext { this._hasSignatureHelpProvider.set(modes.SignatureHelpProviderRegistry.has(model)); this._hasDocumentFormattingProvider.set(modes.DocumentFormattingEditProviderRegistry.has(model) || modes.DocumentRangeFormattingEditProviderRegistry.has(model)); this._hasDocumentSelectionFormattingProvider.set(modes.DocumentRangeFormattingEditProviderRegistry.has(model)); + this._isInWalkThrough.set(model.uri.scheme === 'walkThroughSnippet'); } } diff --git a/src/vs/editor/contrib/goToDeclaration/browser/goToDeclaration.ts b/src/vs/editor/contrib/goToDeclaration/browser/goToDeclaration.ts index 3e3f8e96961..1dabb46e178 100644 --- a/src/vs/editor/contrib/goToDeclaration/browser/goToDeclaration.ts +++ b/src/vs/editor/contrib/goToDeclaration/browser/goToDeclaration.ts @@ -169,7 +169,9 @@ export class GoToDefinitionAction extends DefinitionAction { id: GoToDefinitionAction.ID, label: nls.localize('actions.goToDecl.label', "Go to Definition"), alias: 'Go to Definition', - precondition: ModeContextKeys.hasDefinitionProvider, + precondition: ContextKeyExpr.and( + ModeContextKeys.hasDefinitionProvider, + ModeContextKeys.isInWalkThrough.toNegated()), kbOpts: { kbExpr: EditorContextKeys.TextFocus, primary: goToDeclarationKb @@ -192,7 +194,9 @@ export class OpenDefinitionToSideAction extends DefinitionAction { id: OpenDefinitionToSideAction.ID, label: nls.localize('actions.goToDeclToSide.label', "Open Definition to the Side"), alias: 'Open Definition to the Side', - precondition: ModeContextKeys.hasDefinitionProvider, + precondition: ContextKeyExpr.and( + ModeContextKeys.hasDefinitionProvider, + ModeContextKeys.isInWalkThrough.toNegated()), kbOpts: { kbExpr: EditorContextKeys.TextFocus, primary: KeyChord(KeyMod.CtrlCmd | KeyCode.KEY_K, goToDeclarationKb) @@ -208,7 +212,10 @@ export class PeekDefinitionAction extends DefinitionAction { id: 'editor.action.previewDeclaration', label: nls.localize('actions.previewDecl.label', "Peek Definition"), alias: 'Peek Definition', - precondition: ContextKeyExpr.and(ModeContextKeys.hasDefinitionProvider, PeekContext.notInPeekEditor), + precondition: ContextKeyExpr.and( + ModeContextKeys.hasDefinitionProvider, + PeekContext.notInPeekEditor, + ModeContextKeys.isInWalkThrough.toNegated()), kbOpts: { kbExpr: EditorContextKeys.TextFocus, primary: KeyMod.Alt | KeyCode.F12, @@ -233,7 +240,9 @@ export class GoToImplementationAction extends DefinitionAction { id: GoToImplementationAction.ID, label: nls.localize('actions.goToImplementation.label', "Go to Implementation"), alias: 'Go to Implementation', - precondition: ModeContextKeys.hasTypeDefinitionProvider, + precondition: ContextKeyExpr.and( + ModeContextKeys.hasTypeDefinitionProvider, + ModeContextKeys.isInWalkThrough.toNegated()), kbOpts: { kbExpr: EditorContextKeys.TextFocus, primary: KeyMod.CtrlCmd | KeyCode.F12 @@ -260,7 +269,9 @@ export class PeekImplementationAction extends DefinitionAction { id: PeekImplementationAction.ID, label: nls.localize('actions.peekImplementation.label', "Peek Implementation"), alias: 'Peek Implementation', - precondition: ModeContextKeys.hasTypeDefinitionProvider, + precondition: ContextKeyExpr.and( + ModeContextKeys.hasTypeDefinitionProvider, + ModeContextKeys.isInWalkThrough.toNegated()), kbOpts: { kbExpr: EditorContextKeys.TextFocus, primary: KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.F12 diff --git a/src/vs/editor/contrib/referenceSearch/browser/referenceSearch.ts b/src/vs/editor/contrib/referenceSearch/browser/referenceSearch.ts index e8dd921fb85..f5eb6aa54fd 100644 --- a/src/vs/editor/contrib/referenceSearch/browser/referenceSearch.ts +++ b/src/vs/editor/contrib/referenceSearch/browser/referenceSearch.ts @@ -63,7 +63,10 @@ export class ReferenceAction extends EditorAction { id: 'editor.action.referenceSearch.trigger', label: nls.localize('references.action.label', "Find All References"), alias: 'Find All References', - precondition: ContextKeyExpr.and(ModeContextKeys.hasReferenceProvider, PeekContext.notInPeekEditor), + precondition: ContextKeyExpr.and( + ModeContextKeys.hasReferenceProvider, + PeekContext.notInPeekEditor, + ModeContextKeys.isInWalkThrough.toNegated()), kbOpts: { kbExpr: EditorContextKeys.TextFocus, primary: KeyMod.Shift | KeyCode.F12 -- GitLab