@@ -94,6 +94,9 @@ export class CommentSection extends app.definitions.canvasSectionObject {
94
94
// To associate comment id with its index in commentList array.
95
95
private idIndexMap : Map < any , number > ;
96
96
97
+ private annotationMinSize : number ;
98
+ private annotationMaxSize : number ;
99
+
97
100
constructor ( ) {
98
101
super ( ) ;
99
102
@@ -119,6 +122,8 @@ export class CommentSection extends app.definitions.canvasSectionObject {
119
122
this . sectionProperties . commentsAreListed = ( this . sectionProperties . docLayer . _docType === 'text' || this . sectionProperties . docLayer . _docType === 'presentation' || this . sectionProperties . docLayer . _docType === 'drawing' ) && ! ( < any > window ) . mode . isMobile ( ) ;
120
123
this . idIndexMap = new Map < any , number > ( ) ;
121
124
this . mobileCommentModalId = this . map . uiManager . generateModalId ( this . mobileCommentId ) ;
125
+ this . annotationMinSize = Number ( getComputedStyle ( document . documentElement ) . getPropertyValue ( '--annotation-min-size' ) ) ;
126
+ this . annotationMaxSize = Number ( getComputedStyle ( document . documentElement ) . getPropertyValue ( '--annotation-max-size' ) ) ;
122
127
}
123
128
124
129
public onInitialize ( ) : void {
@@ -1252,7 +1257,7 @@ export class CommentSection extends app.definitions.canvasSectionObject {
1252
1257
1253
1258
var previousAnimationState = this . disableLayoutAnimation ;
1254
1259
this . disableLayoutAnimation = true ;
1255
- this . update ( true ) ;
1260
+ this . update ( true , false ) ;
1256
1261
this . disableLayoutAnimation = previousAnimationState ;
1257
1262
}
1258
1263
@@ -1801,10 +1806,10 @@ export class CommentSection extends app.definitions.canvasSectionObject {
1801
1806
return this . disableLayoutAnimation ? 0 : undefined ; // undefined means it will use default value
1802
1807
}
1803
1808
1804
- private layoutUp ( subList : any , actualPosition : Array < number > , lastY : number ) : number {
1809
+ private layoutUp ( subList : any , actualPosition : Array < number > , lastY : number , relayout : boolean = true ) : number {
1805
1810
var height : number ;
1806
1811
for ( var i = 0 ; i < subList . length ; i ++ ) {
1807
- height = subList [ i ] . getCommentHeight ( ) ;
1812
+ height = subList [ i ] . getCommentHeight ( relayout ) ;
1808
1813
lastY = subList [ i ] . sectionProperties . data . anchorPix [ 1 ] + height < lastY ? subList [ i ] . sectionProperties . data . anchorPix [ 1 ] : lastY - ( height * app . dpiScale ) ;
1809
1814
( new L . PosAnimation ( ) ) . run ( subList [ i ] . sectionProperties . container , { x : Math . round ( actualPosition [ 0 ] / app . dpiScale ) , y : Math . round ( lastY / app . dpiScale ) } , this . getAnimationDuration ( ) ) ;
1810
1815
if ( ! subList [ i ] . isEdit ( ) )
@@ -1813,7 +1818,7 @@ export class CommentSection extends app.definitions.canvasSectionObject {
1813
1818
return lastY ;
1814
1819
}
1815
1820
1816
- private loopUp ( startIndex : number , x : number , startY : number ) : number {
1821
+ private loopUp ( startIndex : number , x : number , startY : number , relayout : boolean = true ) : number {
1817
1822
var tmpIdx = 0 ;
1818
1823
var checkSelectedPart : boolean = this . mustCheckSelectedPart ( ) ;
1819
1824
startY -= this . sectionProperties . marginY ;
@@ -1834,7 +1839,7 @@ export class CommentSection extends app.definitions.canvasSectionObject {
1834
1839
} while ( tmpIdx > - 1 && this . sectionProperties . commentList [ tmpIdx ] . sectionProperties . data . parent === this . sectionProperties . commentList [ tmpIdx + 1 ] . sectionProperties . data . id ) ;
1835
1840
1836
1841
if ( subList . length > 0 ) {
1837
- startY = this . layoutUp ( subList , [ x , subList [ 0 ] . sectionProperties . data . anchorPix [ 1 ] ] , startY ) ;
1842
+ startY = this . layoutUp ( subList , [ x , subList [ 0 ] . sectionProperties . data . anchorPix [ 1 ] ] , startY , relayout ) ;
1838
1843
i = i - subList . length ;
1839
1844
} else {
1840
1845
i = tmpIdx ;
@@ -1844,14 +1849,15 @@ export class CommentSection extends app.definitions.canvasSectionObject {
1844
1849
return startY ;
1845
1850
}
1846
1851
1847
- private layoutDown ( subList : any , actualPosition : Array < number > , lastY : number ) : number {
1852
+ private layoutDown ( subList : any , actualPosition : Array < number > , lastY : number , relayout : boolean = true ) : number {
1848
1853
var selectedComment = subList [ 0 ] === this . sectionProperties . selectedComment ;
1849
1854
for ( var i = 0 ; i < subList . length ; i ++ ) {
1850
1855
lastY = subList [ i ] . sectionProperties . data . anchorPix [ 1 ] > lastY ? subList [ i ] . sectionProperties . data . anchorPix [ 1 ] : lastY ;
1851
1856
1852
1857
var isRTL = document . documentElement . dir === 'rtl' ;
1853
1858
1854
1859
if ( selectedComment ) {
1860
+ // FIXME: getBoundingClientRect is expensive and this is a hot path (called continuously during animations and scrolling)
1855
1861
const posX = ( this . sectionProperties . showSelectedBigger ?
1856
1862
Math . round ( ( document . getElementById ( 'document-container' ) . getBoundingClientRect ( ) . width - subList [ i ] . sectionProperties . container . getBoundingClientRect ( ) . width ) / 2 ) :
1857
1863
Math . round ( actualPosition [ 0 ] / app . dpiScale ) - this . sectionProperties . deflectionOfSelectedComment * ( isRTL ? - 1 : 1 ) ) ;
@@ -1860,14 +1866,14 @@ export class CommentSection extends app.definitions.canvasSectionObject {
1860
1866
else
1861
1867
( new L . PosAnimation ( ) ) . run ( subList [ i ] . sectionProperties . container , { x : Math . round ( actualPosition [ 0 ] / app . dpiScale ) , y : Math . round ( lastY / app . dpiScale ) } , this . getAnimationDuration ( ) ) ;
1862
1868
1863
- lastY += ( subList [ i ] . getCommentHeight ( ) * app . dpiScale ) ;
1869
+ lastY += ( subList [ i ] . getCommentHeight ( relayout ) * app . dpiScale ) ;
1864
1870
if ( ! subList [ i ] . isEdit ( ) )
1865
1871
subList [ i ] . show ( ) ;
1866
1872
}
1867
1873
return lastY ;
1868
1874
}
1869
1875
1870
- private loopDown ( startIndex : number , x : number , startY : number ) : number {
1876
+ private loopDown ( startIndex : number , x : number , startY : number , relayout : boolean = true ) : number {
1871
1877
var tmpIdx = 0 ;
1872
1878
var checkSelectedPart : boolean = this . mustCheckSelectedPart ( ) ;
1873
1879
// Pass over all comments present
@@ -1887,7 +1893,7 @@ export class CommentSection extends app.definitions.canvasSectionObject {
1887
1893
} while ( tmpIdx < this . sectionProperties . commentList . length && this . sectionProperties . commentList [ tmpIdx ] . sectionProperties . data . parent !== '0' ) ;
1888
1894
1889
1895
if ( subList . length > 0 ) {
1890
- startY = this . layoutDown ( subList , [ x , subList [ 0 ] . sectionProperties . data . anchorPix [ 1 ] ] , startY ) ;
1896
+ startY = this . layoutDown ( subList , [ x , subList [ 0 ] . sectionProperties . data . anchorPix [ 1 ] ] , startY , relayout ) ;
1891
1897
i = i + subList . length ;
1892
1898
} else {
1893
1899
i = tmpIdx ;
@@ -1901,6 +1907,7 @@ export class CommentSection extends app.definitions.canvasSectionObject {
1901
1907
if ( this . sectionProperties . arrow ) {
1902
1908
document . getElementById ( 'document-container' ) . removeChild ( this . sectionProperties . arrow ) ;
1903
1909
this . sectionProperties . arrow = null ;
1910
+ app . sectionContainer . requestReDraw ( ) ;
1904
1911
}
1905
1912
}
1906
1913
@@ -1916,7 +1923,7 @@ export class CommentSection extends app.definitions.canvasSectionObject {
1916
1923
endPoint [ 1 ] = Math . floor ( endPoint [ 1 ] / app . dpiScale ) ;
1917
1924
1918
1925
if ( this . sectionProperties . arrow !== null ) {
1919
- var line : SVGLineElement = < SVGLineElement > ( < any > document . getElementById ( 'comment- arrow-line' ) ) ;
1926
+ var line : SVGLineElement = < SVGLineElement > ( this . sectionProperties . arrow . firstElementChild ) ;
1920
1927
line . setAttribute ( 'x1' , String ( startPoint [ 0 ] ) ) ;
1921
1928
line . setAttribute ( 'y1' , String ( startPoint [ 1 ] ) ) ;
1922
1929
line . setAttribute ( 'x2' , String ( endPoint [ 0 ] ) ) ;
@@ -1945,7 +1952,7 @@ export class CommentSection extends app.definitions.canvasSectionObject {
1945
1952
}
1946
1953
}
1947
1954
1948
- private doLayout ( ) : void {
1955
+ private doLayout ( relayout : boolean = true ) : void {
1949
1956
if ( ( < any > window ) . mode . isMobile ( ) || this . sectionProperties . docLayer . _docType === 'spreadsheet' ) {
1950
1957
if ( this . sectionProperties . commentList . length > 0 )
1951
1958
this . orderCommentList ( ) ;
@@ -1954,7 +1961,8 @@ export class CommentSection extends app.definitions.canvasSectionObject {
1954
1961
1955
1962
if ( this . sectionProperties . commentList . length > 0 ) {
1956
1963
this . orderCommentList ( ) ;
1957
- this . resetCommentsSize ( ) ;
1964
+ if ( relayout )
1965
+ this . resetCommentsSize ( ) ;
1958
1966
1959
1967
var isRTL = document . documentElement . dir === 'rtl' ;
1960
1968
@@ -1986,21 +1994,20 @@ export class CommentSection extends app.definitions.canvasSectionObject {
1986
1994
this . showArrow ( [ tempCrd [ 0 ] , tempCrd [ 1 ] ] , [ posX , tempCrd [ 1 ] ] ) ;
1987
1995
}
1988
1996
}
1989
- else {
1997
+ else
1990
1998
this . hideArrow ( ) ;
1991
- app . sectionContainer . requestReDraw ( ) ;
1992
- }
1993
1999
1994
2000
var lastY = 0 ;
1995
2001
if ( selectedIndex ) {
1996
- this . loopUp ( selectedIndex - 1 , x , yOrigin ) ;
1997
- lastY = this . loopDown ( selectedIndex , x , yOrigin ) ;
2002
+ this . loopUp ( selectedIndex - 1 , x , yOrigin , relayout ) ;
2003
+ lastY = this . loopDown ( selectedIndex , x , yOrigin , relayout ) ;
1998
2004
}
1999
2005
else {
2000
- lastY = this . loopDown ( 0 , x , topRight [ 1 ] ) ;
2006
+ lastY = this . loopDown ( 0 , x , topRight [ 1 ] , relayout ) ;
2001
2007
}
2002
2008
}
2003
- this . resizeComments ( ) ;
2009
+ if ( relayout )
2010
+ this . resizeComments ( ) ;
2004
2011
2005
2012
lastY += this . containerObject . getDocumentTopLeft ( ) [ 1 ] ;
2006
2013
if ( lastY > app . file . size . pixels [ 1 ] ) {
@@ -2013,21 +2020,21 @@ export class CommentSection extends app.definitions.canvasSectionObject {
2013
2020
this . disableLayoutAnimation = false ;
2014
2021
}
2015
2022
2016
- private layout ( immediate : any = null ) : void {
2023
+ private layout ( immediate : any = null , relayout : boolean = true ) : void {
2017
2024
if ( immediate )
2018
- this . doLayout ( ) ;
2025
+ this . doLayout ( relayout ) ;
2019
2026
else if ( ! this . sectionProperties . layoutTimer ) {
2020
- this . sectionProperties . layoutTimer = setTimeout ( function ( ) {
2027
+ this . sectionProperties . layoutTimer = setTimeout ( ( ) => {
2021
2028
delete this . sectionProperties . layoutTimer ;
2022
- this . doLayout ( ) ;
2023
- } . bind ( this ) , 10 /* ms */ ) ;
2029
+ this . doLayout ( relayout ) ;
2030
+ } , 10 /* ms */ ) ;
2024
2031
} // else - avoid excessive re-layout
2025
2032
}
2026
2033
2027
- private update ( immediate : boolean = false ) : void {
2028
- if ( this . sectionProperties . docLayer . _docType === 'text' )
2034
+ private update ( immediate : boolean = false , relayout : boolean = true ) : void {
2035
+ if ( relayout && this . sectionProperties . docLayer . _docType === 'text' )
2029
2036
this . updateThreadInfoIndicator ( ) ;
2030
- this . layout ( immediate ) ;
2037
+ this . layout ( immediate , relayout ) ;
2031
2038
}
2032
2039
2033
2040
private updateThreadInfoIndicator ( ) : void {
@@ -2143,15 +2150,11 @@ export class CommentSection extends app.definitions.canvasSectionObject {
2143
2150
// reset theis size to default (100px text)
2144
2151
private resetCommentsSize ( ) : void {
2145
2152
if ( this . sectionProperties . docLayer . _docType === 'text' ) {
2146
- const minMaxHeight = Number ( getComputedStyle ( document . documentElement ) . getPropertyValue ( '--annotation-min-size' ) ) ;
2147
2153
for ( var i = 0 ; i < this . sectionProperties . commentList . length ; i ++ ) {
2148
- if ( this . sectionProperties . commentList [ i ] . sectionProperties . contentNode . style . display !== 'none' )
2149
- this . sectionProperties . commentList [ i ] . sectionProperties . contentNode . style . maxHeight = minMaxHeight + 'px' ;
2150
- }
2151
- if ( this . sectionProperties . selectedComment ) {
2152
- if ( this . sectionProperties . selectedComment . sectionProperties . contentNode . style . display !== 'none' ) {
2153
- const maxMaxHeight = Number ( getComputedStyle ( document . documentElement ) . getPropertyValue ( '--annotation-max-size' ) ) ;
2154
- this . sectionProperties . selectedComment . sectionProperties . contentNode . style . maxHeight = maxMaxHeight + 'px' ;
2154
+ if ( this . sectionProperties . commentList [ i ] . sectionProperties . contentNode . style . display !== 'none' ) {
2155
+ const maxHeight = ( this . sectionProperties . commentList [ i ] === this . sectionProperties . selectedComment ) ?
2156
+ this . annotationMaxSize : this . annotationMinSize ;
2157
+ this . sectionProperties . commentList [ i ] . sectionProperties . contentNode . style . maxHeight = maxHeight + 'px' ;
2155
2158
}
2156
2159
}
2157
2160
}
0 commit comments