@@ -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,9 @@ 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+
7179 window . requestIdleCallback ( ( ) => {
7280 this . make ( ) ;
7381 } , { timeout : 2000 } ) ;
@@ -218,11 +226,27 @@ export default class InlineToolbar extends Module<InlineToolbarNodes> {
218226 private move ( popoverWidth : number ) : void {
219227 const selectionRect = SelectionUtils . rect as DOMRect ;
220228 const wrapperOffset = this . Editor . UI . nodes . wrapper . getBoundingClientRect ( ) ;
229+
230+
231+ let newX : number ;
232+
233+ switch ( this . align ) {
234+ default :
235+ case 'left' :
236+ newX = selectionRect . x - wrapperOffset . x ;
237+ break ;
238+ case 'right' :
239+ newX = selectionRect . x + selectionRect . width - popoverWidth - wrapperOffset . x ;
240+ break ;
241+ case 'center' :
242+ newX = selectionRect . x + selectionRect . width / 2 - popoverWidth / 2 - wrapperOffset . x ;
243+ break ;
244+ }
245+
221246 const newCoords = {
222- x : selectionRect . x - wrapperOffset . x ,
247+ x : newX ,
223248 y : selectionRect . y +
224249 selectionRect . height -
225- // + window.scrollY
226250 wrapperOffset . top +
227251 this . toolbarVerticalMargin ,
228252 } ;
@@ -233,7 +257,14 @@ export default class InlineToolbar extends Module<InlineToolbarNodes> {
233257 * Prevent InlineToolbar from overflowing the content zone on the right side
234258 */
235259 if ( realRightCoord > this . Editor . UI . contentRect . right ) {
236- newCoords . x = this . Editor . UI . contentRect . right - popoverWidth - wrapperOffset . x ;
260+ newCoords . x = this . Editor . UI . contentRect . right - popoverWidth - wrapperOffset . x ;
261+ }
262+
263+ /**
264+ * Prevent InlineToolbar from overflowing the content zone on the left side
265+ */
266+ if ( newCoords . x < 0 ) {
267+ newCoords . x = 0 ;
237268 }
238269
239270 this . nodes . wrapper ! . style . left = Math . floor ( newCoords . x ) + 'px' ;
0 commit comments