Skip to content

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

web: fix RTL support for outline lists (#2175)

Muhammad Ali27863def9c8d
diff --git a/packages/editor/src/extensions/outline-list-item/outline-list-item.ts b/packages/editor/src/extensions/outline-list-item/outline-list-item.ts
index cef020848..0d270c65e 100644
--- a/packages/editor/src/extensions/outline-list-item/outline-list-item.ts
+++ b/packages/editor/src/extensions/outline-list-item/outline-list-item.ts
@@ -17,7 +17,13 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-import { Node, mergeAttributes, findChildren, Editor } from "@tiptap/core";
+import {
+ Node,
+ mergeAttributes,
+ findChildren,
+ Editor,
+ findParentNode
+} from "@tiptap/core";
import { NodeType } from "prosemirror-model";
import { findParentNodeOfTypeClosestToPos } from "../../utils/prosemirror";
import { onArrowUpPressed, onBackspacePressed } from "../list-item/commands";
@@ -140,20 +146,32 @@ export const OutlineListItem = Node.create<ListItemOptions>({
if (!(e.target instanceof HTMLParagraphElement)) return;
if (!li.classList.contains("nested")) return;
+ const { x, y, right } = li.getBoundingClientRect();
+
const clientX =
e instanceof MouseEvent ? e.clientX : e.touches[0].clientX;
+
const clientY =
e instanceof MouseEvent ? e.clientY : e.touches[0].clientY;
- const { x, y } = li.getBoundingClientRect();
-
const hitArea = { width: 26, height: 24 };
- if (
- clientX >= x - hitArea.width &&
- clientX <= x &&
- clientY >= y &&
- clientY <= y + hitArea.height
- ) {
+
+ const selection = editor.state.selection;
+ const parent = findParentNode((node) => !!node.attrs.textDirection)(
+ selection
+ );
+
+ let xStart = clientX >= x - hitArea.width;
+ let xEnd = clientX <= x;
+ const yStart = clientY >= y;
+ const yEnd = clientY <= y + hitArea.height;
+
+ if (parent && parent.node.attrs.textDirection === "rtl") {
+ xEnd = clientX <= right + hitArea.width;
+ xStart = clientX >= right;
+ }
+
+ if (xStart && xEnd && yStart && yEnd) {
const pos = typeof getPos === "function" ? getPos() : 0;
if (!pos) return;
diff --git a/packages/editor/src/extensions/outline-list/outline-list.ts b/packages/editor/src/extensions/outline-list/outline-list.ts
index e263fad51..28dbd1a36 100644
--- a/packages/editor/src/extensions/outline-list/outline-list.ts
+++ b/packages/editor/src/extensions/outline-list/outline-list.ts
@@ -134,9 +134,10 @@ export const OutlineList = Node.create<OutlineListOptions>({
},
addNodeView() {
- return () => {
+ return ({ node }) => {
const ul = document.createElement("ul");
ul.classList.add("outline-list");
+ if (node.attrs.textDirection) ul.dir = node.attrs.textDirection;
return {
dom: ul,
contentDOM: ul
diff --git a/packages/editor/src/extensions/text-direction/text-direction.ts b/packages/editor/src/extensions/text-direction/text-direction.ts
index 09a4a33ec..14f40b960 100644
--- a/packages/editor/src/extensions/text-direction/text-direction.ts
+++ b/packages/editor/src/extensions/text-direction/text-direction.ts
@@ -17,8 +17,11 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+import { isListActive } from "../../utils/prosemirror";
import { Extension, Editor, findParentNode } from "@tiptap/core";
import "@tiptap/extension-text-style";
+import { Paragraph } from "../paragraph";
+import { Node as ProsemirrorNode } from "@tiptap/pm/model";
export type TextDirections = undefined | "rtl";
const TEXT_DIRECTION_TYPES = [
@@ -52,19 +55,21 @@ declare module "@tiptap/core" {
export function getTextDirection(editor: Editor): TextDirections {
const selection = editor.state.selection;
- const { $anchor } = selection;
- const selectedNode = editor.state.doc.nodeAt($anchor.pos);
- if (!!selectedNode && !!selectedNode.attrs.textDirection)
- return selectedNode.attrs.textDirection;
-
- const parent = findParentNode((node) => !!node.attrs.textDirection)(
- selection
- );
+ const parent = findParentNode(
+ (node) =>
+ !!node.attrs.textDirection && !isTextDirectionIgnored(editor, node)
+ )(selection);
if (!parent) return;
return parent.node.attrs.textDirection;
}
+function isTextDirectionIgnored(editor: Editor, node: ProsemirrorNode) {
+ const isInsideList = isListActive(editor);
+ const isParagraph = node.type.name === Paragraph.name;
+ return isInsideList && isParagraph;
+}
+
export const TextDirection = Extension.create<TextDirectionOptions>({
name: "textDirection",
diff --git a/packages/editor/styles/styles.css b/packages/editor/styles/styles.css
index 027fbe94c..2db06de0e 100644
--- a/packages/editor/styles/styles.css
+++ b/packages/editor/styles/styles.css
@@ -27,8 +27,8 @@
padding-bottom: 10px;
cursor: pointer;
position: relative;
- margin-top: 4px;
- margin-bottom:-10px;
+ margin-top: 4px;
+ margin-bottom: -10px;
}
.ProseMirror hr::after {
@@ -503,7 +503,6 @@ p > *::selection {
.outline-list li > p::before {
position: absolute;
top: 4px;
- left: -22px;
cursor: pointer;
content: "";
background-size: 18px;
@@ -518,6 +517,7 @@ p > *::selection {
transform: rotate(0);
transition: transform 250ms ease;
+ left: -22px;
}
.outline-list li:not(.nested) > p::before {
@@ -530,23 +530,25 @@ p > *::selection {
transform: rotate(-90deg);
}
+
.outline-list li .outline-list::before {
content: " ";
position: absolute;
height: 100%;
+ transition: border 200ms ease-in-out;
left: -14px;
border-left: 1px solid var(--border);
- transition: border 200ms ease-in-out;
}
.outline-list li .outline-list:hover:before {
border-left: 1px solid var(--bgSecondaryHover);
}
+
/* IMAGE */
.image-view-content-wrap.ProseMirror-selectednode .resizer::before {
- content: '';
+ content: "";
position: absolute;
top: 0;
left: 0;
@@ -574,14 +576,24 @@ blockquote[dir="rtl"] {
padding-right: 15px;
}
-.outline-list-item-toggle.rtl {
- display: none;
+
+.outline-list[dir="rtl"] li > p::before {
+ right: -22px;
+ left: unset;
}
-[dir="rtl"] .outline-list-item-toggle.rtl {
- display: block;
+.outline-list[dir="rtl"] li .outline-list::before {
+ border-left: unset;
+ border-right: 1px solid var(--border);
+ left: unset;
+ right: -14px;
}
-[dir="rtl"] .outline-list-item-toggle:not(.rtl) {
- display: none;
+.outline-list[dir="rtl"] li .outline-list:hover:before {
+ border-right: 1px solid var(--bgSecondaryHover);
+ border-left: unset;
+}
+
+.outline-list[dir="rtl"] li.collapsed > p::before {
+ transform: rotate(90deg);
}