@@ -296,34 +296,40 @@ export const setPadding = (protyle: IProtyle) => {
296296 padding : 0
297297 } ;
298298 }
299- const oldLeft = parseInt ( protyle . wysiwyg . element . style . paddingLeft ) ;
299+ const oldLeft = parseInt ( protyle . wysiwyg . element . style . paddingLeft || "0" ) ;
300300 const padding = getPadding ( protyle ) ;
301- const left = padding . left ;
302- const right = padding . right ;
301+ const paddingLeft = padding . left ;
302+ const paddingRight = padding . right ;
303+
304+ const protyleWidth = protyle . element . clientWidth ;
305+ const scrollbarWidth = protyle . contentElement . offsetWidth - protyle . contentElement . clientWidth ;
306+ const contentWidth = protyleWidth - scrollbarWidth ;
307+
308+ const wysiwygOldWidth = parseInt ( protyle . wysiwyg . element . getAttribute ( "data-realwidth" ) || "0" ) ;
309+ const wysiwygNewWidth = contentWidth - paddingLeft - paddingRight ;
310+
311+ // https://github.com/siyuan-note/siyuan/issues/15021
312+ protyle . element . style . setProperty ( "--b3-width-protyle" , protyleWidth + "px" ) ;
313+ protyle . element . style . setProperty ( "--b3-width-protyle-content" , contentWidth + "px" ) ;
314+ protyle . element . style . setProperty ( "--b3-width-protyle-wysiwyg" , wysiwygNewWidth . toString ( ) + "px" ) ;
315+ protyle . wysiwyg . element . setAttribute ( "data-realwidth" , wysiwygNewWidth . toString ( ) ) ;
316+
303317 if ( protyle . options . backlinkData ) {
304- protyle . wysiwyg . element . style . padding = `4px ${ right } px 4px ${ left } px` ;
318+ protyle . wysiwyg . element . style . padding = `4px ${ paddingRight } px 4px ${ paddingLeft } px` ;
305319 } else {
306- protyle . wysiwyg . element . style . padding = `${ padding . top } px ${ right } px ${ padding . bottom } px ${ left } px` ;
320+ protyle . wysiwyg . element . style . padding = `${ padding . top } px ${ paddingRight } px ${ padding . bottom } px ${ paddingLeft } px` ;
307321 }
308322 if ( protyle . options . render . background ) {
309- protyle . background . element . querySelector ( ".protyle-background__ia" ) . setAttribute ( "style" , `margin-left:${ left } px;margin-right:${ right } px` ) ;
323+ protyle . background . element . querySelector ( ".protyle-background__ia" ) . setAttribute ( "style" , `margin-left:${ paddingLeft } px;margin-right:${ paddingRight } px` ) ;
310324 }
311325 if ( protyle . options . render . title ) {
312326 // pc 端 文档名 attr 过长和添加标签等按钮重合
313- protyle . title . element . style . margin = `16px ${ right } px 0 ${ left } px` ;
327+ protyle . title . element . style . margin = `16px ${ paddingRight } px 0 ${ paddingLeft } px` ;
314328 }
315- if ( window . siyuan . config . editor . displayBookmarkIcon ) {
316- const editorAttrElement = document . getElementById ( "editorAttr" ) ;
317- if ( editorAttrElement ) {
318- editorAttrElement . innerHTML = `.protyle-wysiwyg--attr .b3-tooltips::after { max-width: ${ protyle . wysiwyg . element . clientWidth - left - right } px; }` ;
319- }
320- }
321- const oldWidth = protyle . wysiwyg . element . getAttribute ( "data-realwidth" ) ;
322- const newWidth = protyle . wysiwyg . element . clientWidth - parseInt ( protyle . wysiwyg . element . style . paddingLeft ) - parseInt ( protyle . wysiwyg . element . style . paddingRight ) ;
323- protyle . wysiwyg . element . setAttribute ( "data-realwidth" , newWidth . toString ( ) ) ;
329+
324330 return {
325- width : Math . abs ( parseInt ( oldWidth ) - newWidth ) ,
326- padding : Math . abs ( oldLeft - parseInt ( protyle . wysiwyg . element . style . paddingLeft ) )
331+ width : Math . abs ( wysiwygOldWidth - wysiwygNewWidth ) ,
332+ padding : Math . abs ( oldLeft - paddingLeft )
327333 } ;
328334} ;
329335
0 commit comments