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

...
Автор SHA1 Повідомлення Дата
l0ng-ai a738209cbe fix(editor): Sort Lines orders by character code
Sort Lines used a locale-aware collator, which interleaves upper- and
lowercase letters. It now compares UTF-16 code units, the order IDEA's
Sort Lines uses (String.compareTo) and LC_ALL=C sort gives.

Closes #3516
2026-11-15 22:46:55 +08:00
4 змінених файлів з 14 додано та 5 видалено

No files matched your search

+1 -1
Переглянути файл
@@ -47,7 +47,7 @@ The editor follows IntelliJ IDEA's behaviour and default keymap. Shortcuts below
| **Move Caret to Code Block Start** / **End** | `⌥⌘[` / `⌥⌘]` | `Ctrl+[` / `Ctrl+]` |
| **Toggle Insert/Overwrite** | `Insert` | `Insert` |
**Edit › Sort Lines** and **Edit › Reverse Lines** reorder the selected lines; they have no default shortcut.
**Edit › Sort Lines** and **Edit › Reverse Lines** reorder the selected lines (the whole file without a selection); they have no default shortcut. Sort Lines orders by character code, so uppercase letters come before lowercase ones.
Brackets and quotes are paired as you type, and typing a quote or bracket over a selection surrounds it. These and other typing aids (smart Home, Tab out of a closing bracket, smart indent on Enter, documentation comment stubs, what Backspace does with indentation, reformat on paste) are under **Settings › Editor › General › Smart Keys**.
+1 -1
Переглянути файл
@@ -47,7 +47,7 @@ description: "多光标与选区、行编辑、剪贴板历史、代码折叠、
| **将光标移至代码块开头** / **末尾** | `⌥⌘[` / `⌥⌘]` | `Ctrl+[` / `Ctrl+]` |
| **切换插入/改写** | `Insert` | `Insert` |
**编辑 › 对行排序** 和 **编辑 › 反转行** 对选中的行重新排序,默认没有快捷键。
**编辑 › 对行排序** 和 **编辑 › 反转行** 对选中的行(没有选区时为整个文件)重新排序,默认没有快捷键。对行排序按字符编码排序,大写字母排在小写字母之前。
输入时括号和引号会自动成对,选中文本后输入引号或括号会把选区包起来。这些以及其他输入辅助(智能 Home、用 Tab 跳出右括号、回车智能缩进、文档注释骨架、退格键如何处理缩进、粘贴时重新格式化)都在 **设置 › 编辑器 › 常规 › 智能键** 中。
+8
Переглянути файл
@@ -28,6 +28,14 @@ describe("Sort Lines / Reverse Lines", () => {
expect(apply(doc, sel, sortLinesSpec)).toBe("a\nb\n--\nc\nd");
});
it("sorts by code unit, uppercase before lowercase, as IDEA does", () => {
const doc = '"github:opentofu/tofu-ls" = "0.5"\n"github:PowerShell/PowerShellEditorServices" = "4.7"';
expect(apply(doc, undefined, sortLinesSpec)).toBe(
'"github:PowerShell/PowerShellEditorServices" = "4.7"\n"github:opentofu/tofu-ls" = "0.5"',
);
expect(apply("b\nB\na\nA\n_\n1", undefined, sortLinesSpec)).toBe("1\nA\nB\n_\na\nb");
});
it("does nothing for a single line or an already sorted block", () => {
expect(apply("only", undefined, sortLinesSpec)).toBeNull();
expect(apply("a\nb", undefined, sortLinesSpec)).toBeNull();
+4 -3
Переглянути файл
@@ -7,8 +7,6 @@ import {
type TransactionSpec,
} from "@codemirror/state";
const collator = new Intl.Collator(undefined, { numeric: false, sensitivity: "variant" });
/** Line blocks the command applies to: one per non-empty selection range, or the document. */
function blocks(state: EditorState): Array<{ from: number; to: number }> {
const ranges = state.selection.ranges.filter((r) => !r.empty);
@@ -59,8 +57,11 @@ function rewrite(
};
}
/** Plain UTF-16 code-unit order, as IDEA sorts (`String.compareTo`): every uppercase letter before every lowercase one. */
const byCodeUnit = (a: string, b: string) => (a < b ? -1 : a > b ? 1 : 0);
export function sortLinesSpec(state: EditorState): TransactionSpec | null {
return rewrite(state, (lines) => [...lines].sort((a, b) => collator.compare(a, b)), "input.sort");
return rewrite(state, (lines) => [...lines].sort(byCodeUnit), "input.sort");
}
export function reverseLinesSpec(state: EditorState): TransactionSpec | null {