дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-06 18:17:15 +02:00
The pull request timeline and diff-thread comment fields and the Submit Review field use the editor-based TextField the commit message uses, so Vim attaches when Vim mode is on. Escape first leaves Insert or Visual mode, and in Normal mode or with Vim off cancels the comment as before; the @mention list keeps its keys ahead of Vim. TextField gains readOnly, onSelectionChange and onKeyDownFirst.
27 рядки
881 B
TypeScript
27 рядки
881 B
TypeScript
import { act } from "@testing-library/react";
|
|
import { EditorView } from "@codemirror/view";
|
|
|
|
function viewOf(field: HTMLElement): EditorView {
|
|
const dom = field.closest<HTMLElement>(".cm-editor");
|
|
const view = dom && EditorView.findFromDOM(dom);
|
|
if (!view) throw new Error("not an editor-based field");
|
|
return view;
|
|
}
|
|
|
|
/** Replaces the text of an editor-based field (`src/editor/TextField.tsx`) as typing would. */
|
|
export function setFieldText(field: HTMLElement, text: string) {
|
|
const view = viewOf(field);
|
|
act(() => {
|
|
view.dispatch({
|
|
changes: { from: 0, to: view.state.doc.length, insert: text },
|
|
selection: { anchor: text.length },
|
|
userEvent: "input.type",
|
|
});
|
|
});
|
|
}
|
|
|
|
/** The text of an editor-based field, as a textarea's value. */
|
|
export function fieldValue(field: HTMLElement): string {
|
|
return viewOf(field).state.doc.toString();
|
|
}
|