Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom formatting of display name #359

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions package.build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down
14 changes: 14 additions & 0 deletions package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 16 additions & 3 deletions src/state/editors.ts
Original file line number Diff line number Diff line change
@@ -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`.
Expand Down Expand Up @@ -234,14 +234,27 @@ 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;

return vscode.commands.executeCommand("setContext", extensionName + ".mode", mode.name);
}

private _formatDisplayName(modeName: string) {
switch (vscode.workspace.getConfiguration(extensionName)
.get<string>("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.
Expand Down