diff --git a/src/vs/editor/contrib/anchorSelect/anchorSelect.ts b/src/vs/editor/contrib/anchorSelect/anchorSelect.ts index 8a422cddbbd61449e97147d314166d146655ecbd..19fc8271619474752626a8a78314a915d20dd3f6 100644 --- a/src/vs/editor/contrib/anchorSelect/anchorSelect.ts +++ b/src/vs/editor/contrib/anchorSelect/anchorSelect.ts @@ -15,6 +15,7 @@ import { RawContextKey, IContextKeyService, IContextKey } from 'vs/platform/cont import { IEditorContribution } from 'vs/editor/common/editorCommon'; import { TrackedRangeStickiness } from 'vs/editor/common/model'; import { MarkdownString } from 'vs/base/common/htmlContent'; +import { IDisposable } from 'vs/base/common/lifecycle'; export const SelectionAnchorSet = new RawContextKey('selectionAnchorSet', false); @@ -28,12 +29,14 @@ class SelectionAnchorController implements IEditorContribution { private decorationId: string | undefined; private selectionAnchorSetContextKey: IContextKey; + private modelChangeListener: IDisposable; constructor( private editor: ICodeEditor, @IContextKeyService contextKeyService: IContextKeyService ) { this.selectionAnchorSetContextKey = SelectionAnchorSet.bindTo(contextKeyService); + this.modelChangeListener = editor.onDidChangeModel(() => this.selectionAnchorSetContextKey.reset()); } setSelectionAnchor(): void { @@ -48,7 +51,7 @@ class SelectionAnchorController implements IEditorContribution { className: 'selection-anchor' } }]); - this.decorationId = newDecorationId.length === 1 ? newDecorationId[0] : undefined; + this.decorationId = newDecorationId[0]; this.selectionAnchorSetContextKey.set(!!this.decorationId); } } @@ -83,6 +86,7 @@ class SelectionAnchorController implements IEditorContribution { dispose(): void { this.cancelSelectionAnchor(); + this.modelChangeListener.dispose(); } } @@ -95,7 +99,7 @@ class SetSelectionAnchor extends EditorAction { precondition: undefined, kbOpts: { kbExpr: EditorContextKeys.editorTextFocus, - primary: KeyChord(KeyMod.CtrlCmd | KeyCode.KEY_K, KeyCode.KEY_B), + primary: KeyChord(KeyMod.CtrlCmd | KeyCode.KEY_K, KeyMod.CtrlCmd | KeyCode.KEY_B), weight: KeybindingWeight.EditorContrib } }); @@ -132,7 +136,7 @@ class SelectFromAnchorToCursor extends EditorAction { precondition: SelectionAnchorSet, kbOpts: { kbExpr: EditorContextKeys.editorTextFocus, - primary: KeyChord(KeyMod.CtrlCmd | KeyCode.KEY_K, KeyCode.KEY_K), + primary: KeyChord(KeyMod.CtrlCmd | KeyCode.KEY_K, KeyMod.CtrlCmd | KeyCode.KEY_K), weight: KeybindingWeight.EditorContrib } }); diff --git a/src/vs/editor/editor.all.ts b/src/vs/editor/editor.all.ts index 01ef0be7c83b48615c40440be8f29d74a33904b6..a591facd8b7fa4a34a52d270929224198b356b6a 100644 --- a/src/vs/editor/editor.all.ts +++ b/src/vs/editor/editor.all.ts @@ -7,6 +7,7 @@ import 'vs/editor/browser/controller/coreCommands'; import 'vs/editor/browser/widget/codeEditorWidget'; import 'vs/editor/browser/widget/diffEditorWidget'; import 'vs/editor/browser/widget/diffNavigator'; +import 'vs/editor/contrib/anchorSelect/anchorSelect'; import 'vs/editor/contrib/bracketMatching/bracketMatching'; import 'vs/editor/contrib/caretOperations/caretOperations'; import 'vs/editor/contrib/caretOperations/transpose'; @@ -45,7 +46,6 @@ import 'vs/editor/contrib/viewportSemanticTokens/viewportSemanticTokens'; import 'vs/editor/contrib/wordHighlighter/wordHighlighter'; import 'vs/editor/contrib/wordOperations/wordOperations'; import 'vs/editor/contrib/wordPartOperations/wordPartOperations'; -import 'vs/editor/contrib/anchorSelect/anchorSelect'; // Load up these strings even in VSCode, even if they are not used // in order to get them translated