@@ -124,11 +124,11 @@ function isLastChildVisible(container) {
124
124
}
125
125
126
126
function SplitPane ( { messageRef, topElement, bottomElement} ) {
127
- let [ dragging , setDragging ] = useState ( false )
127
+ let [ dragBase , setDragBase ] = useState ( Number . NaN )
128
128
let [ splitPos , setSplitPos ] = useState ( 200 )
129
129
let draggingRef = useRef ( )
130
130
let containerRef = useRef ( )
131
- draggingRef . current = dragging
131
+ draggingRef . current = dragBase
132
132
useEffect ( ( ) => {
133
133
let mousemove = ( e ) => {
134
134
if ( ! draggingRef . current ) {
@@ -141,20 +141,20 @@ function SplitPane({messageRef, topElement, bottomElement}) {
141
141
return
142
142
}
143
143
setSplitPos ( getSplitPos ( e . clientY , containerRef . current ) )
144
- setDragging ( false )
144
+ setDragBase ( Number . NaN )
145
145
}
146
146
window . document . addEventListener ( "mousemove" , mousemove )
147
147
window . document . addEventListener ( "mouseup" , mouseup )
148
148
return ( ) => {
149
149
window . document . removeEventListener ( "mousemove" , mousemove )
150
150
window . document . removeEventListener ( "mouseup" , mouseup )
151
151
}
152
- } , [ draggingRef , setDragging ] )
152
+ } , [ draggingRef , setDragBase ] )
153
153
let onMouseDown = useCallback ( ( e ) => {
154
154
e . preventDefault ( )
155
155
setSplitPos ( getSplitPos ( e . clientY , containerRef . current ) )
156
- setDragging ( true )
157
- } , [ setDragging , setSplitPos ] )
156
+ setDragBase ( e . clientY )
157
+ } , [ setDragBase , setSplitPos ] )
158
158
let topElementHeight = Math . trunc ( splitPos )
159
159
if ( containerRef . current ) {
160
160
let rect = containerRef . current . getBoundingClientRect ( )
@@ -174,7 +174,7 @@ function SplitPane({messageRef, topElement, bottomElement}) {
174
174
} }
175
175
className = { twJoin (
176
176
"grow border-t border-x border-gray-500 bg-gray-900 flex flex-col overflow-y-hidden" ,
177
- dragging && "cursor-row-resize" ,
177
+ ! Number . isNaN ( dragBase ) && "cursor-row-resize" ,
178
178
) } >
179
179
< div
180
180
style = { { height : topElementHeight + "px" } }
@@ -184,7 +184,7 @@ function SplitPane({messageRef, topElement, bottomElement}) {
184
184
< SplitBar
185
185
container = { containerRef . current }
186
186
splitPos = { splitPos }
187
- dragging = { dragging }
187
+ dragBase = { dragBase }
188
188
onMouseDown = { onMouseDown } />
189
189
< div ref = { messageRef } className = "px-1 pt-3 pb-1 overflow-y-scroll" >
190
190
{ bottomElement }
@@ -193,7 +193,7 @@ function SplitPane({messageRef, topElement, bottomElement}) {
193
193
)
194
194
}
195
195
196
- function SplitBar ( { splitPos, dragging , onMouseDown, container} ) {
196
+ function SplitBar ( { splitPos, dragBase , onMouseDown, container} ) {
197
197
if ( ! container ) {
198
198
return < div />
199
199
}
@@ -204,15 +204,15 @@ function SplitBar({splitPos, dragging, onMouseDown, container}) {
204
204
let left = rect . left - parentRect . left
205
205
return < >
206
206
< div
207
- onMouseDown = { dragging ? undefined : onMouseDown }
207
+ onMouseDown = { Number . isNaN ( dragBase ) ? onMouseDown : undefined }
208
208
style = { { top : Math . trunc ( splitPos - 1 ) + 0.5 , height : 1 , width : width , left : left } }
209
209
className = "absolute h-[1px] bg-gray-500 z-20 cursor-row-resize" />
210
210
< div
211
- onMouseDown = { dragging ? undefined : onMouseDown }
211
+ onMouseDown = { Number . isNaN ( dragBase ) ? onMouseDown : undefined }
212
212
style = { { top : Math . trunc ( splitPos ) + 0.5 , height : innerHeight , width : width , left : left } }
213
213
className = "absolute bg-slate-800 z-20 cursor-row-resize" />
214
214
< div
215
- onMouseDown = { dragging ? undefined : onMouseDown }
215
+ onMouseDown = { Number . isNaN ( dragBase ) ? onMouseDown : undefined }
216
216
style = { { top : Math . trunc ( splitPos + innerHeight ) + 0.5 , height : 1 , width : width , left : left } }
217
217
className = "absolute h-[1px] bg-gray-500 z-20 cursor-row-resize" />
218
218
</ >
0 commit comments