@@ -404,15 +404,18 @@ Offset.prototype = {
404404 if ( this . options . get ( '_rtl' ) ) {
405405 const rtlW = ew > tw ? ew - tw : 0 ;
406406 const rtlL = rtlW > 0 ? 0 : tw - ew ;
407- element . style . left = `${ tl - rtlW + rtlL + tcleft } px` ;
407+ element . style . left = `${ tl - rtlW + rtlL } px` ;
408408 if ( tcleft > this . getGlobal ( element ) . left ) {
409409 element . style . left = tcleft + 'px' ;
410410 }
411411 } else {
412412 const cw = t_container . offsetWidth + tcleft ;
413413 const overLeft = cw <= ew ? 0 : cw - ( tl + ew ) ;
414- if ( overLeft < 0 ) element . style . left = `${ tl + overLeft + tcleft } px` ;
415- else element . style . left = `${ tl } px` ;
414+ if ( overLeft < 0 ) {
415+ element . style . left = `${ tl + overLeft } px` ;
416+ } else {
417+ element . style . left = `${ tl } px` ;
418+ }
416419 }
417420 } ,
418421
@@ -427,7 +430,6 @@ Offset.prototype = {
427430 * @param {"bottom"|"top" } [params.position="bottom"] Position ('bottom'|'top')
428431 * @param {* } params.inst Instance object of caller
429432 * @param {HTMLElement } [params.sibling=null] The sibling controller element
430- * @param {boolean } [params.isWWScroll=false] Indicates if the scroll event is from the wysiwyg area
431433 * @returns {{position: "top" | "bottom"} | undefined } Success -> {position: current position}
432434 */
433435 setAbsPosition ( element , target , params ) {
@@ -470,34 +472,32 @@ Offset.prototype = {
470472 const th = this . context . get ( 'toolbar_main' ) . offsetHeight ;
471473 const containerToolbar = this . options . get ( 'toolbar_container' ) ;
472474 const headLess = this . editor . isBalloon || this . editor . isInline || containerToolbar ;
473- const toolbarH = ( containerToolbar && globalTop - wScrollY - th > 0 ) || ( ! this . editor . toolbar . isSticky && headLess ) ? 0 : th + ( this . editor . toolbar . isSticky ? this . options . get ( 'toolbar_sticky' ) : 0 ) ;
475+ const toolbarH = ( containerToolbar && globalTop - wScrollY - th > 0 ) || ( ! this . toolbar . isSticky && headLess ) ? 0 : th + ( this . toolbar . isSticky ? this . options . get ( 'toolbar_sticky' ) : 0 ) ;
476+ const statusBarH = this . frameContext . get ( 'statusbar' ) ?. offsetHeight || 0 ;
474477
475478 // check margin
476- const { rmt, rmb, bMargin, rt } = this . _getVMargin ( tmtw , tmbw , toolbarH , clientSize , targetRect , isTextSelection , params . isWWScroll , isToolbarTarget ) ;
477- if ( ( isWWTarget && ( ( rmb > 0 ? bMargin : rmb ) + targetH <= 0 || rmt + rt + targetH - ( this . editor . toolbar . isSticky && isInlineTarget ? toolbarH : 0 ) <= 0 ) ) || rmt + targetH < 0 ) return ;
479+ const { rmt, rmb, bMargin, rt } = this . _getVMargin ( tmtw , tmbw , toolbarH , clientSize , targetRect , isTextSelection , isToolbarTarget ) ;
480+ if ( ( isWWTarget && ( rmb - statusBarH + targetH <= 0 || rmt + rt + targetH - ( this . toolbar . isSticky && isInlineTarget ? toolbarH : 0 ) <= 0 ) ) || rmt + targetH < 0 ) return ;
478481
479- const isSticky = this . editor . toolbar . isSticky && this . context . get ( 'toolbar_main' ) . style . display !== 'none' && ( ! headLess || this . frameContext . get ( 'topArea' ) . getBoundingClientRect ( ) . top <= th ) ;
480- const statusBarH = this . frameContext . get ( 'statusbar' ) ?. offsetHeight || 0 ;
482+ const isSticky = this . toolbar . isSticky && this . context . get ( 'toolbar_main' ) . style . display !== 'none' && ( ! headLess || this . frameContext . get ( 'topArea' ) . getBoundingClientRect ( ) . top <= th ) ;
481483 let t = addOffset . top ;
482484 let y = 0 ;
483485 let arrowDir = '' ;
484486
485487 // [bottom] position
486488 if ( position === 'bottom' ) {
487- let trmt = rmt - ( isSticky && globalTop - wScrollY <= toolbarH ? toolbarH : 0 ) ;
488- if ( isSticky && trmt + toolbarH < 0 ) trmt += toolbarH ;
489489 arrowDir = 'up' ;
490490 t += targetRect . bottom + ah + wScrollY ;
491- y = rmb - ( elH + ah ) - statusBarH ;
491+ y = rmb - ( elH + ah ) ;
492492 // change to <top> position
493493 if ( y - siblingH < 0 ) {
494494 arrowDir = 'down' ;
495495 t -= targetH + elH + ah * 2 ;
496- y = trmt - ( elH + ah ) ;
496+ y = rmt - ( elH + ah ) ;
497497 // sticky the <top> position
498498 if ( y - siblingH < 0 ) {
499499 arrowDir = '' ;
500- t -= y - siblingH - Math . max ( 1 , y + elH + ah ) + ( ! isSticky && trmt < 0 ? toolbarH : 0 ) - ( isSticky ? this . context . get ( 'toolbar_main' ) . offsetTop : 0 ) ;
500+ t -= y - siblingH - Math . max ( 1 , y + elH + ah ) ;
501501 }
502502 }
503503 }
@@ -639,9 +639,9 @@ Offset.prototype = {
639639 const targetH = rects . height ;
640640 const tmtw = rects . top ;
641641 const tmbw = clientSize . h - rects . bottom ;
642- const toolbarH = ! this . editor . toolbar . isSticky && ( this . editor . isBalloon || this . editor . isInline ) ? 0 : this . context . get ( 'toolbar_main' ) . offsetHeight ;
642+ const toolbarH = ! this . toolbar . isSticky && ( this . editor . isBalloon || this . editor . isInline ) ? 0 : this . context . get ( 'toolbar_main' ) . offsetHeight ;
643643
644- const { rmt, rmb, rt } = this . _getVMargin ( tmtw , tmbw , toolbarH , clientSize , rects , isTextSelection , false , false ) ;
644+ const { rmt, rmb, rt } = this . _getVMargin ( tmtw , tmbw , toolbarH , clientSize , rects , isTextSelection , false ) ;
645645 if ( rmb + targetH <= 0 || rmt + rt + targetH <= 0 ) return ;
646646
647647 element . style . visibility = '' ;
@@ -727,7 +727,6 @@ Offset.prototype = {
727727 * @param {{w: number, h: number} } clientSize documentElement.clientWidth, documentElement.clientHeight
728728 * @param {RectsInfo } targetRect Target rect object
729729 * @param {boolean } isTextSelection Is text selection or Range
730- * @param {boolean } isWWScroll Indicates if the scroll event is from the wysiwyg area
731730 * @param {boolean } isToolbarTarget Indicates if the target is a toolbar element
732731 * @returns {{rmt:number, rmb:number, rt:number, tMargin:number, bMargin:number} } Margin values
733732 * - rmt: top margin to frame
@@ -736,7 +735,7 @@ Offset.prototype = {
736735 * - tMargin: top margin
737736 * - bMargin: bottom margin
738737 */
739- _getVMargin ( tmtw , tmbw , toolbarH , clientSize , targetRect , isTextSelection , isWWScroll , isToolbarTarget ) {
738+ _getVMargin ( tmtw , tmbw , toolbarH , clientSize , targetRect , isTextSelection , isToolbarTarget ) {
740739 const isScrollable = this . status . isScrollable ( ) ;
741740 const wwRects = this . selection . getRects ( this . frameContext . get ( 'wysiwyg' ) , 'start' ) . rects ;
742741
@@ -754,27 +753,25 @@ Offset.prototype = {
754753 tMargin = targetRect . top ;
755754 bMargin = clientSize . h - targetRect . bottom ;
756755 const editorOffset = this . getGlobal ( ) ;
757- const editorScroll = this . getGlobalScroll ( ) ;
758- const statusBarH = this . frameContext . get ( 'statusbar' ) ?. offsetHeight || 0 ;
759756
760757 if ( ! isTextSelection ) {
761- const emt = ! isToolbarTarget ? editorOffset . top - editorScroll . top - editorScroll . ts : 0 ;
762- const editorH = this . frameContext . get ( 'topArea' ) . offsetHeight ;
763- rt = ! isToolbarTarget && ( this . editor . toolbar . isSticky || ( isScrollable && ! this . toolbar . _isBalloon ) ) ? toolbarH : 0 ;
764- rmt = targetRect . top - ( targetRect . top < 0 && emt < 0 ? 0 : emt ) - rt ;
765- rmb = bMargin - ( isWWScroll ? editorScroll . oh - ( editorH + emt ) : 0 ) - statusBarH ;
758+ const emt = editorOffset . fixedTop > 0 ? editorOffset . fixedTop : 0 ;
759+ const emb = _w . innerHeight - ( editorOffset . fixedTop + editorOffset . height ) ;
760+ rt = ! isToolbarTarget && ( this . toolbar . isSticky || ( isScrollable && ! this . toolbar . _isBalloon ) ) ? toolbarH : 0 ;
761+ rmt = tMargin - ( ! isToolbarTarget ? emt : 0 ) - rt ;
762+ rmb = bMargin - ( emb > 0 ? emb : 0 ) ;
766763 } else {
767- rt = ! isToolbarTarget && ! this . editor . toolbar . isSticky && ! this . options . get ( 'toolbar_container' ) ? toolbarH : 0 ;
764+ rt = ! isToolbarTarget && ! this . toolbar . isSticky && ! this . options . get ( 'toolbar_container' ) ? toolbarH : 0 ;
768765 const wst = ! isIframe ? editorOffset . top - _w . scrollY + rt : 0 ;
769766 const wsb = ! isIframe ? this . status . currentViewportHeight - ( editorOffset . top + editorOffset . height - _w . scrollY ) : 0 ;
770767 let st = wst ;
771768 if ( toolbarH > wst ) {
772- if ( this . editor . toolbar . isSticky ) {
769+ if ( this . toolbar . isSticky ) {
773770 st = toolbarH ;
774771 } else {
775772 st = wst + toolbarH ;
776773 }
777- } else if ( this . options . get ( 'toolbar_container' ) && ! this . editor . toolbar . isSticky ) {
774+ } else if ( this . options . get ( 'toolbar_container' ) && ! this . toolbar . isSticky ) {
778775 toolbarH = 0 ;
779776 } else {
780777 st = wst + toolbarH ;
0 commit comments