Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

web: fix editor text not selectable from margins (#4292)

Muhammad Alicb353358b7c2
diff --git a/apps/web/src/components/editor/index.tsx b/apps/web/src/components/editor/index.tsx
index 51f6785b8..b6eaadaee 100644
--- a/apps/web/src/components/editor/index.tsx
+++ b/apps/web/src/components/editor/index.tsx
@@ -54,7 +54,7 @@ import { ScopedThemeProvider } from "../theme-provider";
import { Lightbox } from "../lightbox";
import { Allotment } from "allotment";
import { showToast } from "../../utils/toast";
-import { getFormattedDate } from "@notesnook/common";
+import { debounce, getFormattedDate } from "@notesnook/common";
const PDFPreview = React.lazy(() => import("../pdf-preview"));
@@ -445,6 +445,38 @@ function EditorChrome(
isMobile: false
};
const editorMargins = useStore((store) => store.editorMargins);
+ const editorContainerRef = useRef<HTMLElement>(null);
+ const editorScrollRef = useRef<HTMLElement>(null);
+
+ useEffect(() => {
+ if (!editorScrollRef.current) return;
+ function onResize(
+ entries: ResizeObserverEntry[],
+ _observer: ResizeObserver
+ ) {
+ const editor = editorContainerRef.current?.querySelector(
+ ".ProseMirror"
+ ) as HTMLElement | undefined;
+ const parent = editorScrollRef.current?.getBoundingClientRect();
+ const child = editorContainerRef.current?.getBoundingClientRect();
+ if (!parent || !child || !editor || entries.length <= 0) return;
+
+ const CONTAINER_MARGIN = 30;
+ const negativeSpace = Math.abs(
+ parent.left - child.left - CONTAINER_MARGIN
+ );
+
+ editor.style.marginLeft = `-${negativeSpace}px`;
+ editor.style.marginRight = `-${negativeSpace}px`;
+ editor.style.paddingLeft = `${negativeSpace}px`;
+ editor.style.paddingRight = `${negativeSpace}px`;
+ }
+ const observer = new ResizeObserver(debounce(onResize, 500));
+ observer.observe(editorScrollRef.current);
+ return () => {
+ observer.disconnect();
+ };
+ }, []);
if (headless) return <>{children}</>;
@@ -469,10 +501,12 @@ function EditorChrome(
<Toolbar />
<FlexScrollContainer
+ scrollRef={editorScrollRef}
className="editorScroll"
style={{ display: "flex", flexDirection: "column", flex: 1 }}
>
<Flex
+ ref={editorContainerRef}
variant="columnFill"
className="editor"
sx={{
@@ -481,7 +515,7 @@ function EditorChrome(
width: "100%"
}}
pl={6}
- pr={2}
+ pr={6}
onClick={onRequestFocus}
>
{!isMobile && (
diff --git a/apps/web/src/components/scroll-container/index.tsx b/apps/web/src/components/scroll-container/index.tsx
index 95ef35c15..1a0e5fd06 100644
--- a/apps/web/src/components/scroll-container/index.tsx
+++ b/apps/web/src/components/scroll-container/index.tsx
@@ -54,6 +54,7 @@ type FlexScrollContainerProps = {
id?: string;
className?: string;
style?: React.CSSProperties;
+ scrollRef?: React.Ref<HTMLElement>;
} & MacScrollbarProps;
export function FlexScrollContainer({
@@ -61,11 +62,13 @@ export function FlexScrollContainer({
children,
style,
className,
+ scrollRef,
...restProps
}: PropsWithChildren<FlexScrollContainerProps>) {
return (
<MacScrollbar
{...restProps}
+ ref={scrollRef}
id={id}
className={className}
style={style}