From d2964aa008d3675250fd4602008133650b54614a Mon Sep 17 00:00:00 2001 From: Martyanov Andrey <37772440+martyanovandrey@users.noreply.github.com> Date: Fri, 22 Dec 2023 10:54:24 +0300 Subject: [PATCH] feat(plugins/terms): rtl support (#354) --- src/js/term/utils.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/js/term/utils.ts b/src/js/term/utils.ts index df405422..c94c0411 100644 --- a/src/js/term/utils.ts +++ b/src/js/term/utils.ts @@ -76,10 +76,15 @@ export function setDefinitionPosition( const {left: definitionParentLeft} = definitionParent.getBoundingClientRect(); // If definition not fit document change base alignment - const definitionRightCoordinate = definitionWidth + Number(getCoords(termElement).left); - const fitDefinitionDocument = - document.body.clientWidth > definitionRightCoordinate ? 0 : definitionWidth - termWidth; + const definitionLeftCoordinate = Number(getCoords(termElement).left); + const definitionRightCoordinate = definitionWidth + definitionLeftCoordinate; + + const definitionOutOfScreenOnLeft = definitionLeftCoordinate - definitionWidth < 0; + const definitionOutOfScreenOnRight = definitionRightCoordinate > document.body.clientWidth; + const isAlignSwapped = definitionOutOfScreenOnRight || document.dir === 'rtl'; + const fitDefinitionDocument = + isAlignSwapped && !definitionOutOfScreenOnLeft ? definitionWidth - termWidth : 0; const customHeaderTop = getCoords(definitionParent).top - definitionParent.offsetTop; definitionElement.style.top =