-
Notifications
You must be signed in to change notification settings - Fork 67
Custom formatting of display name #359
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -280,6 +280,21 @@ export const pkg = (modules: Builder.ParsedModule[]) => ({ | |||
+ "non-directional, like Kakoune.", | ||||
], | ||||
}, | ||||
activeModeDisplayTextTransform: { | ||||
"enum": [ | ||||
"as-is", | ||||
"uppercase", | ||||
"lowercase", | ||||
|
||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: remove empty line
Suggested change
|
||||
], | ||||
"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"], | ||||
|
71 marked this conversation as resolved.
Show resolved
Hide resolved
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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`. | ||
|
@@ -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) { | ||
71 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
switch (vscode.workspace.getConfiguration(extensionName) | ||
.get<string>("activeModeDisplayTextTransform")) { | ||
Comment on lines
+246
to
+247
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a good way to get the key, but to avoid reading the configuration every time the mode changes (which can occur pretty often), I would instead use |
||
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. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This defines
activeModeDisplayTextTransform
as a property set on modes, not a global configuration. You need to move this below and name it"dance.activeModeDisplayTextTransform"
instead.