mirror of
https://github.com/streetwriters/notesnook.git
synced 2026-02-24 04:00:59 +01:00
fix: scroll jumps when sticking/unsticking toolbar
This commit is contained in:
@@ -16,7 +16,7 @@ import Banner from "../banner";
|
||||
import EditorLoading from "./loading";
|
||||
|
||||
const ReactMCE = React.lazy(() => import("./tinymce"));
|
||||
var isToolbarSticky = false;
|
||||
|
||||
function Editor(props) {
|
||||
const editorRef = useRef();
|
||||
const sessionState = useStore((store) => store.session.state);
|
||||
@@ -89,19 +89,25 @@ function Editor(props) {
|
||||
const title = document.querySelector(".editorTitle");
|
||||
const headerOffset = title.scrollHeight;
|
||||
const hideOffset = headerOffset + 60;
|
||||
if (e.target.scrollTop > hideOffset && !isToolbarSticky) {
|
||||
const { editor } = editorRef.current;
|
||||
if (e.target.scrollTop > hideOffset && !editor.isToolbarSticky) {
|
||||
editor.pauseScrollIntoView = true;
|
||||
const toolbar = document.querySelector(".tox-editor-header");
|
||||
toolbar.style.position = "fixed";
|
||||
toolbar.style.top = "40px";
|
||||
toolbar.style.bottom = "auto";
|
||||
toolbar.style.width = `${title.clientWidth}px`;
|
||||
isToolbarSticky = true;
|
||||
} else if (e.target.scrollTop <= hideOffset && isToolbarSticky) {
|
||||
editor.isToolbarSticky = true;
|
||||
} else if (
|
||||
e.target.scrollTop <= hideOffset &&
|
||||
editor.isToolbarSticky
|
||||
) {
|
||||
editor.pauseScrollIntoView = true;
|
||||
const toolbar = document.querySelector(".tox-editor-header");
|
||||
toolbar.style.position = "relative";
|
||||
toolbar.style.top = "0px";
|
||||
toolbar.style.bottom = "0px";
|
||||
isToolbarSticky = false;
|
||||
toolbar.style.bottom = "auto";
|
||||
editor.isToolbarSticky = false;
|
||||
}
|
||||
}}
|
||||
>
|
||||
|
||||
@@ -175,6 +175,14 @@ function TinyMCE(props) {
|
||||
"data:" + blobInfo.blob().type + ";base64," + blobInfo.base64()
|
||||
);
|
||||
},
|
||||
setup: (editor) => {
|
||||
editor.on("ScrollIntoView", (e) => {
|
||||
if (editor.pauseScrollIntoView) {
|
||||
e.preventDefault();
|
||||
editor.pauseScrollIntoView = false;
|
||||
}
|
||||
});
|
||||
},
|
||||
}}
|
||||
// onBeforeExecCommand={async (command) => {
|
||||
// if (
|
||||
|
||||
Reference in New Issue
Block a user