diff options
Diffstat (limited to 'ext/fg/js/source.js')
| -rw-r--r-- | ext/fg/js/source.js | 40 | 
1 files changed, 38 insertions, 2 deletions
| diff --git a/ext/fg/js/source.js b/ext/fg/js/source.js index a360b331..e724488d 100644 --- a/ext/fg/js/source.js +++ b/ext/fg/js/source.js @@ -25,13 +25,20 @@ const IGNORE_TEXT_PATTERN = /\u200c/;   */  class TextSourceRange { -    constructor(range, content='') { +    constructor(range, content, imposterContainer) {          this.range = range;          this.content = content; +        this.imposterContainer = imposterContainer;      }      clone() { -        return new TextSourceRange(this.range.cloneRange(), this.content); +        return new TextSourceRange(this.range.cloneRange(), this.content, this.imposterContainer); +    } + +    cleanup() { +        if (this.imposterContainer !== null && this.imposterContainer.parentNode !== null) { +            this.imposterContainer.parentNode.removeChild(this.imposterContainer); +        }      }      text() { @@ -61,6 +68,10 @@ class TextSourceRange {          return this.range.getBoundingClientRect();      } +    getWritingMode() { +        return TextSourceRange.getElementWritingMode(TextSourceRange.getParentElement(this.range.startContainer)); +    } +      getPaddedRect() {          const range = this.range.cloneRange();          const startOffset = range.startOffset; @@ -204,6 +215,23 @@ class TextSourceRange {          return state.remainder > 0;      } + +    static getParentElement(node) { +        while (node !== null && node.nodeType !== Node.ELEMENT_NODE) { +            node = node.parentNode; +        } +        return node; +    } + +    static getElementWritingMode(element) { +        if (element === null) { +            return 'horizontal-tb'; +        } + +        const style = window.getComputedStyle(element); +        const writingMode = style.writingMode; +        return typeof writingMode === 'string' ? writingMode : 'horizontal-tb'; +    }  } @@ -221,6 +249,10 @@ class TextSourceElement {          return new TextSourceElement(this.element, this.content);      } +    cleanup() { +        // NOP +    } +      text() {          return this.content;      } @@ -267,6 +299,10 @@ class TextSourceElement {          return this.element.getBoundingClientRect();      } +    getWritingMode() { +        return 'horizontal-tb'; +    } +      select() {          // NOP      } |