Files
openidea/src/workbench/softWrap.ts
T
ovra e86134ce83 feat(vcs): soft-wrap long lines in the diff viewer (#2286)
The diff viewer never soft-wrapped, so a long changed line ran off the right edge. Diff panes now follow Settings › Editor › General › Soft-wrap files for the file, and the viewer's settings menu has a Use Soft Wraps checkbox that overrides it for all diffs and is remembered with the other viewer options. View › Active Editor › Soft-Wrap (editor.toggleSoftWrap) also toggles it when a diff pane has focus. Toggling reconfigures both panes in place, keeping the selection and the scroll position, including aligned split diffs.

Closes #2263

Co-authored-by: atlas-u <167598036+atlas-u@users.noreply.github.com>
2026-11-09 17:03:21 +08:00

40 lines
1.2 KiB
TypeScript

/** Soft-wrap action targets outside the regular editor, retained while its menus are open. */
import { getContext, setContext } from "@/platform/context";
interface SoftWrapSurface {
enabled(): boolean;
toggle(): void;
}
let focused: SoftWrapSurface | null = null;
export function focusedSoftWrapSurface(): SoftWrapSurface | null {
return focused;
}
export function registerSoftWrapSurface(host: HTMLElement, surface: SoftWrapSurface): () => void {
const focus = (target: Element | null) => {
if (target && host.contains(target)) {
focused = surface;
setContext("softWrapSurfaceFocus", true);
} else if (
focused === surface &&
!getContext().popupOpen &&
!target?.closest('[role="menu"], [role="menubar"], [aria-haspopup="menu"]')
) {
focused = null;
setContext("softWrapSurfaceFocus", false);
}
};
const onFocus = (event: FocusEvent) => focus(event.target instanceof Element ? event.target : null);
document.addEventListener("focusin", onFocus);
focus(document.activeElement);
return () => {
document.removeEventListener("focusin", onFocus);
if (focused === surface) {
focused = null;
setContext("softWrapSurfaceFocus", false);
}
};
}