дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-04 09:11:10 +02:00
Wheel-scrolling a diff in WebKit could jump scrollTop backwards and loop, so the bottom was unreachable. - collapsedDiffLines replaced the separator row's children synchronously in docViewUpdate, before layout flushed; WebKit then clamped scrollTop back whenever a collapsed-lines separator entered the viewport. The replacement now runs in a keyed requestMeasure write phase. - In synchronized side-by-side diffs (PaddedPanes / UnalignedPanes), the follower's measure-driven scrollTop adjustments were read as user scrolls and followed in reverse. The wheeled pane now leads for 150 ms after its last wheel event (released on pointerdown), and non-document height changes refresh the expected echo offsets. Covers the split aligned, split unaligned and unified views.
35 рядки
1.6 KiB
TypeScript
35 рядки
1.6 KiB
TypeScript
import { EditorState, type Extension } from "@codemirror/state";
|
|
import { ViewPlugin } from "@codemirror/view";
|
|
import { tx } from "@/platform/i18n";
|
|
import { iconNode } from "@/ui/iconNode";
|
|
|
|
const collapseButtons = ViewPlugin.define((view) => {
|
|
const enhance = () => {
|
|
for (const row of view.contentDOM.querySelectorAll(".cm-collapsedLines")) {
|
|
if (row.firstElementChild) continue;
|
|
const button = view.dom.ownerDocument.createElement("button");
|
|
button.type = "button";
|
|
button.title = tx("Expand unchanged lines");
|
|
button.setAttribute("aria-expanded", "false");
|
|
const label = view.dom.ownerDocument.createElement("span");
|
|
label.className = "cm-diffCollapseLabel";
|
|
label.textContent = row.textContent;
|
|
button.append(iconNode("chevron-down", 14), label);
|
|
button.addEventListener("click", () => view.focus());
|
|
// The existing widget handles the bubbled click and expands the matching range in both panes.
|
|
row.replaceChildren(button);
|
|
}
|
|
};
|
|
// Defer DOM replacement into CodeMirror's measure write phase rather than mutating synchronously
|
|
// during docViewUpdate: in WebKit, inserting the inline SVG while updated viewport gaps have not
|
|
// flushed layout yet causes scrollTop to clamp backwards and trap wheel scrolling in a loop.
|
|
const measure = { key: enhance, read: () => null, write: enhance };
|
|
const schedule = () => view.requestMeasure(measure);
|
|
schedule();
|
|
return { docViewUpdate: schedule };
|
|
});
|
|
|
|
export function collapsedDiffLines(): Extension {
|
|
return [EditorState.phrases.of({ "$ unchanged lines": tx("$ unchanged lines") }), collapseButtons];
|
|
}
|