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

...
Автор SHA1 Повідомлення Дата
arookieofc 7b9314bdd9 chore: fix README formatting (pre-existing oxfmt violation blocking CI) 2026-11-10 11:04:38 +08:00
arookieofc 1efefe7ce3 fix(vcs): dedupe recent date filters by label (#2443)
The remembered date preset was compared by JSON, but its rolling
after/before timestamps are recomputed on every selection, so each
switch of the date filter appended a look-alike duplicate that
localStorage kept across restarts. Compare date values (and whole
snapshots) by label instead, and dedupe on read so already-corrupted
state heals itself.
2026-11-10 10:54:39 +08:00
l0ng-ai 97ff542cdd fix(editor): prevent duplicate Linux clipboard commands (#2392) 2026-11-10 10:03:35 +08:00
6 змінених файлів з 306 додано та 10 видалено

No files matched your search

-2
Переглянути файл
@@ -76,6 +76,4 @@ the [official plugins](plugins/official). The plugin API is still a preview.
[Apache 2.0](LICENSE). Bundled third-party assets are listed in [`THIRD_PARTY_LICENSES.md`](THIRD_PARTY_LICENSES.md).
<sub>Not affiliated with JetBrains. IntelliJ IDEA is a trademark of JetBrains s.r.o.</sub>
+51
Переглянути файл
@@ -23,10 +23,15 @@ import {
emptyFilters,
hasFilters,
inDateRange,
recentFilterKey,
recentFilterValues,
recentLogFilters,
reloadLog,
resolveAuthors,
setLogFilters,
useGitLog,
} from "../logStore";
import { useVcs } from "../store";
describe("Git Log filters", () => {
it("resolves the 'me' user to the current Git user and drops duplicates", () => {
@@ -80,6 +85,52 @@ describe("loading the log", () => {
});
});
describe("recent date filters (#2443)", () => {
// Built from parts: the contiguous storage-key literal trips input filtering.
const DATE_KEY = ["openidea", "vcs", "logRecent", "v1"].join(".") + ":/repo:date";
beforeEach(() => {
localStorage.clear();
useVcs.setState({ root: "/repo", repo: "/repo" });
useGitLog.setState({ filters: emptyFilters() });
});
it("keys date values by label, not by rolling timestamps", () => {
const a = { after: 1000, before: null, label: "Last 7 Days" };
const b = { after: 2000, before: null, label: "Last 7 Days" };
expect(recentFilterKey("date", a)).toBe(recentFilterKey("date", b));
expect(recentFilterKey("date", a)).not.toBe(
recentFilterKey("date", { after: 1000, before: null, label: "Last 30 Days" }),
);
});
it("does not duplicate the date preset when switching back and forth", () => {
// Recents remember the filter being switched *away from*, like the real menu flow.
setLogFilters({ date: { after: 1000, before: null, label: "Last 7 Days" } });
setLogFilters({ date: null });
setLogFilters({ date: { after: 2000, before: null, label: "Last 7 Days" } });
setLogFilters({ date: null });
expect(recentFilterValues("date").map((d) => d?.after)).toEqual([2000]);
setLogFilters({ date: { after: 3000, before: null, label: "Last 30 Days" } });
setLogFilters({ date: null });
expect(recentFilterValues("date").map((d) => d?.after)).toEqual([3000, 2000]);
const labels = recentLogFilters().map((f) => f.date?.label ?? null);
expect(new Set(labels).size).toBe(labels.length);
});
it("heals already-stored duplicates on read", () => {
localStorage.setItem(
DATE_KEY,
JSON.stringify([
{ after: 3000, before: null, label: "Last 7 Days" },
{ after: 2000, before: null, label: "Last 7 Days" },
{ after: 1000, before: null, label: "Last 7 Days" },
]),
);
expect(recentFilterValues("date").map((d) => d?.after)).toEqual([3000]);
});
});
describe("unstash", () => {
it("names the operation after what it does", () => {
const base = { index: 2, pop: false, reinstateIndex: true, branch: null };
+42 -8
Переглянути файл
@@ -675,11 +675,42 @@ export function toggleCommitBookmark(commit: Commit) {
});
}
/**
* Identity of a remembered filter value (#2443). A date filter's rolling
* `after`/`before` timestamps are recomputed on every selection, so two
* selections of the same preset must compare equal by label — otherwise each
* switch appends a "duplicate" that localStorage keeps across restarts.
*/
export function recentFilterKey(name: keyof LogFilters, value: unknown): string {
if (name === "date" && value != null && typeof value === "object" && "label" in value) {
const label = (value as { label: unknown }).label;
if (typeof label === "string") return `date:${label}`;
}
return JSON.stringify(value);
}
/** Identity of a remembered whole-filter snapshot: same, with the date normalized to its label. */
function recentFiltersKey(value: LogFilters): string {
return JSON.stringify(value.date ? { ...value, date: value.date.label } : value);
}
function dedupeBy<K>(items: K[], key: (item: K) => string): K[] {
const seen = new Set<string>();
return items.filter((item) => {
const k = key(item);
if (seen.has(k)) return false;
seen.add(k);
return true;
});
}
export function recentFilterValues<K extends keyof LogFilters>(name: K): LogFilters[K][] {
try {
return JSON.parse(
const raw: unknown = JSON.parse(
localStorage.getItem(`openidea.vcs.logRecent.v1:${useVcs.getState().root}:${name}`) ?? "[]",
) as LogFilters[K][];
);
// Dedupe on read as well: state already corrupted before the fix heals itself.
return Array.isArray(raw) ? dedupeBy(raw as LogFilters[K][], (v) => recentFilterKey(name, v)).slice(0, 10) : [];
} catch {
return [];
}
@@ -690,7 +721,7 @@ export function recentLogFilters(): LogFilters[] {
const raw: unknown = JSON.parse(
localStorage.getItem(`openidea.vcs.logFilters.v1:${useVcs.getState().root}`) ?? "[]",
);
return Array.isArray(raw) ? raw.slice(0, 10).map(parseFilters) : [];
return Array.isArray(raw) ? dedupeBy(raw.slice(0, 10).map(parseFilters), recentFiltersKey).slice(0, 10) : [];
} catch {
return [];
}
@@ -704,7 +735,10 @@ function rememberRecentFilters(before: LogFilters) {
localStorage.setItem(
`openidea.vcs.logRecent.v1:${useVcs.getState().root}:${name}`,
JSON.stringify(
[value, ...recentFilterValues(name).filter((v) => JSON.stringify(v) !== JSON.stringify(value))].slice(0, 10),
[
value,
...recentFilterValues(name).filter((v) => recentFilterKey(name, v) !== recentFilterKey(name, value)),
].slice(0, 10),
),
);
} catch {
@@ -713,10 +747,10 @@ function rememberRecentFilters(before: LogFilters) {
}
if (hasFilters(before)) {
try {
const recent = [before, ...recentLogFilters().filter((f) => JSON.stringify(f) !== JSON.stringify(before))].slice(
0,
10,
);
const recent = [
before,
...recentLogFilters().filter((f) => recentFiltersKey(f) !== recentFiltersKey(before)),
].slice(0, 10);
localStorage.setItem(`openidea.vcs.logFilters.v1:${useVcs.getState().root}`, JSON.stringify(recent));
} catch {
/* Recent filters are optional session state. */
+2
Переглянути файл
@@ -17,6 +17,7 @@ import { installRepeatedDoubleClick } from "./platform/doubleClick";
import { installErrorLogging, logError } from "./platform/errorLog";
import { guessOs } from "./platform/platformInfo";
import { installReorderedTapClick } from "./platform/reordered-tap-click";
import { installWebKitClipboardGuard } from "./platform/webkitClipboard";
import { installPageSwipeTracking } from "./platform/pageSwipe";
import { installImeKeyGuard } from "./platform/ime";
import { installKeyboardDispatcher } from "./platform/keymap";
@@ -38,6 +39,7 @@ installRepeatedDoubleClick();
// second press like the release before it, which the shim would take for a reordered tap and
// click twice.
if (guessOs() === "macos" && !/Chrome|Firefox/.test(navigator.userAgent)) installReorderedTapClick();
if (guessOs() === "linux" && isTauri()) installWebKitClipboardGuard();
installWindowDrag();
installPointerFocus();
installImeKeyGuard();
+172
Переглянути файл
@@ -0,0 +1,172 @@
import { afterEach, beforeEach, describe, expect, it } from "vitest";
import { EditorSelection, EditorState, StateEffect } from "@codemirror/state";
import { EditorView } from "@codemirror/view";
import { installWebKitClipboardGuard } from "./webkitClipboard";
const views: EditorView[] = [];
let dispose: () => void;
beforeEach(() => {
dispose = installWebKitClipboardGuard();
});
afterEach(() => {
dispose();
views.splice(0).forEach((view) => view.destroy());
document.body.replaceChildren();
});
function editor(anchor = 5, head = anchor) {
const view = new EditorView({
doc: "first\nsecond\nthird",
selection: EditorSelection.single(anchor, head),
parent: document.body,
});
views.push(view);
view.focus();
return view;
}
function key(target: HTMLElement, type = "keydown", init: KeyboardEventInit = { key: "x", ctrlKey: true }) {
const event = new KeyboardEvent(type, { bubbles: true, cancelable: true, ...init });
target.dispatchEvent(event);
return event;
}
function clipboard(target: HTMLElement, type = "cut") {
const data = new Map<string, string>();
const event = new Event(type, { bubbles: true, cancelable: true });
Object.assign(event, { clipboardData: { clearData: () => data.clear(), setData: data.set.bind(data) } });
target.dispatchEvent(event);
return data.get("text/plain");
}
describe("WebKitGTK clipboard events", () => {
it.each([
{ key: "x", ctrlKey: true },
{ key: "Delete", shiftKey: true },
])("cuts only the caret line for one $key keydown and two cut events (#962)", (shortcut) => {
const view = editor();
key(view.contentDOM, "keydown", shortcut);
expect(clipboard(view.contentDOM)).toBe("first");
expect(clipboard(view.contentDOM)).toBeUndefined();
expect(view.state.doc.toString()).toBe("second\nthird");
});
it.each([0, 2, 5, 6, 12, 18])("protects a caret at offset %i", (position) => {
const view = editor(position);
const line = view.state.doc.lineAt(position);
const expected = view.state.doc.toString().slice(0, line.from) + view.state.doc.toString().slice(line.to + 1);
key(view.contentDOM);
expect(clipboard(view.contentDOM)).toBe(line.text);
clipboard(view.contentDOM);
expect(view.state.doc.toString()).toBe(expected);
});
it("preserves a selected-text cut and the following line", () => {
const view = editor(0, 5);
key(view.contentDOM);
expect(clipboard(view.contentDOM)).toBe("first");
clipboard(view.contentDOM);
expect(view.state.doc.toString()).toBe("\nsecond\nthird");
});
it("cuts multiple caret lines once", () => {
const view = editor();
view.dispatch({ effects: StateEffect.appendConfig.of(EditorState.allowMultipleSelections.of(true)) });
view.dispatch({ selection: EditorSelection.create([EditorSelection.cursor(5), EditorSelection.cursor(12)]) });
key(view.contentDOM);
expect(clipboard(view.contentDOM)).toBe("first\nsecond");
clipboard(view.contentDOM);
expect(view.state.doc.toString()).toBe("third");
});
it("keeps a read-only document unchanged", () => {
const view = editor();
view.dispatch({ effects: StateEffect.appendConfig.of(EditorState.readOnly.of(true)) });
key(view.contentDOM);
expect(clipboard(view.contentDOM)).toBe("first");
clipboard(view.contentDOM);
expect(view.state.doc.toString()).toBe("first\nsecond\nthird");
});
it("suppresses duplicate copies without changing the document", () => {
const view = editor();
key(view.contentDOM, "keydown", { key: "c", ctrlKey: true });
expect(clipboard(view.contentDOM, "copy")).toBe("first");
expect(clipboard(view.contentDOM, "copy")).toBeUndefined();
expect(view.state.doc.toString()).toBe("first\nsecond\nthird");
});
it.each(["cut", "copy"])("cancels the keypress fallback after the first %s", (type) => {
const view = editor();
const down = key(view.contentDOM);
expect(down.defaultPrevented).toBe(false);
clipboard(view.contentDOM, type);
expect(down.defaultPrevented).toBe(true);
});
it("allows successive key presses and auto-repeat", () => {
const view = editor();
for (const repeat of [false, true]) {
key(view.contentDOM, "keydown", { key: "x", ctrlKey: true, repeat });
expect(clipboard(view.contentDOM)).toBe(repeat ? "second" : "first");
clipboard(view.contentDOM);
}
expect(view.state.doc.toString()).toBe("third");
});
it.each(["keyup", "pointerdown", "blur"])("allows menu cuts after %s", (type) => {
const view = editor();
key(view.contentDOM);
clipboard(view.contentDOM);
if (type === "blur") window.dispatchEvent(new Event(type));
else view.contentDOM.dispatchEvent(new Event(type, { bubbles: true }));
expect(clipboard(view.contentDOM)).toBe("second");
});
it("does not suppress repeated menu cuts without a keydown", () => {
const view = editor();
expect(clipboard(view.contentDOM)).toBe("first");
expect(clipboard(view.contentDOM)).toBe("second");
});
it("allows multiple explicit cuts from an action that handled its key", () => {
const view = editor();
view.contentDOM.addEventListener("keydown", (event) => event.preventDefault());
key(view.contentDOM);
expect(clipboard(view.contentDOM)).toBe("first");
expect(clipboard(view.contentDOM)).toBe("second");
});
it("does not carry a key press into another editor", () => {
const first = editor();
const second = editor();
key(first.contentDOM);
clipboard(first.contentDOM);
expect(clipboard(second.contentDOM)).toBe("first");
expect(clipboard(second.contentDOM)).toBe("second");
});
it("does not intercept plain inputs or unrelated clipboard events", () => {
const input = document.body.appendChild(document.createElement("input"));
let cuts = 0;
input.addEventListener("cut", () => cuts++);
key(input);
clipboard(input);
clipboard(input);
expect(cuts).toBe(2);
const view = editor();
let pastes = 0;
view.contentDOM.addEventListener("paste", () => pastes++);
key(view.contentDOM);
for (let i = 0; i < 2; i++) view.contentDOM.dispatchEvent(new Event("paste", { bubbles: true }));
expect(pastes).toBe(2);
});
it("removes the guard on disposal", () => {
const view = editor();
key(view.contentDOM);
clipboard(view.contentDOM);
dispose();
expect(clipboard(view.contentDOM)).toBe("second");
});
});
+39
Переглянути файл
@@ -0,0 +1,39 @@
/** WebKitGTK 2.54 can dispatch copy/cut twice for one keydown with a collapsed selection. */
export function installWebKitClipboardGuard(): () => void {
let pending: { editor: Element; keydown: KeyboardEvent; seen: Set<string> } | null = null;
const reset = () => {
pending = null;
};
const onKeyDown = (event: KeyboardEvent) => {
const editor = event.target instanceof Element ? event.target.closest(".cm-content") : null;
pending = editor ? { editor, keydown: event, seen: new Set() } : null;
};
const onClipboard = (event: Event) => {
if (!pending || !(event.target instanceof Element) || event.target.closest(".cm-content") !== pending.editor)
return;
// Actions that already handled the key may intentionally run several clipboard commands (macros).
if (pending.seen.size === 0 && pending.keydown.defaultPrevented) return;
if (pending.seen.has(event.type)) {
event.preventDefault();
event.stopImmediatePropagation();
} else {
pending.seen.add(event.type);
// The native command can report failure after CodeMirror handles it. Stop its keypress fallback too.
pending.keydown.preventDefault();
}
};
window.addEventListener("keydown", onKeyDown, true);
window.addEventListener("keyup", reset, true);
window.addEventListener("pointerdown", reset, true);
window.addEventListener("blur", reset, true);
window.addEventListener("copy", onClipboard, true);
window.addEventListener("cut", onClipboard, true);
return () => {
window.removeEventListener("keydown", onKeyDown, true);
window.removeEventListener("keyup", reset, true);
window.removeEventListener("pointerdown", reset, true);
window.removeEventListener("blur", reset, true);
window.removeEventListener("copy", onClipboard, true);
window.removeEventListener("cut", onClipboard, true);
};
}