0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2026-05-07 18:48:39 +00:00

handle scroll remake

This commit is contained in:
Víctor Losada Hernández
2026-04-12 23:42:20 +02:00
parent 5a778ad4e6
commit ed5e5004e0
2 changed files with 28 additions and 31 deletions
+28 -8
View File
@@ -129,12 +129,6 @@ const CodeEditor = forwardRef(
onCursorChange(line);
}
if(update.viewportChanged) {
const { from } = update.view.viewport;
const line = update.state.doc.lineAt(from).number;
onViewChange(line);
}
});
const highlightExtension = renderer === 'V3'
@@ -169,7 +163,7 @@ const CodeEditor = forwardRef(
themeCompartment.of(themeExtension),
highlightActiveLine(),
highlightActiveLineGutter(),
//keyboard shortcut
keymap.of([...defaultKeymap, foldKeymap, ...searchKeymap]),
generalKeymap,
@@ -195,9 +189,35 @@ const CodeEditor = forwardRef(
parent : editorRef.current,
});
const view = viewRef.current;
let ticking = false;
const handleScroll = ()=>{
if(ticking) return;
ticking = true;
requestAnimationFrame(()=>{
const view = viewRef.current;
if(!view?.scrollDOM) return;
const top = view.scrollDOM.scrollTop;
const block = view.lineBlockAtHeight(top);
const line = view.state.doc.lineAt(block.from).number;
onViewChange(line);
ticking = false;
});
};
view.scrollDOM.addEventListener('scroll', handleScroll);
docsRef.current[tab] = state;
return ()=>viewRef.current?.destroy();
return ()=>{
view.scrollDOM.removeEventListener('scroll', handleScroll);
viewRef.current?.destroy();
};
}, []);
useEffect(()=>{