@@ -287,34 +287,40 @@ export const setPadding = (protyle: IProtyle) => {
287287 padding : 0
288288 } ;
289289 }
290- const oldLeft = parseInt ( protyle . wysiwyg . element . style . paddingLeft ) ;
290+ const oldLeft = parseInt ( protyle . wysiwyg . element . style . paddingLeft || "0" ) ;
291291 const padding = getPadding ( protyle ) ;
292- const left = padding . left ;
293- const right = padding . right ;
292+ const paddingLeft = padding . left ;
293+ const paddingRight = padding . right ;
294+
295+ const protyleWidth = protyle . element . clientWidth ;
296+ const scrollbarWidth = protyle . contentElement . offsetWidth - protyle . contentElement . clientWidth ;
297+ const contentWidth = protyleWidth - scrollbarWidth ;
298+
299+ const wysiwygOldWidth = parseInt ( protyle . wysiwyg . element . getAttribute ( "data-realwidth" ) || "0" ) ;
300+ const wysiwygNewWidth = contentWidth - paddingLeft - paddingRight ;
301+
302+ // https://github.com/siyuan-note/siyuan/issues/15021
303+ protyle . element . style . setProperty ( "--b3-width-protyle" , protyleWidth + "px" ) ;
304+ protyle . element . style . setProperty ( "--b3-width-protyle-content" , contentWidth + "px" ) ;
305+ protyle . element . style . setProperty ( "--b3-width-protyle-wysiwyg" , wysiwygNewWidth . toString ( ) + "px" ) ;
306+ protyle . wysiwyg . element . setAttribute ( "data-realwidth" , wysiwygNewWidth . toString ( ) ) ;
307+
294308 if ( protyle . options . backlinkData ) {
295- protyle . wysiwyg . element . style . padding = `4px ${ right } px 4px ${ left } px` ;
309+ protyle . wysiwyg . element . style . padding = `4px ${ paddingRight } px 4px ${ paddingLeft } px` ;
296310 } else {
297- protyle . wysiwyg . element . style . padding = `${ padding . top } px ${ right } px ${ padding . bottom } px ${ left } px` ;
311+ protyle . wysiwyg . element . style . padding = `${ padding . top } px ${ paddingRight } px ${ padding . bottom } px ${ paddingLeft } px` ;
298312 }
299313 if ( protyle . options . render . background ) {
300- protyle . background . element . querySelector ( ".protyle-background__ia" ) . setAttribute ( "style" , `margin-left:${ left } px;margin-right:${ right } px` ) ;
314+ protyle . background . element . querySelector ( ".protyle-background__ia" ) . setAttribute ( "style" , `margin-left:${ paddingLeft } px;margin-right:${ paddingRight } px` ) ;
301315 }
302316 if ( protyle . options . render . title ) {
303317 // pc 端 文档名 attr 过长和添加标签等按钮重合
304- protyle . title . element . style . margin = `16px ${ right } px 0 ${ left } px` ;
318+ protyle . title . element . style . margin = `16px ${ paddingRight } px 0 ${ paddingLeft } px` ;
305319 }
306- if ( window . siyuan . config . editor . displayBookmarkIcon ) {
307- const editorAttrElement = document . getElementById ( "editorAttr" ) ;
308- if ( editorAttrElement ) {
309- editorAttrElement . innerHTML = `.protyle-wysiwyg--attr .b3-tooltips::after { max-width: ${ protyle . wysiwyg . element . clientWidth - left - right } px; }` ;
310- }
311- }
312- const oldWidth = protyle . wysiwyg . element . getAttribute ( "data-realwidth" ) ;
313- const newWidth = protyle . wysiwyg . element . clientWidth - parseInt ( protyle . wysiwyg . element . style . paddingLeft ) - parseInt ( protyle . wysiwyg . element . style . paddingRight ) ;
314- protyle . wysiwyg . element . setAttribute ( "data-realwidth" , newWidth . toString ( ) ) ;
320+
315321 return {
316- width : Math . abs ( parseInt ( oldWidth ) - newWidth ) ,
317- padding : Math . abs ( oldLeft - parseInt ( protyle . wysiwyg . element . style . paddingLeft ) )
322+ width : Math . abs ( wysiwygOldWidth - wysiwygNewWidth ) ,
323+ padding : Math . abs ( oldLeft - paddingLeft )
318324 } ;
319325} ;
320326
0 commit comments