From 39ad492b56d2b8b980784ffab3673130c26e9d94 Mon Sep 17 00:00:00 2001 From: jariji Date: Sun, 8 Mar 2026 19:44:12 +0000 Subject: [PATCH] fix: respect language-specific dance.defaultMode overrides dance.defaultMode is declared as language-overridable in package.json, but observePreference reads it via getConfiguration("dance") without a document scope, so language-specific overrides (e.g. [magit] or [git-commit]) are never resolved. The global value is stored as a single _defaultMode and applied to every new editor. Move the configuration lookup into _getDefaultModeForEditor, which passes the editor's document as the scope so that VS Code resolves language-specific values correctly. Co-Authored-By: Claude Opus 4.6 --- src/state/editors.ts | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/state/editors.ts b/src/state/editors.ts index aa54a26..0935f74 100644 --- a/src/state/editors.ts +++ b/src/state/editors.ts @@ -612,7 +612,6 @@ export class Editors implements vscode.Disposable { // Now `hiddenEditors` only contains editors that are no longer visible, and // `addedEditors` only contains editors that were not visible previously. - const defaultMode = this._extension.modes.defaultMode; for (const addedEditor of addedEditors) { const fallback = this._fallbacks.get(addedEditor.document); @@ -622,6 +621,7 @@ export class Editors implements vscode.Disposable { this._editors.set(addedEditor, fallback); this._fallbacks.delete(addedEditor.document); } else { + const defaultMode = this._getDefaultModeForEditor(addedEditor); this._editors.set( addedEditor, new PerEditorState(this._extension, addedEditor, defaultMode)); } @@ -656,6 +656,25 @@ export class Editors implements vscode.Disposable { } } + /** + * Returns the default mode for a new editor, respecting language-specific + * overrides of `dance.defaultMode`. + */ + private _getDefaultModeForEditor(editor: vscode.TextEditor): Mode { + const config = vscode.workspace.getConfiguration(extensionName, editor.document); + const defaultModeName = config.get("defaultMode"); + + if (defaultModeName !== undefined) { + const mode = this._extension.modes.get(defaultModeName); + + if (mode !== undefined) { + return mode; + } + } + + return this._extension.modes.defaultMode; + } + private _handleDidOpenTextDocument(document: vscode.TextDocument) { // When changing the file type of a new file, the current document is closed // and a new document with the same name and content is created. Attempt to