@@ -57,6 +57,11 @@ export default class InlineToolbar extends Module<InlineToolbarNodes> {
5757 */
5858 private tools : Map < InlineToolAdapter , IInlineTool > = new Map ( ) ;
5959
60+ /**
61+ * Inline toolbar alignment
62+ */
63+ private align : 'left' | 'center' | 'right' = 'left' ;
64+
6065 /**
6166 * @param moduleConfiguration - Module Configuration
6267 * @param moduleConfiguration.config - Editor's config
@@ -68,6 +73,11 @@ export default class InlineToolbar extends Module<InlineToolbarNodes> {
6873 eventsDispatcher,
6974 } ) ;
7075
76+ // Get the value from the config
77+ this . align = config . alignInlineToolbar ?? 'left' ;
78+
79+ console . log ( this . align ) ;
80+
7181 window . requestIdleCallback ( ( ) => {
7282 this . make ( ) ;
7383 } , { timeout : 2000 } ) ;
@@ -218,11 +228,23 @@ export default class InlineToolbar extends Module<InlineToolbarNodes> {
218228 private move ( popoverWidth : number ) : void {
219229 const selectionRect = SelectionUtils . rect as DOMRect ;
220230 const wrapperOffset = this . Editor . UI . nodes . wrapper . getBoundingClientRect ( ) ;
231+
232+
233+ let newX : number ;
234+
235+ // Calculate x based on alignment
236+ if ( this . align === 'left' ) {
237+ newX = selectionRect . x - wrapperOffset . x ;
238+ } else if ( this . align === 'right' ) {
239+ newX = selectionRect . x + selectionRect . width - popoverWidth - wrapperOffset . x ;
240+ } else { // center (default)
241+ newX = selectionRect . x + selectionRect . width / 2 - popoverWidth / 2 - wrapperOffset . x ;
242+ }
243+
221244 const newCoords = {
222- x : selectionRect . x - wrapperOffset . x ,
245+ x : newX ,
223246 y : selectionRect . y +
224247 selectionRect . height -
225- // + window.scrollY
226248 wrapperOffset . top +
227249 this . toolbarVerticalMargin ,
228250 } ;
@@ -233,7 +255,14 @@ export default class InlineToolbar extends Module<InlineToolbarNodes> {
233255 * Prevent InlineToolbar from overflowing the content zone on the right side
234256 */
235257 if ( realRightCoord > this . Editor . UI . contentRect . right ) {
236- newCoords . x = this . Editor . UI . contentRect . right - popoverWidth - wrapperOffset . x ;
258+ newCoords . x = this . Editor . UI . contentRect . right - popoverWidth - wrapperOffset . x ;
259+ }
260+
261+ /**
262+ * Prevent InlineToolbar from overflowing the content zone on the left side
263+ */
264+ if ( newCoords . x < 0 ) {
265+ newCoords . x = 0 ;
237266 }
238267
239268 this . nodes . wrapper ! . style . left = Math . floor ( newCoords . x ) + 'px' ;
0 commit comments