Skip to content

Commit 8da35f3

Browse files
lpranamMinion3665
authored andcommitted
comment: bring comment fully inside view on selection
This also removes getBoundingClientRect which was called frequently during animation which was costly This will make performance better problem: in narrow windows even on selection they may move not enough to bring them inside the visible area Signed-off-by: Pranam Lashkari <lpranam@collabora.com> Change-Id: I26702bcc01be873486bf371bf38a264dc46a57f6
1 parent 70aa26b commit 8da35f3

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

browser/src/canvas/sections/CommentListSection.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1926,10 +1926,18 @@ export class CommentSection extends CanvasSectionObject {
19261926
var isRTL = document.documentElement.dir === 'rtl';
19271927

19281928
if (selectedComment) {
1929-
// FIXME: getBoundingClientRect is expensive and this is a hot path (called continuously during animations and scrolling)
1930-
const posX = (this.sectionProperties.showSelectedBigger ?
1931-
Math.round((document.getElementById('document-container').getBoundingClientRect().width - subList[i].sectionProperties.container.getBoundingClientRect().width)/2) :
1929+
const commentWidth = this.sectionProperties.commentWidth;
1930+
const documentCanvasWidth = (document.getElementById('document-canvas') as any).width;
1931+
let posX = (this.sectionProperties.showSelectedBigger ?
1932+
Math.round((documentCanvasWidth - commentWidth)/2) :
19321933
Math.round(actualPosition[0] / app.dpiScale) - this.sectionProperties.deflectionOfSelectedComment * (isRTL ? -1 : 1));
1934+
// if on selection full comment is not visible bring it fully inside view, helps in narrow windows and tablets
1935+
if (isRTL && posX < 0)
1936+
posX = 0;
1937+
else if (posX + commentWidth > documentCanvasWidth)
1938+
{
1939+
posX = documentCanvasWidth - commentWidth;
1940+
}
19331941

19341942
subList[i].sectionProperties.container.style.left = String(posX + this.sectionProperties.canvasContainerLeft) + 'px';
19351943
subList[i].sectionProperties.container.style.top = String(Math.round(lastY / app.dpiScale) + this.sectionProperties.canvasContainerTop) + 'px';

0 commit comments

Comments
 (0)