дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-04 09:11:10 +02:00
feat(editor): disable sticky lines for the current language (#6814)
Adds a View action, Disable Sticky Lines for Language, that appends the active document's language to the existing per-language disabled list without touching the global Sticky Lines setting. It is available when sticky lines are on and the active editor has a known language (never for a notebook cell), keeps other entries, skips redundant writes, and is mapped from the EditorStickyLinesDisableForLang action id. Includes zh and zh-TW translations. Co-authored-by: muutot <[email protected]>
Цей коміт міститься в:
1 джерело
f7141f6515
коміт
a111b32e11
6 files changed
+149
-2
No files matched your search
@@ -1,6 +1,6 @@
|
||||
import type { EditorView } from "@codemirror/view";
|
||||
import type { Locator } from "@playwright/test";
|
||||
import { expect, test } from "./fixtures";
|
||||
import { expect, stubDesktop, stubSettingsWrites, test } from "./fixtures";
|
||||
|
||||
function codeStart(line: Locator) {
|
||||
return line.evaluate((element) => {
|
||||
@@ -19,6 +19,8 @@ function codeStart(line: Locator) {
|
||||
}
|
||||
|
||||
test("Sticky Lines follows editor text, line numbers and the viewport below Find", async ({ workbench: page }) => {
|
||||
await stubDesktop(page);
|
||||
await stubSettingsWrites(page);
|
||||
await page.setViewportSize({ width: 1200, height: 760 });
|
||||
const header = "for (const value of entries)";
|
||||
const path = "/dev/acme-api/sticky-layout.ts";
|
||||
@@ -126,4 +128,17 @@ test("Sticky Lines follows editor text, line numbers and the viewport below Find
|
||||
await find.press("Escape");
|
||||
await pinned.locator(".cm-openidea-stickyText").click({ position: { x: 32, y: 4 } });
|
||||
await expect(content.locator(".cm-activeLine")).toContainText(header);
|
||||
|
||||
await page.evaluate(async () => {
|
||||
const actionsModule = "/src/platform/actions.ts";
|
||||
const { executeAction } = await import(/* @vite-ignore */ actionsModule);
|
||||
await executeAction("editor.disableStickyLinesForLanguage");
|
||||
});
|
||||
await expect(sticky).toHaveCount(0);
|
||||
const disabled = await page.evaluate(async () => {
|
||||
const projectModule = "/src/platform/project.ts";
|
||||
const { useProject } = await import(/* @vite-ignore */ projectModule);
|
||||
return useProject.getState().settings?.editor?.codeEditing?.stickyLinesDisabledLanguages;
|
||||
});
|
||||
expect(disabled).toContain("typescript");
|
||||
});
|
||||
@@ -778,6 +778,37 @@ export async function toggleSchemeSwitch(key: SchemeSwitch, on = !editorPrefs()[
|
||||
}
|
||||
}
|
||||
|
||||
/** IDEA's StickyLinesDisableForLangAction: the active document's known base language, if enabled. */
|
||||
function activeStickyLinesLanguage(): string | null {
|
||||
// A notebook cell has no base document: never change the last text tab's language setting.
|
||||
if (!appearanceSwitches.stickyLines.on() || focusedCellEditor()) return null;
|
||||
return activeSlot()?.model.info?.id || null;
|
||||
}
|
||||
|
||||
async function disableStickyLinesForLanguage(): Promise<void> {
|
||||
const language = activeStickyLinesLanguage();
|
||||
if (!language) return;
|
||||
const disabled = editorPrefs().codeEditing.stickyLinesDisabledLanguages;
|
||||
if (disabled.includes(language)) return;
|
||||
try {
|
||||
useProject.setState({
|
||||
settings: await call(
|
||||
commands.settingsSet(
|
||||
"global",
|
||||
"editor.codeEditing.stickyLinesDisabledLanguages",
|
||||
JSON.stringify([...disabled, language]),
|
||||
),
|
||||
),
|
||||
});
|
||||
} catch (e) {
|
||||
notifications().notify({
|
||||
level: "error",
|
||||
title: "Cannot change the setting",
|
||||
body: e instanceof Error ? e.message : String(e),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const appearanceSwitch = (id: string, s: AppearanceSwitch, keywords: string[]): Action => ({
|
||||
id,
|
||||
title: s.title,
|
||||
@@ -896,6 +927,16 @@ export function registerEditorActions(): () => void {
|
||||
appearanceSwitch("editor.toggleLineNumbers", appearanceSwitches.lineNumbers, ["gutter", "hide line numbers"]),
|
||||
appearanceSwitch("editor.toggleIndentGuides", appearanceSwitches.indentGuides, ["indent lines", "indentation"]),
|
||||
appearanceSwitch("editor.toggleStickyLines", appearanceSwitches.stickyLines, ["sticky scroll"]),
|
||||
{
|
||||
id: "editor.disableStickyLinesForLanguage",
|
||||
title: "Disable Sticky Lines for Language",
|
||||
description: "Disable sticky lines for the current document's language without changing the global setting.",
|
||||
category: "View",
|
||||
keywords: ["sticky scroll", "language"],
|
||||
when: "textEditorActive",
|
||||
enabled: () => activeStickyLinesLanguage() !== null,
|
||||
run: disableStickyLinesForLanguage,
|
||||
},
|
||||
appearanceSwitch("editor.toggleWhitespaces", appearanceSwitches.whitespaces, [
|
||||
"render whitespace",
|
||||
"spaces",
|
||||
|
||||
@@ -1,4 +1,12 @@
|
||||
import { afterAll, afterEach, beforeAll, describe, expect, it, vi } from "vitest";
|
||||
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { useContextKeys } from "@/platform/context";
|
||||
import type { EditorSlot } from "./model/slot";
|
||||
|
||||
let activeSlot: Partial<EditorSlot> | null = null;
|
||||
vi.mock("./controller", async (importOriginal) => ({
|
||||
...(await importOriginal<object>()),
|
||||
editorController: () => ({ activeSlot }),
|
||||
}));
|
||||
|
||||
/** Writes the dotted key into the current settings, as the host does. */
|
||||
const ipc = vi.hoisted(() => ({
|
||||
@@ -29,7 +37,9 @@ beforeAll(() => {
|
||||
});
|
||||
afterAll(() => dispose());
|
||||
afterEach(() => {
|
||||
activeSlot = null;
|
||||
useProject.setState({ settings: null });
|
||||
useContextKeys.setState({}, true);
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
@@ -71,6 +81,82 @@ describe("editor appearance toggle actions", () => {
|
||||
expect(resolveActionId("EditorGutterToggleGlobalLineNumbers")).toBe("editor.toggleLineNumbers");
|
||||
expect(resolveActionId("EditorGutterToggleGlobalIndentLines")).toBe("editor.toggleIndentGuides");
|
||||
expect(resolveActionId("EditorGutterToggleGlobalStickyLines")).toBe("editor.toggleStickyLines");
|
||||
expect(resolveActionId("EditorStickyLinesDisableForLang")).toBe("editor.disableStickyLinesForLanguage");
|
||||
});
|
||||
});
|
||||
|
||||
describe("Disable Sticky Lines for Language", () => {
|
||||
const id = "editor.disableStickyLinesForLanguage";
|
||||
const key = "editor.codeEditing.stickyLinesDisabledLanguages";
|
||||
const typescript = { id: "typescript", name: "TypeScript" };
|
||||
const activate = (info: { id: string; name: string } | undefined) => {
|
||||
activeSlot = { disposed: false, model: { info } } as never;
|
||||
};
|
||||
const setEditorSettings = (disabledLanguages: string[], stickyScroll = true) => {
|
||||
useProject.setState({
|
||||
settings: { editor: { stickyScroll, codeEditing: { stickyLinesDisabledLanguages: disabledLanguages } } } as never,
|
||||
});
|
||||
};
|
||||
|
||||
beforeEach(() => useContextKeys.setState({ textEditorActive: true }));
|
||||
|
||||
it("is a View action mapped from IDEA", () => {
|
||||
expect(getAction(id)).toMatchObject({ title: "Disable Sticky Lines for Language", category: "View" });
|
||||
expect(resolveActionId("EditorStickyLinesDisableForLang")).toBe(id);
|
||||
});
|
||||
|
||||
it("is unavailable when global sticky lines are off", async () => {
|
||||
activate(typescript);
|
||||
setEditorSettings(["python"], false);
|
||||
expect(await executeAction(id)).toBe(false);
|
||||
expect(ipc.settingsSet).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("is unavailable without a known active document language", async () => {
|
||||
setEditorSettings(["python"]);
|
||||
expect(await executeAction(id)).toBe(false);
|
||||
activate(undefined);
|
||||
expect(await executeAction(id)).toBe(false);
|
||||
expect(ipc.settingsSet).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("writes the current language id once while preserving other disabled languages", async () => {
|
||||
activate(typescript);
|
||||
setEditorSettings(["python", "go"]);
|
||||
|
||||
expect(await executeAction(id)).toBe(true);
|
||||
expect(ipc.settingsSet).toHaveBeenCalledTimes(1);
|
||||
expect(ipc.settingsSet).toHaveBeenCalledWith("global", key, JSON.stringify(["python", "go", "typescript"]));
|
||||
expect(useProject.getState().settings?.editor).toMatchObject({
|
||||
stickyScroll: true,
|
||||
codeEditing: { stickyLinesDisabledLanguages: ["python", "go", "typescript"] },
|
||||
});
|
||||
});
|
||||
|
||||
it("is idempotent across repeated execution", async () => {
|
||||
activate(typescript);
|
||||
setEditorSettings(["python"]);
|
||||
|
||||
expect(await executeAction(id)).toBe(true);
|
||||
expect(await executeAction(id)).toBe(true);
|
||||
expect(ipc.settingsSet).toHaveBeenCalledTimes(1);
|
||||
expect(ipc.settingsSet).toHaveBeenCalledWith("global", key, JSON.stringify(["python", "typescript"]));
|
||||
});
|
||||
|
||||
it("leaves the global Show Sticky Lines toggle independent", async () => {
|
||||
activate(typescript);
|
||||
setEditorSettings(["python"]);
|
||||
const globalToggle = getAction("editor.toggleStickyLines");
|
||||
|
||||
await executeAction(id);
|
||||
expect(actionToggled(globalToggle)).toBe(true);
|
||||
await executeAction("editor.toggleStickyLines");
|
||||
expect(ipc.settingsSet).toHaveBeenLastCalledWith("global", "editor.stickyScroll", "false");
|
||||
expect(actionToggled(globalToggle)).toBe(false);
|
||||
expect(useProject.getState().settings?.editor).toMatchObject({
|
||||
codeEditing: { stickyLinesDisabledLanguages: ["python", "typescript"] },
|
||||
});
|
||||
expect(await executeAction(id)).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -157,6 +157,7 @@ export const IDEA_ACTIONS: Readonly<Record<string, string>> = {
|
||||
EditorGutterToggleGlobalLineNumbers: "editor.toggleLineNumbers",
|
||||
EditorGutterToggleGlobalIndentLines: "editor.toggleIndentGuides",
|
||||
EditorGutterToggleGlobalStickyLines: "editor.toggleStickyLines",
|
||||
EditorStickyLinesDisableForLang: "editor.disableStickyLinesForLanguage",
|
||||
ActivateProjectToolWindow: "toolwindow.project",
|
||||
HideAllWindows: "toolwindow.hideAll",
|
||||
HideActiveWindow: "toolwindow.hideActive",
|
||||
|
||||
@@ -3019,6 +3019,8 @@
|
||||
"Soft-Wrap": "軟換行",
|
||||
"Show Line Numbers": "顯示行號",
|
||||
"Show Indent Guides": "顯示縮排參考線",
|
||||
"Disable Sticky Lines for Language": "為目前語言停用粘滯行",
|
||||
"Disable sticky lines for the current document's language without changing the global setting.": "為目前文件的語言停用粘滯行,不變更全域設定。",
|
||||
"Show Sticky Lines": "顯示粘滯行",
|
||||
"Show Whitespaces": "顯示空白",
|
||||
"Use Soft Wraps": "使用軟換行",
|
||||
|
||||
@@ -3674,6 +3674,8 @@
|
||||
"Soft-Wrap": "软换行",
|
||||
"Show Line Numbers": "显示行号",
|
||||
"Show Indent Guides": "显示缩进参考线",
|
||||
"Disable Sticky Lines for Language": "为当前语言禁用粘滞行",
|
||||
"Disable sticky lines for the current document's language without changing the global setting.": "为当前文档的语言禁用粘滞行,不更改全局设置。",
|
||||
"Show Sticky Lines": "显示粘滞行",
|
||||
"Show Whitespaces": "显示空白",
|
||||
"Use Soft Wraps": "使用软换行",
|
||||
|
||||
Reference in new issue
Заблокувати користувача