editor: fix unable to change text direction if default is rtl

Signed-off-by: 01zulfi <85733202+01zulfi@users.noreply.github.com>
This commit is contained in:
01zulfi
2026-01-19 15:58:17 +05:00
parent e899e69410
commit 7d4fe9127c
2 changed files with 11 additions and 8 deletions

View File

@@ -23,7 +23,7 @@ import { Paragraph } from "../paragraph/index.js";
import { Node as ProsemirrorNode } from "@tiptap/pm/model";
import { isListActive } from "../../utils/list.js";
export type TextDirections = undefined | "rtl";
export type TextDirections = undefined | "rtl" | "ltr";
const TEXT_DIRECTION_TYPES = [
"paragraph",
"heading",
@@ -90,13 +90,15 @@ export const TextDirection = Extension.create<TextDirectionOptions>({
// NOTE: for some reason setting this to undefined breaks enter behaviour
// on Android for some keyboards (GBoard etc.). Empty string works fine.
default: this.options.defaultDirection || "",
parseHTML: (element) => (element.dir === "rtl" ? "rtl" : undefined),
parseHTML: (element) =>
element.dir === "rtl"
? "rtl"
: element.dir === "ltr"
? "ltr"
: undefined,
keepOnSplit: true,
renderHTML: (attributes) => {
if (
!attributes.textDirection ||
attributes.textDirection !== "rtl"
) {
if (!attributes.textDirection) {
return {};
}

View File

@@ -51,9 +51,10 @@ export function TextDirection(props: ToolProps) {
const { editor } = props;
const textDirection = getTextDirection(editor);
const newTextDirection: TextDirections = textDirection ? undefined : "rtl";
const newTextDirection: TextDirections =
textDirection === "rtl" ? "ltr" : "rtl";
const icon: IconNames = textDirection ? "rtl" : "ltr";
const icon: IconNames = textDirection === "rtl" ? "rtl" : "ltr";
return (
<TextDirectionTool direction={newTextDirection} {...props} icon={icon} />