Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:sparkles: Support inline text direction controls https://github.com/siyuan-note/siyuan/issues/15276

Vanessafb7e16442bf9
diff --git a/app/appearance/langs/ar.json b/app/appearance/langs/ar.json
index 72f2ac6e13..d6691b68eb 100644
--- a/app/appearance/langs/ar.json
+++ b/app/appearance/langs/ar.json
@@ -1,4 +1,5 @@
{
+ "textDirection": "اتجاه النص",
"contextFilter": "مرشح السياق",
"contextFilterTip": "يُطبّق على جميع طرق العرض في كتلة قاعدة البيانات هذه",
"contextFilterNoRelation": "أنشئ حقل علاقة وقم بتكوينه قبل تمكين مرشح السياق",
diff --git a/app/appearance/langs/de.json b/app/appearance/langs/de.json
index 2ef699210e..bf62a7c830 100644
--- a/app/appearance/langs/de.json
+++ b/app/appearance/langs/de.json
@@ -1,4 +1,5 @@
{
+ "textDirection": "Textrichtung",
"contextFilter": "Kontextfilter",
"contextFilterTip": "Gilt für alle Ansichten in diesem Datenbankblock",
"contextFilterNoRelation": "Erstelle und konfiguriere ein Beziehungsfeld, bevor du den Kontextfilter aktivierst",
diff --git a/app/appearance/langs/en.json b/app/appearance/langs/en.json
index 08b9bff0c8..1bef8f8e20 100644
--- a/app/appearance/langs/en.json
+++ b/app/appearance/langs/en.json
@@ -1,4 +1,5 @@
{
+ "textDirection": "Text direction",
"contextFilter": "Context filter",
"contextFilterTip": "Applies to every view in this database block",
"contextFilterNoRelation": "Create and configure a relation field before enabling the context filter",
diff --git a/app/appearance/langs/es.json b/app/appearance/langs/es.json
index 9b9868e047..5d6bc0b237 100644
--- a/app/appearance/langs/es.json
+++ b/app/appearance/langs/es.json
@@ -1,4 +1,5 @@
{
+ "textDirection": "Dirección del texto",
"contextFilter": "Filtro contextual",
"contextFilterTip": "Se aplica a todas las vistas de este bloque de base de datos",
"contextFilterNoRelation": "Crea y configura un campo de relación antes de activar el filtro contextual",
diff --git a/app/appearance/langs/fr.json b/app/appearance/langs/fr.json
index 2d99ae399f..b94a75b95a 100644
--- a/app/appearance/langs/fr.json
+++ b/app/appearance/langs/fr.json
@@ -1,4 +1,5 @@
{
+ "textDirection": "Direction du texte",
"contextFilter": "Filtre contextuel",
"contextFilterTip": "S’applique à toutes les vues de ce bloc de base de données",
"contextFilterNoRelation": "Créez et configurez un champ de relation avant d’activer le filtre contextuel",
diff --git a/app/appearance/langs/he.json b/app/appearance/langs/he.json
index 0a7e1220de..95d61bf0e6 100644
--- a/app/appearance/langs/he.json
+++ b/app/appearance/langs/he.json
@@ -1,4 +1,5 @@
{
+ "textDirection": "כיוון הטקסט",
"contextFilter": "מסנן הקשר",
"contextFilterTip": "חל על כל התצוגות בבלוק מסד הנתונים הזה",
"contextFilterNoRelation": "יש ליצור ולהגדיר שדה קשר לפני הפעלת מסנן ההקשר",
diff --git a/app/appearance/langs/hi.json b/app/appearance/langs/hi.json
index 3f9c8d2aac..3ffea8d776 100644
--- a/app/appearance/langs/hi.json
+++ b/app/appearance/langs/hi.json
@@ -1,4 +1,5 @@
{
+ "textDirection": "पाठ की दिशा",
"contextFilter": "संदर्भ फ़िल्टर",
"contextFilterTip": "इस डेटाबेस ब्लॉक के हर दृश्य पर लागू होता है",
"contextFilterNoRelation": "संदर्भ फ़िल्टर चालू करने से पहले संबंध फ़ील्ड बनाएँ और कॉन्फ़िगर करें",
diff --git a/app/appearance/langs/id.json b/app/appearance/langs/id.json
index 78ae1f3561..6167f4ccc1 100644
--- a/app/appearance/langs/id.json
+++ b/app/appearance/langs/id.json
@@ -1,4 +1,5 @@
{
+ "textDirection": "Arah teks",
"contextFilter": "Filter konteks",
"contextFilterTip": "Berlaku untuk setiap tampilan dalam blok basis data ini",
"contextFilterNoRelation": "Buat dan konfigurasikan bidang relasi sebelum mengaktifkan filter konteks",
diff --git a/app/appearance/langs/it.json b/app/appearance/langs/it.json
index f0794c79a8..1eee527bef 100644
--- a/app/appearance/langs/it.json
+++ b/app/appearance/langs/it.json
@@ -1,4 +1,5 @@
{
+ "textDirection": "Direzione del testo",
"contextFilter": "Filtro contestuale",
"contextFilterTip": "Si applica a tutte le viste di questo blocco database",
"contextFilterNoRelation": "Crea e configura un campo relazione prima di attivare il filtro contestuale",
diff --git a/app/appearance/langs/ja.json b/app/appearance/langs/ja.json
index 3035527e81..7aed6aaa18 100644
--- a/app/appearance/langs/ja.json
+++ b/app/appearance/langs/ja.json
@@ -1,4 +1,5 @@
{
+ "textDirection": "テキストの方向",
"contextFilter": "コンテキストフィルター",
"contextFilterTip": "このデータベースブロックのすべてのビューに適用します",
"contextFilterNoRelation": "コンテキストフィルターを有効にする前に関連フィールドを作成して設定してください",
diff --git a/app/appearance/langs/ko.json b/app/appearance/langs/ko.json
index 0172466abf..b6753945c8 100644
--- a/app/appearance/langs/ko.json
+++ b/app/appearance/langs/ko.json
@@ -1,4 +1,5 @@
{
+ "textDirection": "텍스트 방향",
"contextFilter": "컨텍스트 필터",
"contextFilterTip": "이 데이터베이스 블록의 모든 보기에 적용됩니다",
"contextFilterNoRelation": "컨텍스트 필터를 사용하기 전에 관계 필드를 만들고 구성하세요",
diff --git a/app/appearance/langs/nl.json b/app/appearance/langs/nl.json
index 28a638bf62..45a8061817 100644
--- a/app/appearance/langs/nl.json
+++ b/app/appearance/langs/nl.json
@@ -1,4 +1,5 @@
{
+ "textDirection": "Tekstrichting",
"contextFilter": "Contextfilter",
"contextFilterTip": "Is van toepassing op alle weergaven in dit databaseblok",
"contextFilterNoRelation": "Maak en configureer een relatieveld voordat je het contextfilter inschakelt",
diff --git a/app/appearance/langs/pl.json b/app/appearance/langs/pl.json
index 51866a8af7..3a9897d537 100644
--- a/app/appearance/langs/pl.json
+++ b/app/appearance/langs/pl.json
@@ -1,4 +1,5 @@
{
+ "textDirection": "Kierunek tekstu",
"contextFilter": "Filtr kontekstowy",
"contextFilterTip": "Dotyczy wszystkich widoków w tym bloku bazy danych",
"contextFilterNoRelation": "Przed włączeniem filtra kontekstowego utwórz i skonfiguruj pole relacji",
diff --git a/app/appearance/langs/pt-BR.json b/app/appearance/langs/pt-BR.json
index 58540cf08d..ac24aaedb2 100644
--- a/app/appearance/langs/pt-BR.json
+++ b/app/appearance/langs/pt-BR.json
@@ -1,4 +1,5 @@
{
+ "textDirection": "Direção do texto",
"contextFilter": "Filtro contextual",
"contextFilterTip": "Aplica-se a todas as visualizações deste bloco de banco de dados",
"contextFilterNoRelation": "Crie e configure um campo de relação antes de ativar o filtro contextual",
diff --git a/app/appearance/langs/ru.json b/app/appearance/langs/ru.json
index b1938ce99b..6ad514e532 100644
--- a/app/appearance/langs/ru.json
+++ b/app/appearance/langs/ru.json
@@ -1,4 +1,5 @@
{
+ "textDirection": "Направление текста",
"contextFilter": "Контекстный фильтр",
"contextFilterTip": "Применяется ко всем представлениям в этом блоке базы данных",
"contextFilterNoRelation": "Перед включением контекстного фильтра создайте и настройте поле связи",
diff --git a/app/appearance/langs/sk.json b/app/appearance/langs/sk.json
index d0620d0c77..e3f01e57a8 100644
--- a/app/appearance/langs/sk.json
+++ b/app/appearance/langs/sk.json
@@ -1,4 +1,5 @@
{
+ "textDirection": "Smer textu",
"contextFilter": "Kontextový filter",
"contextFilterTip": "Použije sa na všetky zobrazenia v tomto databázovom bloku",
"contextFilterNoRelation": "Pred zapnutím kontextového filtra vytvorte a nastavte pole vzťahu",
diff --git a/app/appearance/langs/th.json b/app/appearance/langs/th.json
index c31b263a06..ffcdf148cc 100644
--- a/app/appearance/langs/th.json
+++ b/app/appearance/langs/th.json
@@ -1,4 +1,5 @@
{
+ "textDirection": "ทิศทางข้อความ",
"contextFilter": "ตัวกรองบริบท",
"contextFilterTip": "ใช้กับทุกมุมมองในบล็อกฐานข้อมูลนี้",
"contextFilterNoRelation": "สร้างและกำหนดค่าฟิลด์ความสัมพันธ์ก่อนเปิดใช้ตัวกรองบริบท",
diff --git a/app/appearance/langs/tr.json b/app/appearance/langs/tr.json
index b3e1f4cfa2..d2ad307aab 100644
--- a/app/appearance/langs/tr.json
+++ b/app/appearance/langs/tr.json
@@ -1,4 +1,5 @@
{
+ "textDirection": "Metin yönü",
"contextFilter": "Bağlam filtresi",
"contextFilterTip": "Bu veritabanı bloğundaki tüm görünümlere uygulanır",
"contextFilterNoRelation": "Bağlam filtresini etkinleştirmeden önce bir ilişki alanı oluşturup yapılandırın",
diff --git a/app/appearance/langs/uk.json b/app/appearance/langs/uk.json
index e5f838506a..43ed237177 100644
--- a/app/appearance/langs/uk.json
+++ b/app/appearance/langs/uk.json
@@ -1,4 +1,5 @@
{
+ "textDirection": "Напрямок тексту",
"contextFilter": "Контекстний фільтр",
"contextFilterTip": "Застосовується до всіх подань у цьому блоці бази даних",
"contextFilterNoRelation": "Перед увімкненням контекстного фільтра створіть і налаштуйте поле зв’язку",
diff --git a/app/appearance/langs/zh-CN.json b/app/appearance/langs/zh-CN.json
index 6e24186b30..3eeb5ae84b 100644
--- a/app/appearance/langs/zh-CN.json
+++ b/app/appearance/langs/zh-CN.json
@@ -1,4 +1,5 @@
{
+ "textDirection": "文本方向",
"contextFilter": "上下文筛选",
"contextFilterTip": "应用于当前数据库块的所有视图",
"contextFilterNoRelation": "请先创建并配置关联字段,再启用上下文筛选",
diff --git a/app/appearance/langs/zh-TW.json b/app/appearance/langs/zh-TW.json
index 498148a986..b31f00999f 100644
--- a/app/appearance/langs/zh-TW.json
+++ b/app/appearance/langs/zh-TW.json
@@ -1,4 +1,5 @@
{
+ "textDirection": "文字方向",
"contextFilter": "情境篩選",
"contextFilterTip": "套用於此資料庫區塊的所有檢視",
"contextFilterNoRelation": "啟用情境篩選前,請先建立並設定關聯欄位",
diff --git a/app/src/protyle/toolbar/Font.ts b/app/src/protyle/toolbar/Font.ts
index e3ee6c90e0..8862f2ebf3 100644
--- a/app/src/protyle/toolbar/Font.ts
+++ b/app/src/protyle/toolbar/Font.ts
@@ -46,6 +46,11 @@ import {
openFontFamilyMenu,
} from "./fontFamilyMenu";
import {hasInlineFontFamilyExcludedType} from "./fontFamilyCore";
+import {
+ hasInlineDirectionStyle,
+ hasSameInlineDirectionStyle,
+ setInlineDirectionStyle,
+} from "./inlineDirectionStyle";
const MAX_RECENT_FONT_STYLES = 14;
@@ -263,6 +268,7 @@ export const appearanceMenu = (protyle: IProtyle, nodeElements?: Element[],
const {fontSize, baseFontSize} = getFontSizeInfo(protyle, nodeElements);
const fontFamilyState = getInlineFontFamilyState(protyle, fontFamilyElements || nodeElements);
const disableFontFamily = disableFont || fontFamilyState.disabled;
+ const showInlineDirection = !nodeElements || nodeElements.length === 0 || !!onChange;
const applyFontStyle = (type: string, color?: string) => {
fontEvent(protyle, nodeElements, type, color, true, onChange);
};
@@ -306,6 +312,20 @@ export const appearanceMenu = (protyle: IProtyle, nodeElements?: Element[],
<button data-type="style2" class="color__square ariaLabel" data-position="3south" aria-label="${window.siyuan.languages.hollow}" style="-webkit-text-stroke: 0.2px var(--b3-theme-on-background);-webkit-text-fill-color : transparent;">A</button>
<button data-type="style4" class="color__square ariaLabel" data-position="3south" aria-label="${window.siyuan.languages.shadow}" style="text-shadow: 1px 1px var(--b3-theme-surface-lighter), 2px 2px var(--b3-theme-surface-lighter), 3px 3px var(--b3-theme-surface-lighter), 4px 4px var(--b3-theme-surface-lighter)">A</button>
</div>
+${showInlineDirection ? `<div class="fn__hr"></div>
+<div data-id="textDirection" class="fn__flex">
+ <span class="fn__flex-center">${window.siyuan.languages.textDirection}</span>
+ <span class="fn__flex-1"></span>
+ <button type="button" class="block__icon block__icon--show ariaLabel" data-position="3south" data-type="direction" data-value="ltr" aria-label="${window.siyuan.languages.ltr}">
+ <svg><use xlink:href="#iconLtr"></use></svg>
+ </button>
+ <button type="button" class="block__icon block__icon--show ariaLabel" data-position="3south" data-type="direction" data-value="rtl" aria-label="${window.siyuan.languages.rtl}">
+ <svg><use xlink:href="#iconRtl"></use></svg>
+ </button>
+ <button type="button" class="block__icon block__icon--show ariaLabel" data-position="3south" data-type="direction" data-value="" aria-label="${window.siyuan.languages.clear}">
+ <svg><use xlink:href="#iconClear"></use></svg>
+ </button>
+</div>` : ""}
<div class="fn__hr${disableFontFamily ? " fn__none" : ""}"></div>
<div data-id="fontFamily" class="fn__flex${disableFontFamily ? " fn__none" : ""}">
<span class="fn__flex-center">${window.siyuan.languages.fontFamily}</span>
@@ -383,6 +403,9 @@ export const appearanceMenu = (protyle: IProtyle, nodeElements?: Element[],
} else if (dataType === "color") {
applyFontStyle(dataType, target.style.color);
closeSelectionToolbarAppearance();
+ } else if (dataType === "direction") {
+ applyFontStyle(dataType, target.dataset.value);
+ closeSelectionToolbarAppearance();
} else {
applyFontStyle(dataType);
closeSelectionToolbarAppearance();
@@ -443,7 +466,7 @@ export const fontEvent = (protyle: IProtyle, nodeElements: Element[], type?: str
focusRange = true, onChange?: (type: string, color?: string) => void) => {
let localFontStyles = window.siyuan.storage[Constants.LOCAL_FONTSTYLES];
if (type) {
- if (type !== "fontFamily") {
+ if (!["direction", "fontFamily"].includes(type)) {
const value = `${type}${Constants.ZWSP}${color}`;
const recentKey = getRecentInlineStyleKey(value);
localFontStyles = [value, ...localFontStyles.filter((item: string) =>
@@ -585,6 +608,9 @@ export const setFontStyle = (textElement: HTMLElement, textOption: ITextOption)
}
}
break;
+ case "direction":
+ setInlineDirectionStyle(textElement.style, textOption.color);
+ break;
case "backgroundColor":
textElement.style.backgroundColor = textOption.color;
break;
@@ -658,7 +684,8 @@ export const hasSameTextStyle = (currentElement: HTMLElement, sideElement: HTMLE
sideElement.style.textShadow === currentElement.style.textShadow &&
sideElement.style.backgroundColor === currentElement.style.backgroundColor &&
sideElement.style.fontSize === currentElement.style.fontSize &&
- sideElement.style.fontFamily === currentElement.style.fontFamily) {
+ sideElement.style.fontFamily === currentElement.style.fontFamily &&
+ hasSameInlineDirectionStyle(currentElement.style, sideElement.style)) {
return true;
}
return false;
@@ -673,6 +700,8 @@ export const hasSameTextStyle = (currentElement: HTMLElement, sideElement: HTMLE
!sideElement.style.textShadow &&
!sideElement.style.fontSize &&
!sideElement.style.fontFamily &&
+ !sideElement.style.direction &&
+ !sideElement.style.unicodeBidi &&
!sideElement.style.backgroundColor;
}
if (textObj.type === "color") {
@@ -699,6 +728,9 @@ export const hasSameTextStyle = (currentElement: HTMLElement, sideElement: HTMLE
if (textObj.type === "fontFamily") {
return textObj.color === sideElement.style.fontFamily;
}
+ if (textObj.type === "direction") {
+ return hasInlineDirectionStyle(sideElement.style, textObj.color);
+ }
}
return false;
};
diff --git a/app/src/protyle/toolbar/FormatPainter.ts b/app/src/protyle/toolbar/FormatPainter.ts
index 3a18c45a4a..6d4ff2ad99 100644
--- a/app/src/protyle/toolbar/FormatPainter.ts
+++ b/app/src/protyle/toolbar/FormatPainter.ts
@@ -35,6 +35,8 @@ const getSegment = (textNode: Text, editableElement: Element) => {
styles.fontSize = styles.fontSize || element.style.fontSize || undefined;
styles.shadow = styles.shadow || !!element.style.textShadow || undefined;
styles.hollow = styles.hollow || !!element.style.webkitTextStroke || undefined;
+ styles.direction = styles.direction ||
+ (element.style.direction === "ltr" || element.style.direction === "rtl" ? element.style.direction : undefined);
}
if (element === editableElement) {
break;
diff --git a/app/src/protyle/toolbar/formatPainter.test.ts b/app/src/protyle/toolbar/formatPainter.test.ts
index 53d47e1792..6aaacd11b8 100644
--- a/app/src/protyle/toolbar/formatPainter.test.ts
+++ b/app/src/protyle/toolbar/formatPainter.test.ts
@@ -10,13 +10,26 @@ describe("getCommonFormatPainterSnapshot", () => {
it("keeps only formats shared by every selected text segment", () => {
assert.deepEqual(getCommonFormatPainterSnapshot([{
types: ["strong", "em"],
- styles: {color: "red", fontFamily: "Arial", fontSize: "16px"},
+ styles: {color: "red", direction: "rtl", fontFamily: "Arial", fontSize: "16px"},
}, {
types: ["strong", "u"],
- styles: {color: "blue", fontFamily: "Arial", fontSize: "16px"},
+ styles: {color: "blue", direction: "rtl", fontFamily: "Arial", fontSize: "16px"},
}]), {
types: ["strong"],
- styles: {fontFamily: "Arial", fontSize: "16px"},
+ styles: {direction: "rtl", fontFamily: "Arial", fontSize: "16px"},
+ });
+ });
+
+ it("omits mixed inline text directions", () => {
+ assert.deepEqual(getCommonFormatPainterSnapshot([{
+ types: [],
+ styles: {direction: "ltr"},
+ }, {
+ types: [],
+ styles: {direction: "rtl"},
+ }]), {
+ types: [],
+ styles: {},
});
});
diff --git a/app/src/protyle/toolbar/formatPainterCore.ts b/app/src/protyle/toolbar/formatPainterCore.ts
index 0fa537a6b9..8d23428df6 100644
--- a/app/src/protyle/toolbar/formatPainterCore.ts
+++ b/app/src/protyle/toolbar/formatPainterCore.ts
@@ -1,6 +1,7 @@
export interface IFormatPainterStyle {
backgroundColor?: string;
color?: string;
+ direction?: "ltr" | "rtl";
fontFamily?: string;
fontSize?: string;
shadow?: boolean;
@@ -29,7 +30,7 @@ export const FORMAT_PAINTER_TYPES = ["strong", "em", "u", "s", "mark", "sup", "s
const getCommonStyles = (segments: IFormatPainterSegment[]) => {
const styles: IFormatPainterStyle = {};
const keys: (keyof IFormatPainterStyle)[] = [
- "backgroundColor", "color", "fontFamily", "fontSize", "shadow", "hollow"
+ "backgroundColor", "color", "direction", "fontFamily", "fontSize", "shadow", "hollow"
];
keys.forEach(key => {
const comparableSegments = key === "fontFamily" ?
diff --git a/app/src/protyle/toolbar/index.ts b/app/src/protyle/toolbar/index.ts
index a8ba94a78f..dab306ae2c 100644
--- a/app/src/protyle/toolbar/index.ts
+++ b/app/src/protyle/toolbar/index.ts
@@ -458,6 +458,9 @@ export class Toolbar {
if (snapshot.styles.fontFamily) {
applyMark("text", {type: "fontFamily", color: snapshot.styles.fontFamily});
}
+ if (snapshot.styles.direction) {
+ applyMark("text", {type: "direction", color: snapshot.styles.direction});
+ }
if (snapshot.styles.shadow) {
applyMark("text", {type: "style4"});
}
@@ -1014,6 +1017,8 @@ export class Toolbar {
item.style.backgroundColor = "";
item.style.fontSize = "";
item.style.fontFamily = "";
+ item.style.direction = "";
+ item.style.unicodeBidi = "";
}
item.setAttribute("data-type", types.join(" "));
if (hasSemanticInlineType(types.join(" "))) {
diff --git a/app/src/protyle/toolbar/inlineDirectionStyle.test.ts b/app/src/protyle/toolbar/inlineDirectionStyle.test.ts
new file mode 100644
index 0000000000..9a4030cd19
--- /dev/null
+++ b/app/src/protyle/toolbar/inlineDirectionStyle.test.ts
@@ -0,0 +1,52 @@
+import {describe, it} from "node:test";
+import * as assert from "node:assert/strict";
+import {
+ hasInlineDirectionStyle,
+ hasSameInlineDirectionStyle,
+ normalizeInlineDirection,
+ setInlineDirectionStyle,
+} from "./inlineDirectionStyle";
+
+const createStyle = (direction = "", unicodeBidi = "") => ({
+ direction,
+ unicodeBidi,
+ removeProperty(property: string) {
+ if (property === "direction") {
+ this.direction = "";
+ } else if (property === "unicode-bidi") {
+ this.unicodeBidi = "";
+ }
+ return "";
+ },
+}) as CSSStyleDeclaration;
+
+describe("inline direction style", () => {
+ it("normalizes only supported directions", () => {
+ assert.equal(normalizeInlineDirection("ltr"), "ltr");
+ assert.equal(normalizeInlineDirection("rtl"), "rtl");
+ assert.equal(normalizeInlineDirection("auto"), undefined);
+ assert.equal(normalizeInlineDirection(""), undefined);
+ });
+
+ it("sets an isolated explicit direction", () => {
+ const style = createStyle();
+ setInlineDirectionStyle(style, "rtl");
+ assert.equal(style.direction, "rtl");
+ assert.equal(style.unicodeBidi, "isolate");
+ assert.equal(hasInlineDirectionStyle(style, "rtl"), true);
+ assert.equal(hasInlineDirectionStyle(style, "ltr"), false);
+ });
+
+ it("clears both direction properties", () => {
+ const style = createStyle("ltr", "isolate");
+ setInlineDirectionStyle(style, "");
+ assert.equal(hasInlineDirectionStyle(style), true);
+ });
+
+ it("keeps differently directed spans separate", () => {
+ assert.equal(hasSameInlineDirectionStyle(
+ createStyle("ltr", "isolate"), createStyle("rtl", "isolate")), false);
+ assert.equal(hasSameInlineDirectionStyle(
+ createStyle("rtl", "isolate"), createStyle("rtl", "isolate")), true);
+ });
+});
diff --git a/app/src/protyle/toolbar/inlineDirectionStyle.ts b/app/src/protyle/toolbar/inlineDirectionStyle.ts
new file mode 100644
index 0000000000..9d3e067f29
--- /dev/null
+++ b/app/src/protyle/toolbar/inlineDirectionStyle.ts
@@ -0,0 +1,26 @@
+export type TInlineDirection = "ltr" | "rtl";
+
+export const normalizeInlineDirection = (direction?: string): TInlineDirection | undefined =>
+ direction === "ltr" || direction === "rtl" ? direction : undefined;
+
+export const setInlineDirectionStyle = (style: CSSStyleDeclaration, direction?: string) => {
+ const normalizedDirection = normalizeInlineDirection(direction);
+ if (normalizedDirection) {
+ style.direction = normalizedDirection;
+ style.unicodeBidi = "isolate";
+ } else {
+ style.removeProperty("direction");
+ style.removeProperty("unicode-bidi");
+ }
+};
+
+export const hasInlineDirectionStyle = (style: CSSStyleDeclaration, direction?: string) => {
+ const normalizedDirection = normalizeInlineDirection(direction);
+ if (!normalizedDirection) {
+ return !style.direction && !style.unicodeBidi;
+ }
+ return style.direction === normalizedDirection && style.unicodeBidi === "isolate";
+};
+
+export const hasSameInlineDirectionStyle = (current: CSSStyleDeclaration, side: CSSStyleDeclaration) =>
+ current.direction === side.direction && current.unicodeBidi === side.unicodeBidi;