Порівняти коміти

...
Автор SHA1 Повідомлення Дата
l0ng-ai bad9f9f376 feat(editor): choose the styles Cycle Identifier Case goes through
Settings › Editor › General › Smart Keys gets a Cycle Identifier Case group
with one checkbox per style (snake_case, SCREAMING_SNAKE_CASE, kebab-case,
camelCase, PascalCase), all on by default. The action skips the styles that
are off and keeps starting from the style the name is written in, even when
that one is off.

Fixes #6972
2026-11-30 23:50:05 +08:00
10 змінених файлів з 91 додано та 7 видалено

No files matched your search

+25
Переглянути файл
@@ -314,6 +314,30 @@ pub struct SmartKeysSettings {
pub insert_doc_stub: bool,
/// Backspace › Unindent: `autoindent` (proper indent position) | `nearest` indent position | `none`.
pub backspace_unindent: String,
/// The styles Cycle Identifier Case goes through.
pub cycle_case: CycleCaseSettings,
}
/// Editor › General › Smart Keys › Cycle Identifier Case: the styles the action goes through.
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, Type)]
#[serde(default, rename_all = "camelCase")]
pub struct CycleCaseSettings {
/// `snake_case`
pub snake: bool,
/// `SCREAMING_SNAKE_CASE`
pub screaming: bool,
/// `kebab-case`
pub kebab: bool,
/// `camelCase`
pub camel: bool,
/// `PascalCase`
pub pascal: bool,
}
impl Default for CycleCaseSettings {
fn default() -> Self {
Self { snake: true, screaming: true, kebab: true, camel: true, pascal: true }
}
}
impl Default for SmartKeysSettings {
@@ -335,6 +359,7 @@ impl Default for SmartKeysSettings {
smart_indent: true,
insert_doc_stub: true,
backspace_unindent: "autoindent".into(),
cycle_case: CycleCaseSettings::default(),
}
}
}
+16
Переглянути файл
@@ -5975,6 +5975,20 @@ export type CustomKeymap = {
overrides?: { [key in string]: string[] },
};
/** Editor › General › Smart Keys › Cycle Identifier Case: the styles the action goes through. */
export type CycleCaseSettings = {
/** `snake_case` */
snake?: boolean,
/** `SCREAMING_SNAKE_CASE` */
screaming?: boolean,
/** `kebab-case` */
kebab?: boolean,
/** `camelCase` */
camel?: boolean,
/** `PascalCase` */
pascal?: boolean,
};
/**
* A field watchpoint (DAP data breakpoint) on a `dataId` from [`DebugManager::data_breakpoint_info`]
* (java-debug ids, `Class#field`, stay valid across sessions).
@@ -15073,6 +15087,8 @@ export type SmartKeysSettings = {
insertDocStub?: boolean,
/** Backspace › Unindent: `autoindent` (proper indent position) | `nearest` indent position | `none`. */
backspaceUnindent?: string,
/** The styles Cycle Identifier Case goes through. */
cycleCase?: CycleCaseSettings,
};
export type SourceFolder = {
+1 -1
Переглянути файл
@@ -1348,7 +1348,7 @@ export function registerEditorActions(): () => void {
edit("code.joinLines", "Join Lines", (v) => joinLines(v)),
edit("code.toggleCase", "Toggle Case", (v) => toggleCase(v), { keywords: ["upper", "lower"] }),
edit("code.transpose", "Transpose", (v) => transpose(v), { category: "Editor Actions" }),
edit("code.cycleCase", "Cycle Identifier Case", (v) => cycleCase(v), {
edit("code.cycleCase", "Cycle Identifier Case", (v) => cycleCase(v, editorPrefs().smartKeys.cycleCase), {
keywords: ["camel", "snake", "kebab", "pascal", "screaming"],
}),
caret("code.addCaretsToLineEnds", "Add Carets to Ends of Selected Lines", (v) => addCaretsToLineEnds(v), {
+6 -3
Переглянути файл
@@ -36,7 +36,7 @@ import {
} from "@codemirror/commands";
import { SearchCursor } from "@codemirror/search";
import { humpLeft, humpRight, wordStartLeft } from "../model/camelHumps";
import { cycleIdentifierCase, wordSpan } from "../model/identifierCase";
import { cycleIdentifierCase, wordSpan, type IdentifierCase } from "../model/identifierCase";
import { restartSticky } from "./stickySelection";
type Node = ReturnType<ReturnType<typeof syntaxTree>["resolveInner"]>;
@@ -1087,7 +1087,10 @@ const NAME_CHAR = /[\p{L}\p{N}_$-]/u;
* or of each selection, from the style it is written in: snake_case →
* SCREAMING_SNAKE_CASE → kebab-case → camelCase → PascalCase.
*/
export const cycleCase: Command = (view) => {
export const cycleCase = (
view: EditorView,
enabled: Readonly<Partial<Record<IdentifierCase, boolean>>> = {},
): boolean => {
const { state } = view;
if (state.readOnly) return false;
/** The `-`-joined name at or right before `pos`. */
@@ -1107,7 +1110,7 @@ export const cycleCase: Command = (view) => {
const span = wordSpan(state.sliceDoc(name.from, name.to));
if (!span) return { range: r };
const from = name.from + span.from;
const insert = cycleIdentifierCase(state.sliceDoc(from, name.from + span.to));
const insert = cycleIdentifierCase(state.sliceDoc(from, name.from + span.to), enabled);
if (insert === null) return { range: r };
changed = true;
const set = state.changes({ from, to: name.from + span.to, insert });
+15
Переглянути файл
@@ -39,6 +39,21 @@ describe("cycle identifier case", () => {
expect(cycleIdentifierCase("MyVarName")).toBe("my_var_name");
});
it("goes only through the styles turned on, starting from the one the name is written in", () => {
const camelSnake = { screaming: false, kebab: false, pascal: false };
expect(cycleIdentifierCase("myVarName", camelSnake)).toBe("my_var_name");
expect(cycleIdentifierCase("my_var_name", camelSnake)).toBe("myVarName");
// A name in a style that is turned off still moves on to the next one that is on.
expect(cycleIdentifierCase("my-var-name", camelSnake)).toBe("myVarName");
expect(cycleIdentifierCase("MyVarName", camelSnake)).toBe("my_var_name");
// Only the name's own style on: nothing else to go to.
expect(
cycleIdentifierCase("myVarName", { snake: false, screaming: false, kebab: false, pascal: false }),
).toBeNull();
// One word in snake_case is written as in camelCase, so with Name and NAME off it stays.
expect(cycleIdentifierCase("name", { pascal: false, screaming: false })).toBeNull();
});
it("gives one word its three spellings: name → Name → NAME", () => {
expect(cycleIdentifierCase("name")).toBe("Name");
expect(cycleIdentifierCase("Name")).toBe("NAME");
+9 -3
Переглянути файл
@@ -81,14 +81,20 @@ export function toIdentifierCase(text: string, style: IdentifierCase): string {
/**
* `text` in the next style of the cycle, skipping the styles that write it the
* same way; null when none writes it differently.
* same way and those `enabled` turns off (Settings › Editor › General › Smart
* Keys); null when none writes it differently.
*/
export function cycleIdentifierCase(text: string): string | null {
export function cycleIdentifierCase(
text: string,
enabled: Readonly<Partial<Record<IdentifierCase, boolean>>> = {},
): string | null {
const current = identifierCase(text);
if (!current) return null;
// One word has three spellings, not five: name → Name → NAME.
const single = identifierWords(text).length === 1 && !SEPARATOR.test(text);
const order: readonly IdentifierCase[] = single ? ["camel", "pascal", "screaming", "snake"] : identifierCases;
const all: readonly IdentifierCase[] = single ? ["camel", "pascal", "screaming", "snake"] : identifierCases;
// The style the name is written in stays the starting point even when it is turned off.
const order = all.filter((style) => style === current || enabled[style] !== false);
const start = Math.max(0, order.indexOf(current));
for (let step = 1; step <= order.length; step++) {
const next = toIdentifierCase(text, order[(start + step) % order.length]!);
+13
Переглянути файл
@@ -819,6 +819,9 @@ const SMART_KEYS = editorPage({
"whitespace",
"indent",
"semicolon",
"case",
"snake case",
"camel case",
],
sections: [
{
@@ -913,6 +916,16 @@ const SMART_KEYS = editorPage({
},
],
},
{
title: "Cycle Identifier Case",
items: [
{ t: "check", key: `${P}.smartKeys.cycleCase.snake`, label: "snake_case" },
{ t: "check", key: `${P}.smartKeys.cycleCase.screaming`, label: "SCREAMING_SNAKE_CASE" },
{ t: "check", key: `${P}.smartKeys.cycleCase.kebab`, label: "kebab-case" },
{ t: "check", key: `${P}.smartKeys.cycleCase.camel`, label: "camelCase" },
{ t: "check", key: `${P}.smartKeys.cycleCase.pascal`, label: "PascalCase" },
],
},
],
});
+2
Переглянути файл
@@ -233,6 +233,8 @@ export const EDITOR_EXTRA_DEFAULTS = {
smartIndent: true,
insertDocStub: true,
backspaceUnindent: "autoindent",
/** The styles Cycle Identifier Case goes through. */
cycleCase: { snake: true, screaming: true, kebab: true, camel: true, pascal: true },
},
codeEditing: {
highlightUsages: true,
+2
Переглянути файл
@@ -284,6 +284,8 @@ describe("catalogs", () => {
const OWN_SCRIPT = new Set(["zh", "ko"]);
/** Product names intentionally kept as written in every locale. */
const SAME_AS_ENGLISH = new Set([
"SCREAMING_SNAKE_CASE",
"camelCase",
// PostgreSQL storage parameters, the placeholder of Modify Table's Storage options field.
"fillfactor=70, autovacuum_enabled=false",
// The placeholder of an Xcode run configuration's project or workspace field.
+2
Переглянути файл
@@ -1189,6 +1189,8 @@
"Join Lines": "合并行",
"Toggle Case": "切换大小写",
"Cycle Identifier Case": "循环切换标识符大小写",
"SCREAMING_SNAKE_CASE": "SCREAMING_SNAKE_CASE",
"camelCase": "camelCase",
"Add or Remove Caret": "添加或移除插入点",
"Create Rectangular Selection on Mouse Drag": "拖动鼠标创建矩形选区",
"Middle Click": "鼠标中键",