mirror of
https://github.com/streetwriters/notesnook.git
synced 2026-02-23 19:49:56 +01:00
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:
@@ -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 {};
|
||||
}
|
||||
|
||||
|
||||
@@ -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} />
|
||||
|
||||
Reference in New Issue
Block a user