@@ -57,6 +57,11 @@ export default class InlineToolbar extends Module<InlineToolbarNodes> {
57
57
*/
58
58
private tools : Map < InlineToolAdapter , IInlineTool > = new Map ( ) ;
59
59
60
+ /**
61
+ * Inline toolbar alignment
62
+ */
63
+ private align : 'left' | 'center' | 'right' = 'left' ;
64
+
60
65
/**
61
66
* @param moduleConfiguration - Module Configuration
62
67
* @param moduleConfiguration.config - Editor's config
@@ -68,6 +73,9 @@ export default class InlineToolbar extends Module<InlineToolbarNodes> {
68
73
eventsDispatcher,
69
74
} ) ;
70
75
76
+ // Get the value from the config
77
+ this . align = config . alignInlineToolbar ?? 'left' ;
78
+
71
79
window . requestIdleCallback ( ( ) => {
72
80
this . make ( ) ;
73
81
} , { timeout : 2000 } ) ;
@@ -218,11 +226,27 @@ export default class InlineToolbar extends Module<InlineToolbarNodes> {
218
226
private move ( popoverWidth : number ) : void {
219
227
const selectionRect = SelectionUtils . rect as DOMRect ;
220
228
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
+
221
246
const newCoords = {
222
- x : selectionRect . x - wrapperOffset . x ,
247
+ x : newX ,
223
248
y : selectionRect . y +
224
249
selectionRect . height -
225
- // + window.scrollY
226
250
wrapperOffset . top +
227
251
this . toolbarVerticalMargin ,
228
252
} ;
@@ -233,7 +257,14 @@ export default class InlineToolbar extends Module<InlineToolbarNodes> {
233
257
* Prevent InlineToolbar from overflowing the content zone on the right side
234
258
*/
235
259
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 ;
237
268
}
238
269
239
270
this . nodes . wrapper ! . style . left = Math . floor ( newCoords . x ) + 'px' ;
0 commit comments