File tree Expand file tree Collapse file tree 3 files changed +17
-31
lines changed
packages/richtext-lexical/src/field/lexical/plugins/handles Expand file tree Collapse file tree 3 files changed +17
-31
lines changed Original file line number Diff line number Diff line change @@ -113,33 +113,14 @@ function useAddBlockHandle(
113
113
114
114
useEffect ( ( ) => {
115
115
if ( menuRef . current && hoveredElement ?. node ) {
116
- editor . getEditorState ( ) . read ( ( ) => {
117
- // Check if blockNode is an empty text node
118
- let isEmptyParagraph = true
119
- if (
120
- hoveredElement . node . getType ( ) !== 'paragraph' ||
121
- hoveredElement . node . getTextContent ( ) !== ''
122
- ) {
123
- isEmptyParagraph = false
124
- }
125
-
126
- setHandlePosition (
127
- hoveredElement ?. elem ,
128
- menuRef . current ,
129
- anchorElem ,
130
- isEmptyParagraph
131
- ? blockHandleHorizontalOffset
132
- : blockHandleHorizontalOffset - ( editorConfig ?. admin ?. hideGutter ? 20 : 0 ) ,
133
- )
134
- } )
116
+ setHandlePosition (
117
+ hoveredElement ?. elem ,
118
+ menuRef . current ,
119
+ anchorElem ,
120
+ blockHandleHorizontalOffset ,
121
+ )
135
122
}
136
- } , [
137
- anchorElem ,
138
- hoveredElement ,
139
- editor ,
140
- blockHandleHorizontalOffset ,
141
- editorConfig ?. admin ?. hideGutter ,
142
- ] )
123
+ } , [ anchorElem , hoveredElement , blockHandleHorizontalOffset ] )
143
124
144
125
const handleAddClick = useCallback (
145
126
( event ) => {
Original file line number Diff line number Diff line change @@ -80,7 +80,7 @@ function useDraggableBlockMenu(
80
80
const [ lastTargetBlockElem , setLastTargetBlockElem ] = useState < HTMLElement | null > ( null )
81
81
const { editorConfig } = useEditorConfigContext ( )
82
82
83
- const blockHandleHorizontalOffset = editorConfig ?. admin ?. hideGutter ? - 24 : - 8
83
+ const blockHandleHorizontalOffset = editorConfig ?. admin ?. hideGutter ? - 44 : - 8
84
84
85
85
useEffect ( ( ) => {
86
86
/**
@@ -212,7 +212,11 @@ function useDraggableBlockMenu(
212
212
213
213
if ( draggableBlockElem !== targetBlockElem ) {
214
214
setTargetLine (
215
- blockHandleHorizontalOffset ,
215
+ editorConfig ?. admin ?. hideGutter ? '0px' : '3rem' ,
216
+ blockHandleHorizontalOffset +
217
+ ( editorConfig ?. admin ?. hideGutter
218
+ ? menuRef ?. current ?. getBoundingClientRect ( ) ?. width ?? 0
219
+ : - menuRef ?. current ?. getBoundingClientRect ( ) ?. width ?? 0 ) ,
216
220
targetLineElem ,
217
221
targetBlockElem ,
218
222
lastTargetBlockElem ,
Original file line number Diff line number Diff line change @@ -6,7 +6,8 @@ const TEXT_BOX_HORIZONTAL_PADDING = -24
6
6
const DEBUG = false
7
7
8
8
export function setTargetLine (
9
- SPACE : number ,
9
+ offsetWidth : string ,
10
+ offsetLeft : number ,
10
11
targetLineElem : HTMLElement ,
11
12
targetBlockElem : HTMLElement ,
12
13
lastTargetBlockElem : HTMLElement | null ,
@@ -51,10 +52,10 @@ export function setTargetLine(
51
52
if ( ! isBelow ) {
52
53
top -= TARGET_LINE_HALF_HEIGHT * 2
53
54
}
54
- const left = TEXT_BOX_HORIZONTAL_PADDING - SPACE
55
+ const left = TEXT_BOX_HORIZONTAL_PADDING - offsetLeft
55
56
56
57
targetLineElem . style . transform = `translate(${ left } px, ${ top } px)`
57
- targetLineElem . style . width = `${ anchorWidth - ( TEXT_BOX_HORIZONTAL_PADDING - SPACE ) * 2 } px `
58
+ targetLineElem . style . width = `calc( ${ anchorWidth } px - ${ offsetWidth } ) `
58
59
targetLineElem . style . opacity = '.4'
59
60
60
61
/**
You can’t perform that action at this time.
0 commit comments