Skip to content

Commit 4a35137

Browse files
pattonwebzclaude
andauthored
PRO-1081: Make CodeMirror code viewer resizable
* PRO-1081: Make CodeMirror code viewer resizable - Switch .CodeMirror from fixed height: 100px to min-height: 100px so the box starts compact but can be dragged taller - Add max-height: 600px to keep it bounded by default - Set resize: vertical and overflow: hidden to enable the native resize handle (overflow must be non-visible for CSS resize to work; CodeMirror-scroll handles internal scrolling independently) - Add ResizeObserver in CodeMirrorViewer to call cm.refresh() after each drag, keeping line rendering correct after the container height changes Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * PRO-1081: Tighten ResizeObserver — rAF, guard, cancel on cleanup - Default height 160px (down from 320px) - Guard ResizeObserver construction behind window.ResizeObserver check - Wrap refresh() call in requestAnimationFrame to avoid "ResizeObserver loop limit exceeded" errors; cancel pending rAF on unmount Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 7d9c53c commit 4a35137

2 files changed

Lines changed: 25 additions & 1 deletion

File tree

src/issueModal/components/CodeMirrorViewer.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,25 @@ const CodeMirrorViewer = ( { value } ) => {
4242

4343
editorRef.current = window.wp.codeEditor.initialize( textareaRef.current, editorSettings );
4444

45+
// When the user drags the resize handle, CodeMirror's JS viewport
46+
// measurements don't update automatically. Observing the wrapper element
47+
// and calling refresh() keeps line rendering correct after a resize.
48+
// rAF defers the refresh out of the ResizeObserver callback to avoid
49+
// "ResizeObserver loop limit exceeded" errors in some browsers.
50+
const cmEl = editorRef.current.codemirror.getWrapperElement();
51+
let rafId;
52+
const observer = window.ResizeObserver
53+
? new ResizeObserver( () => {
54+
cancelAnimationFrame( rafId );
55+
rafId = requestAnimationFrame( () => editorRef.current?.codemirror?.refresh() );
56+
} )
57+
: null;
58+
observer?.observe( cmEl );
59+
4560
// Cleanup on unmount
4661
return () => {
62+
cancelAnimationFrame( rafId );
63+
observer?.disconnect();
4764
if ( editorRef.current?.codemirror ) {
4865
editorRef.current.codemirror.toTextArea();
4966
editorRef.current = null;

src/issueModal/sass/issue-modal.scss

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,14 @@
404404
}
405405

406406
.CodeMirror {
407-
height: 100px;
407+
// overflow: hidden is required for CSS resize to work (visible blocks
408+
// the resize handle). CodeMirror's own .CodeMirror-scroll handles
409+
// internal scrolling.
410+
height: 160px;
411+
min-height: 100px;
412+
max-height: 600px;
413+
resize: vertical;
414+
overflow: hidden;
408415
border: 1px solid #ddd;
409416
border-radius: 4px;
410417
font-size: 12px;

0 commit comments

Comments
 (0)