From 1a1b34888fadb8615cc8334f57cb20414e89b777 Mon Sep 17 00:00:00 2001 From: Tyler Date: Mon, 24 Feb 2025 17:03:54 -0500 Subject: [PATCH 1/2] Custom formatting of display name --- package.build.ts | 15 +++++++++++++++ package.json | 14 ++++++++++++++ src/state/editors.ts | 19 ++++++++++++++++--- 3 files changed, 45 insertions(+), 3 deletions(-) diff --git a/package.build.ts b/package.build.ts index 1bb2577c..aeb44a38 100644 --- a/package.build.ts +++ b/package.build.ts @@ -280,6 +280,21 @@ export const pkg = (modules: Builder.ParsedModule[]) => ({ + "non-directional, like Kakoune.", ], }, + activeModeDisplayTextTransform: { + "enum": [ + "as-is", + "uppercase", + "lowercase", + + ], + "default": "as-is", + "description": "Controls how the active mode is formatted in the status bar.", + "enumDescriptions": [ + "Display the name with its original formatting.", + "Convert the name to uppercase.", + "Convert the name to lowercase.", + ], + }, decorations: { ...selectionDecorationType, type: ["array", "object", "null"], diff --git a/package.json b/package.json index e705a67b..912b9bb8 100644 --- a/package.json +++ b/package.json @@ -208,6 +208,20 @@ "Selections are anchored to characters, like Kakoune; that is, they are positioned *on* characters, and therefore cannot be empty. Additionally, one-character selections will behave as if they were non-directional, like Kakoune." ] }, + "activeModeDisplayTextTransform": { + "enum": [ + "as-is", + "uppercase", + "lowercase" + ], + "default": "as-is", + "description": "Controls how the active mode is formatted in the status bar.", + "enumDescriptions": [ + "Display the name with its original formatting.", + "Convert the name to uppercase.", + "Convert the name to lowercase." + ] + }, "decorations": { "type": [ "array", diff --git a/src/state/editors.ts b/src/state/editors.ts index c0f18705..31c9903a 100644 --- a/src/state/editors.ts +++ b/src/state/editors.ts @@ -1,10 +1,10 @@ import * as vscode from "vscode"; -import type { Extension } from "./extension"; -import type { Mode } from "./modes"; import { command, commands, Context, Positions, SelectionBehavior, Selections } from "../api"; import { extensionName } from "../utils/constants"; import { assert } from "../utils/errors"; +import type { Extension } from "./extension"; +import type { Mode } from "./modes"; /** * Dance-specific state related to a single `vscode.TextEditor`. @@ -234,7 +234,7 @@ export class PerEditorState implements vscode.Disposable { public notifyDidBecomeActive() { const { editor, mode } = this; - this.extension.statusBar.activeModeSegment.setContent(mode.name); + this.extension.statusBar.activeModeSegment.setContent(this._formatDisplayName(mode.name)); editor.options.lineNumbers = mode.lineNumbers; editor.options.cursorStyle = mode.cursorStyle; @@ -242,6 +242,19 @@ export class PerEditorState implements vscode.Disposable { return vscode.commands.executeCommand("setContext", extensionName + ".mode", mode.name); } + private _formatDisplayName(modeName: string) { + switch (vscode.workspace.getConfiguration(extensionName) + .get("activeModeDisplayTextTransform")) { + case "uppercase": + return modeName.toUpperCase(); + case "lowercase": + return modeName.toLowerCase(); + case "as-is": + default: + return modeName; + } + } + /** * Called when `vscode.window.onDidChangeActiveTextEditor` is triggered with * another editor. From 1c596e9b8504f53b16242178cebd125fa544e0bd Mon Sep 17 00:00:00 2001 From: Tyler Date: Fri, 6 Jun 2025 16:40:41 -0400 Subject: [PATCH 2/2] Better way to fetch config --- package.build.ts | 30 +++++++++++++++--------------- package.json | 28 ++++++++++++++-------------- src/state/editors.ts | 3 +-- src/state/extension.ts | 16 ++++++++++++++++ 4 files changed, 46 insertions(+), 31 deletions(-) diff --git a/package.build.ts b/package.build.ts index aeb44a38..131e768f 100644 --- a/package.build.ts +++ b/package.build.ts @@ -280,21 +280,6 @@ export const pkg = (modules: Builder.ParsedModule[]) => ({ + "non-directional, like Kakoune.", ], }, - activeModeDisplayTextTransform: { - "enum": [ - "as-is", - "uppercase", - "lowercase", - - ], - "default": "as-is", - "description": "Controls how the active mode is formatted in the status bar.", - "enumDescriptions": [ - "Display the name with its original formatting.", - "Convert the name to uppercase.", - "Convert the name to lowercase.", - ], - }, decorations: { ...selectionDecorationType, type: ["array", "object", "null"], @@ -366,6 +351,21 @@ export const pkg = (modules: Builder.ParsedModule[]) => ({ description: "Controls the different modes available in Dance.", }, + "dance.activeModeDisplayTextTransform": { + "enum": [ + "as-is", + "uppercase", + "lowercase", + ], + "default": "as-is", + "description": "Controls how the active mode is formatted in the status bar.", + "enumDescriptions": [ + "Display the name with its original formatting.", + "Convert the name to uppercase.", + "Convert the name to lowercase.", + ], + }, + "dance.menus": { type: "object", scope: "language-overridable", diff --git a/package.json b/package.json index 912b9bb8..f9cc3db0 100644 --- a/package.json +++ b/package.json @@ -208,20 +208,6 @@ "Selections are anchored to characters, like Kakoune; that is, they are positioned *on* characters, and therefore cannot be empty. Additionally, one-character selections will behave as if they were non-directional, like Kakoune." ] }, - "activeModeDisplayTextTransform": { - "enum": [ - "as-is", - "uppercase", - "lowercase" - ], - "default": "as-is", - "description": "Controls how the active mode is formatted in the status bar.", - "enumDescriptions": [ - "Display the name with its original formatting.", - "Convert the name to uppercase.", - "Convert the name to lowercase." - ] - }, "decorations": { "type": [ "array", @@ -450,6 +436,20 @@ }, "description": "Controls the different modes available in Dance." }, + "dance.activeModeDisplayTextTransform": { + "enum": [ + "as-is", + "uppercase", + "lowercase" + ], + "default": "as-is", + "description": "Controls how the active mode is formatted in the status bar.", + "enumDescriptions": [ + "Display the name with its original formatting.", + "Convert the name to uppercase.", + "Convert the name to lowercase." + ] + }, "dance.menus": { "type": "object", "scope": "language-overridable", diff --git a/src/state/editors.ts b/src/state/editors.ts index 31c9903a..dee7b670 100644 --- a/src/state/editors.ts +++ b/src/state/editors.ts @@ -243,8 +243,7 @@ export class PerEditorState implements vscode.Disposable { } private _formatDisplayName(modeName: string) { - switch (vscode.workspace.getConfiguration(extensionName) - .get("activeModeDisplayTextTransform")) { + switch (this.extension.activeModeDisplayPreference) { case "uppercase": return modeName.toUpperCase(); case "lowercase": diff --git a/src/state/extension.ts b/src/state/extension.ts index 6085d262..a7a9eb9f 100644 --- a/src/state/extension.ts +++ b/src/state/extension.ts @@ -35,6 +35,11 @@ export class Extension implements vscode.Disposable { return this._gotoMenus as ReadonlyMap; } + private _activeModeDisplayPreference: string; + public get activeModeDisplayPreference() { + return this._activeModeDisplayPreference; + } + // State. // ========================================================================== @@ -120,6 +125,17 @@ export class Extension implements vscode.Disposable { public constructor(public readonly commands: Commands) { this.recorder = new Recorder(this); + // Configuration: mode display preference. + this._activeModeDisplayPreference = vscode.workspace.getConfiguration(extensionName) + .get("activeModeDisplayTextTransform") ?? "as-is"; + this.observePreference( + ".activeModeDisplayTextTransform", + (value, validator, inspect) => { + this._activeModeDisplayPreference = value; + }, + true, + ); + // Configuration: menus. this.observePreference>( ".menus",