From 20e85481ee284ba592e1104d1ec48c352ef44380 Mon Sep 17 00:00:00 2001 From: Anup Narkhede Date: Mon, 15 May 2023 18:12:09 +0100 Subject: [PATCH 1/3] Restore detection of text direction on Chrome --- src/trix/core/helpers/bidi.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/trix/core/helpers/bidi.js b/src/trix/core/helpers/bidi.js index 20efd506d..800de60ef 100644 --- a/src/trix/core/helpers/bidi.js +++ b/src/trix/core/helpers/bidi.js @@ -6,8 +6,10 @@ const RTL_PATTERN = export const getDirection = (function() { const input = makeElement("input", { dir: "auto", name: "x", dirName: "x.dir" }) + const textArea = makeElement("textarea", { dir: "auto", name: "y", dirName: "y.dir" }) const form = makeElement("form") form.appendChild(input) + form.appendChild(textArea) const supportsDirName = (function() { try { @@ -27,8 +29,8 @@ export const getDirection = (function() { if (supportsDirName) { return function(string) { - input.value = string - return new FormData(form).get(input.dirName) + input.value = textArea.value = string + return new FormData(form).get(textArea.dirName) } } else if (supportsDirSelector) { return function(string) { From 304426dac056f3462d4cc6d37a4a697d5825edca Mon Sep 17 00:00:00 2001 From: Alberto Fernandez-Capel Date: Tue, 16 May 2023 14:39:32 +0100 Subject: [PATCH 2/3] Use textarea to check dirname and input to check :dir css selector --- src/trix/core/helpers/bidi.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/trix/core/helpers/bidi.js b/src/trix/core/helpers/bidi.js index 800de60ef..81fe0e380 100644 --- a/src/trix/core/helpers/bidi.js +++ b/src/trix/core/helpers/bidi.js @@ -13,7 +13,7 @@ export const getDirection = (function() { const supportsDirName = (function() { try { - return new FormData(form).has(input.dirName) + return new FormData(form).has(textArea.dirName) } catch (error) { return false } @@ -29,7 +29,7 @@ export const getDirection = (function() { if (supportsDirName) { return function(string) { - input.value = textArea.value = string + textArea.value = string return new FormData(form).get(textArea.dirName) } } else if (supportsDirSelector) { From a85487f6606bc45bc4c598e0bb96f2354a69fb73 Mon Sep 17 00:00:00 2001 From: Alberto Fernandez-Capel Date: Tue, 16 May 2023 15:28:47 +0100 Subject: [PATCH 3/3] Add bidi detection test --- src/test/unit.js | 1 + src/test/unit/bidi_test.js | 9 +++++++++ 2 files changed, 10 insertions(+) create mode 100644 src/test/unit/bidi_test.js diff --git a/src/test/unit.js b/src/test/unit.js index 0680fbb11..81da21ac8 100644 --- a/src/test/unit.js +++ b/src/test/unit.js @@ -1,4 +1,5 @@ import "test/unit/attachment_test" +import "test/unit/bidi_test" import "test/unit/block_test" import "test/unit/composition_test" import "test/unit/document_test" diff --git a/src/test/unit/bidi_test.js b/src/test/unit/bidi_test.js new file mode 100644 index 000000000..17d104b97 --- /dev/null +++ b/src/test/unit/bidi_test.js @@ -0,0 +1,9 @@ +import { assert, test, testGroup } from "test/test_helper" +import { getDirection } from "trix/core/helpers" + +testGroup("BIDI", () => { + test("detects text direction", () => { + assert.equal(getDirection("abc"), "ltr") + assert.equal(getDirection("אבג"), "rtl") + }) +})