fix: out of range error due to rerender
This commit is contained in:
parent
dc2ff83fa5
commit
bd8ad1ed1b
1 changed files with 4 additions and 2 deletions
|
|
@ -20,7 +20,7 @@ const flashField = StateField.define({
|
||||||
try {
|
try {
|
||||||
for (let e of tr.effects) {
|
for (let e of tr.effects) {
|
||||||
if (e.is(setFlash)) {
|
if (e.is(setFlash)) {
|
||||||
if (e.value) {
|
if (e.value && tr.newDoc?.length?.length > 0) {
|
||||||
const mark = Decoration.mark({ attributes: { style: `background-color: #FFCA2880` } });
|
const mark = Decoration.mark({ attributes: { style: `background-color: #FFCA2880` } });
|
||||||
flash = Decoration.set([mark.range(0, tr.newDoc.length)]);
|
flash = Decoration.set([mark.range(0, tr.newDoc.length)]);
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -152,6 +152,8 @@ export default function CodeMirror({
|
||||||
return _extensions;
|
return _extensions;
|
||||||
}, [keybindings, isAutoCompletionEnabled, isLineWrappingEnabled]);
|
}, [keybindings, isAutoCompletionEnabled, isLineWrappingEnabled]);
|
||||||
|
|
||||||
|
const basicSetup = useMemo(() => ({ lineNumbers: isLineNumbersDisplayed }), [isLineNumbersDisplayed]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div style={{ fontSize, fontFamily }} className="w-full">
|
<div style={{ fontSize, fontFamily }} className="w-full">
|
||||||
<_CodeMirror
|
<_CodeMirror
|
||||||
|
|
@ -161,7 +163,7 @@ export default function CodeMirror({
|
||||||
onCreateEditor={handleOnCreateEditor}
|
onCreateEditor={handleOnCreateEditor}
|
||||||
onUpdate={handleOnUpdate}
|
onUpdate={handleOnUpdate}
|
||||||
extensions={extensions}
|
extensions={extensions}
|
||||||
basicSetup={{ lineNumbers: isLineNumbersDisplayed }}
|
basicSetup={basicSetup}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue