Skip to content

Commit 60e68b3

Browse files
committed
Resize editor by dragging the bottom-right corner
1 parent 6b16e7d commit 60e68b3

File tree

2 files changed

+102
-2
lines changed

2 files changed

+102
-2
lines changed

src/components/editor/Editor.tsx

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@ export const Editor: React.FC<EditorProps> = ({ query, onChange, startDate, endD
139139
const tableNameRef = useRef<string>(tableName || '');
140140
const [editorHeight, setEditorHeight] = useState("250px");
141141
const lastMousePosition = useRef({ x: 0, y: 0 });
142+
const containerRef = useRef<HTMLDivElement>(null);
143+
const isDraggingRef = useRef(false);
142144

143145
useEffect(() => {
144146
tableDefinitionsRef.current = tableDefinitions || [];
@@ -561,8 +563,40 @@ export const Editor: React.FC<EditorProps> = ({ query, onChange, startDate, endD
561563
}
562564
};
563565

566+
const handleMouseDown = (e: React.MouseEvent) => {
567+
isDraggingRef.current = true;
568+
document.addEventListener('mousemove', handleMouseMove);
569+
document.addEventListener('mouseup', handleMouseUp);
570+
};
571+
572+
const handleMouseMove = useCallback((e: MouseEvent) => {
573+
if (!isDraggingRef.current || !containerRef.current) return;
574+
575+
const containerRect = containerRef.current.getBoundingClientRect();
576+
const newHeight = Math.max(150, e.clientY - containerRect.top);
577+
setEditorHeight(`${newHeight}px`);
578+
579+
// Trigger Monaco editor layout update
580+
if (editorRef.current) {
581+
editorRef.current.layout();
582+
}
583+
}, []);
584+
585+
const handleMouseUp = useCallback(() => {
586+
isDraggingRef.current = false;
587+
document.removeEventListener('mousemove', handleMouseMove);
588+
document.removeEventListener('mouseup', handleMouseUp);
589+
}, [handleMouseMove]);
590+
591+
useEffect(() => {
592+
return () => {
593+
document.removeEventListener('mousemove', handleMouseMove);
594+
document.removeEventListener('mouseup', handleMouseUp);
595+
};
596+
}, [handleMouseMove, handleMouseUp]);
597+
564598
return (
565-
<div className="EditorContainer">
599+
<div ref={containerRef} className="EditorContainer" style={{ position: 'relative' }}>
566600
<MonacoEditor
567601
height={editorHeight}
568602
language="pipe-sql"
@@ -583,7 +617,19 @@ export const Editor: React.FC<EditorProps> = ({ query, onChange, startDate, endD
583617
onChange={handleChange}
584618
onMount={handleEditorDidMount}
585619
/>
586-
620+
<div
621+
className="resize-handle"
622+
onMouseDown={handleMouseDown}
623+
style={{
624+
position: 'absolute',
625+
bottom: 0,
626+
right: 0,
627+
width: '20px',
628+
height: '20px',
629+
cursor: 'se-resize',
630+
background: 'transparent'
631+
}}
632+
/>
587633
</div>
588634
);
589635
};

src/components/styles/main.css

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,4 +326,58 @@
326326
background: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><path d="M5 2H7V14H5V2ZM9 2H11V14H9V2Z" fill="%23CC8400"/></svg>') center center no-repeat;
327327
cursor: pointer;
328328
background-size: 12px;
329+
}
330+
331+
.resize-handle {
332+
position: absolute;
333+
bottom: 0;
334+
right: 0;
335+
width: 16px;
336+
height: 16px;
337+
cursor: se-resize;
338+
display: flex;
339+
align-items: flex-end;
340+
justify-content: flex-end;
341+
}
342+
343+
.resize-handle::after {
344+
content: '';
345+
display: block;
346+
width: 10px;
347+
height: 10px;
348+
background-image: linear-gradient(
349+
135deg,
350+
transparent 0%,
351+
transparent 20%,
352+
rgba(204, 204, 220, 0.3) 20%,
353+
rgba(204, 204, 220, 0.3) 40%,
354+
transparent 40%,
355+
transparent 60%,
356+
rgba(204, 204, 220, 0.3) 60%,
357+
rgba(204, 204, 220, 0.3) 80%,
358+
transparent 80%,
359+
transparent 100%
360+
);
361+
transition: all 0.2s ease;
362+
}
363+
364+
.resize-handle:hover::after {
365+
background-image: linear-gradient(
366+
135deg,
367+
transparent 0%,
368+
transparent 20%,
369+
rgba(204, 204, 220, 0.6) 20%,
370+
rgba(204, 204, 220, 0.6) 40%,
371+
transparent 40%,
372+
transparent 60%,
373+
rgba(204, 204, 220, 0.6) 60%,
374+
rgba(204, 204, 220, 0.6) 80%,
375+
transparent 80%,
376+
transparent 100%
377+
);
378+
}
379+
380+
/* Remove the hover state since we want it always visible */
381+
.EditorContainer:hover .resize-handle {
382+
opacity: 1;
329383
}

0 commit comments

Comments
 (0)