Skip to content

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

editor: use default scroll container on mobile to fix selection bugs

Ammar Ahmedfb778f56eda7
diff --git a/packages/editor/src/extensions/table/component.tsx b/packages/editor/src/extensions/table/component.tsx
index dec310723..7852f395a 100644
--- a/packages/editor/src/extensions/table/component.tsx
+++ b/packages/editor/src/extensions/table/component.tsx
@@ -22,7 +22,7 @@ import { ReactNodeView, ReactNodeViewProps } from "../react/index.js";
import { Node as ProsemirrorNode } from "prosemirror-model";
import { Editor } from "../../types.js";
import { Editor as TiptapEditor } from "@tiptap/core";
-import { useEffect, useRef } from "react";
+import { useCallback, useEffect, useRef } from "react";
import { updateColumnsOnResize } from "@tiptap/pm/tables";
import { EditorView, NodeView } from "prosemirror-view";
import {
@@ -32,7 +32,7 @@ import {
TableProperties
} from "../../toolbar/tools/table.js";
import { getToolDefinition } from "../../toolbar/tool-definitions.js";
-import { getPosition } from "@notesnook/ui";
+import { getPosition, ScrollContainer } from "@notesnook/ui";
import {
findSelectedDOMNode,
hasSameAttributes
@@ -41,12 +41,14 @@ import { DesktopOnly } from "../../components/responsive/index.js";
import { TextDirections } from "../text-direction/index.js";
import { strings } from "@notesnook/intl";
import SimpleBar from "simplebar-react";
+import { useIsMobile } from "../../toolbar/stores/toolbar-store.js";
export function TableComponent(props: ReactNodeViewProps) {
const { editor, node, forwardRef } = props;
const colgroupRef = useRef<HTMLTableColElement>(null);
const tableRef = useRef<HTMLTableElement>();
const { textDirection } = node.attrs;
+ const isMobile = useIsMobile();
useEffect(() => {
if (!colgroupRef.current || !tableRef.current) return;
@@ -54,6 +56,22 @@ export function TableComponent(props: ReactNodeViewProps) {
updateColumnsOnResize(node, colgroupRef.current, tableRef.current, 50);
}, [node]);
+ const renderScrollContent = useCallback(() => {
+ return (
+ <div dir={textDirection}>
+ <table
+ ref={(ref) => {
+ forwardRef?.(ref);
+ tableRef.current = ref || undefined;
+ }}
+ >
+ <colgroup ref={colgroupRef} />
+ {/* <tbody /> */}
+ </table>
+ </div>
+ );
+ }, [forwardRef, textDirection]);
+
return (
<>
<DesktopOnly>
@@ -68,19 +86,12 @@ export function TableComponent(props: ReactNodeViewProps) {
textDirection={textDirection}
/>
</DesktopOnly>
- <SimpleBar autoHide>
- <Box dir={textDirection}>
- <table
- ref={(ref) => {
- forwardRef?.(ref);
- tableRef.current = ref || undefined;
- }}
- >
- <colgroup ref={colgroupRef} />
- {/* <tbody /> */}
- </table>
- </Box>
- </SimpleBar>
+
+ {isMobile ? (
+ <ScrollContainer>{renderScrollContent()}</ScrollContainer>
+ ) : (
+ <SimpleBar>{renderScrollContent()}</SimpleBar>
+ )}
</>
);
}