Файли
openidea/src/features/settings/nativeToAscii.ts
T
l0ng-ai 27ed0515e8 feat(editor): support transparent native-to-ascii conversion (#537)
Properties documents passed through charset decoding alone, leaving Unicode escapes in the shared document text.

- Add a default-off "Transparent native-to-ascii conversion" setting under the properties encoding and a stable action. Changing it reloads clean properties buffers in place; dirty buffers keep their codec.
- Decode eligible escapes and surrogate pairs when constructing documents, and save non-ASCII as uppercase escapes in pure ASCII. Backslash pairs, malformed escapes, unpaired surrogates and line terminator escapes stay literal, so an edit cannot split a property across lines.
- Use the same codec for search, closed-file readers, Git diffs, staging and partial commits. Clean saves and undone edits preserve the original bytes.

Fixes #519
2026-10-31 14:20:59 +08:00

33 рядки
1.1 KiB
TypeScript

import type { Action } from "@/platform/actions";
import { call, commands } from "@/platform/ipc";
import { loadSettings, useProject } from "@/platform/project";
import { stage, type Scope } from "./model/staging";
export const NATIVE_TO_ASCII_ACTION = "editor.encodings.toggleNativeToAscii";
const KEY = "editor.encodings.nativeToAscii";
export function nativeToAsciiAction(): Action {
return {
id: NATIVE_TO_ASCII_ACTION,
title: "Transparent native-to-ascii conversion",
category: "Editor",
keywords: ["properties", "encoding", "Unicode"],
run: async ({ arg }) => {
const staged = arg as { pageId?: string; scope?: Scope; value?: boolean } | undefined;
if (staged?.pageId && staged.scope && typeof staged.value === "boolean") {
stage(staged.pageId, staged.scope, KEY, staged.value);
return;
}
const { settings, project } = useProject.getState();
await call(
commands.settingsSet(
project ? "project" : "global",
KEY,
JSON.stringify(!settings?.editor?.encodings?.nativeToAscii),
),
);
await loadSettings();
},
};
}