mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-04-23 09:18:30 +02:00
Editor line wrapping support (not used yet)
This commit is contained in:
@@ -35,6 +35,7 @@ export interface EditorProps {
|
|||||||
onFocus?: () => void;
|
onFocus?: () => void;
|
||||||
onBlur?: () => void;
|
onBlur?: () => void;
|
||||||
singleLine?: boolean;
|
singleLine?: boolean;
|
||||||
|
wrapLines?: boolean;
|
||||||
format?: (v: string) => string;
|
format?: (v: string) => string;
|
||||||
autocomplete?: GenericCompletionConfig;
|
autocomplete?: GenericCompletionConfig;
|
||||||
actions?: ReactNode;
|
actions?: ReactNode;
|
||||||
@@ -59,6 +60,7 @@ const _Editor = forwardRef<EditorView | undefined, EditorProps>(function Editor(
|
|||||||
format,
|
format,
|
||||||
autocomplete,
|
autocomplete,
|
||||||
actions,
|
actions,
|
||||||
|
wrapLines,
|
||||||
}: EditorProps,
|
}: EditorProps,
|
||||||
ref,
|
ref,
|
||||||
) {
|
) {
|
||||||
@@ -93,6 +95,15 @@ const _Editor = forwardRef<EditorView | undefined, EditorProps>(function Editor(
|
|||||||
cm.current?.view.dispatch({ effects: effect });
|
cm.current?.view.dispatch({ effects: effect });
|
||||||
}, [placeholder]);
|
}, [placeholder]);
|
||||||
|
|
||||||
|
// Update wrap lines
|
||||||
|
const wrapLinesCompartment = useRef(new Compartment());
|
||||||
|
useEffect(() => {
|
||||||
|
if (cm.current === null) return;
|
||||||
|
const ext = wrapLines ? [EditorView.lineWrapping] : [];
|
||||||
|
const effect = wrapLinesCompartment.current.reconfigure(ext);
|
||||||
|
cm.current?.view.dispatch({ effects: effect });
|
||||||
|
}, [wrapLines]);
|
||||||
|
|
||||||
// Update language extension when contentType changes
|
// Update language extension when contentType changes
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (cm.current === null) return;
|
if (cm.current === null) return;
|
||||||
@@ -126,16 +137,15 @@ const _Editor = forwardRef<EditorView | undefined, EditorProps>(function Editor(
|
|||||||
doc: `${defaultValue ?? ''}`,
|
doc: `${defaultValue ?? ''}`,
|
||||||
extensions: [
|
extensions: [
|
||||||
languageCompartment.of(langExt),
|
languageCompartment.of(langExt),
|
||||||
placeholderCompartment.current.of(
|
placeholderCompartment.current.of([]),
|
||||||
placeholderExt(placeholderElFromText(placeholder ?? '')),
|
wrapLinesCompartment.current.of([]),
|
||||||
),
|
|
||||||
...getExtensions({
|
...getExtensions({
|
||||||
container,
|
container,
|
||||||
|
readOnly,
|
||||||
|
singleLine,
|
||||||
onChange: handleChange,
|
onChange: handleChange,
|
||||||
onFocus: handleFocus,
|
onFocus: handleFocus,
|
||||||
onBlur: handleBlur,
|
onBlur: handleBlur,
|
||||||
readOnly,
|
|
||||||
singleLine,
|
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user