diff --git a/src/views/conflicts-resolution/actions-gutter.tsx b/src/views/conflicts-resolution/actions-gutter.tsx index 71f2e6d..f40abfd 100644 --- a/src/views/conflicts-resolution/actions-gutter.tsx +++ b/src/views/conflicts-resolution/actions-gutter.tsx @@ -6,14 +6,27 @@ interface ActionsGutterProps { // This is essential to correctly draw the lines between // the left and right editor lineHeight: number; - width: number; } const ActionsGutter: React.FC = ({ diffChunks, lineHeight, - width, }) => { + const [actualWidth, setActualWidth] = React.useState(0); + const containerRef = React.useRef(null); + + React.useEffect(() => { + const resizeObserver = new ResizeObserver((entries) => { + setActualWidth(entries[0].contentRect.width); + }); + + if (containerRef.current) { + resizeObserver.observe(containerRef.current); + } + + return () => resizeObserver.disconnect(); + }, []); + const drawChunk = (chunk: DiffChunk, index: number) => { const topLeft = (chunk.startLeftLine - 1) * lineHeight; const bottomLeft = (chunk.endLeftLine - 1) * lineHeight; @@ -30,9 +43,9 @@ const ActionsGutter: React.FC = ({ = ({ }; return ( -
+
= ({ setLineHeight(editor.defaultLineHeight); }; - // const [leftWidth, setLeftWidth] = useState("33%"); - const [gutterWidth, setGutterWidth] = useState(100); - // const [rightWidth, setRightWidth] = useState("33%"); + const [actualWidth, setActualWidth] = React.useState(0); + const containerRef = React.useRef(null); + + const [leftWidth, setLeftWidth] = useState("33%"); + const [gutterWidth, setGutterWidth] = useState("33%"); + const [rightWidth, setRightWidth] = useState("33%"); + + React.useEffect(() => { + const resizeObserver = new ResizeObserver((entries) => { + const actualWidth = entries[0].contentRect.width; + setActualWidth(actualWidth); + setLeftWidth(`${actualWidth / 3}px`); + setGutterWidth(`${actualWidth / 3}px`); + setRightWidth(`${actualWidth / 3}px`); + }); + + if (containerRef.current) { + resizeObserver.observe(containerRef.current); + } + + return () => resizeObserver.disconnect(); + }, []); const diffs = diff(oldText, newText); return (
-
- -
-
- -
-
- -
+ + +
); }; diff --git a/src/views/conflicts-resolution/editor-pane.tsx b/src/views/conflicts-resolution/editor-pane.tsx index ebea7d5..1bccb3b 100644 --- a/src/views/conflicts-resolution/editor-pane.tsx +++ b/src/views/conflicts-resolution/editor-pane.tsx @@ -14,45 +14,45 @@ interface EditorPaneProps { onContentChange: (content: string) => void; } -const EditorPane: React.FC = ({ - content, - highlightPluginSpec, - onEditorUpdate, - onContentChange, -}) => { - const extensions = [ - // basicSetup minus line numbers - // EditorView.lineWrapping, - EditorView.editable.of(true), - createDiffHighlightPlugin(highlightPluginSpec), - EditorView.theme({ - "&": { - backgroundColor: "var(--background-primary)", - color: "var(--text-normal)", - }, - ".cm-content": { - padding: 0, - caretColor: "var(--caret-color)", - fontSize: "var(--font-text-size)", - fontFamily: "var(--font-text)", - }, - "&.cm-focused .cm-selectionBackground, .cm-selectionBackground": { - background: "var(--text-selection)", - }, - "&.cm-focused": { - outline: 0, - }, - "&.cm-focused .cm-cursor": { - borderLeftColor: "var(--text-normal)", - }, - }), - markdown(), - ]; +const EditorPane: React.FC = (props) => { + const { content, highlightPluginSpec, onEditorUpdate, onContentChange } = + props; + const extensions = React.useMemo(() => { + return [ + // basicSetup minus line numbers + // EditorView.lineWrapping, + EditorView.editable.of(true), + createDiffHighlightPlugin(highlightPluginSpec), + EditorView.theme({ + "&": { + backgroundColor: "var(--background-primary)", + color: "var(--text-normal)", + }, + ".cm-content": { + padding: 0, + caretColor: "var(--caret-color)", + fontSize: "var(--font-text-size)", + fontFamily: "var(--font-text)", + }, + "&.cm-focused .cm-selectionBackground, .cm-selectionBackground": { + background: "var(--text-selection)", + }, + "&.cm-focused": { + outline: 0, + }, + "&.cm-focused .cm-cursor": { + borderLeftColor: "var(--text-normal)", + }, + }), + markdown(), + ]; + }, [highlightPluginSpec]); return ( {