@@ -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,11 @@ 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
+
79
+ console . log ( this . align ) ;
80
+
71
81
window . requestIdleCallback ( ( ) => {
72
82
this . make ( ) ;
73
83
} , { timeout : 2000 } ) ;
@@ -218,11 +228,23 @@ export default class InlineToolbar extends Module<InlineToolbarNodes> {
218
228
private move ( popoverWidth : number ) : void {
219
229
const selectionRect = SelectionUtils . rect as DOMRect ;
220
230
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
+
221
244
const newCoords = {
222
- x : selectionRect . x - wrapperOffset . x ,
245
+ x : newX ,
223
246
y : selectionRect . y +
224
247
selectionRect . height -
225
- // + window.scrollY
226
248
wrapperOffset . top +
227
249
this . toolbarVerticalMargin ,
228
250
} ;
@@ -233,7 +255,14 @@ export default class InlineToolbar extends Module<InlineToolbarNodes> {
233
255
* Prevent InlineToolbar from overflowing the content zone on the right side
234
256
*/
235
257
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 ;
237
266
}
238
267
239
268
this . nodes . wrapper ! . style . left = Math . floor ( newCoords . x ) + 'px' ;
0 commit comments