From c92fc11fcdad294059931a0927ec7f7701eb5be5 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Sun, 13 Oct 2019 16:43:26 -0400 Subject: [PATCH] Fix getElementWritingMode returning deprecated values on Edge --- ext/fg/js/source.js | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/ext/fg/js/source.js b/ext/fg/js/source.js index ee4f58e2..a483952e 100644 --- a/ext/fg/js/source.js +++ b/ext/fg/js/source.js @@ -229,13 +229,29 @@ class TextSourceRange { } static getElementWritingMode(element) { - if (element === null) { - return 'horizontal-tb'; + if (element !== null) { + const style = window.getComputedStyle(element); + const writingMode = style.writingMode; + if (typeof writingMode === 'string') { + TextSourceRange.normalizeWritingMode(writingMode); + } } + return 'horizontal-tb'; + } - const style = window.getComputedStyle(element); - const writingMode = style.writingMode; - return typeof writingMode === 'string' ? writingMode : 'horizontal-tb'; + static normalizeWritingMode(writingMode) { + switch (writingMode) { + case 'lr': + case 'lr-tb': + case 'rl': + return 'horizontal-tb'; + case 'tb': + return 'vertical-lr'; + case 'tb-rl': + return 'vertical-rl'; + default: + return writingMode; + } } static getNodesInRange(range) {