Skip to content

Commit 5e3dfb1

Browse files
authored
[UI] Fix custom opt string after draggable windows update (#50)
DraggableWindow currently attached onMouseDown to the root container and conditionally checked for a .drag-title handle. This means any click inside the window, including on text inputs, bubbles through the handler and can interfere with typing or focus, especially after the resize update.
1 parent 6f05879 commit 5e3dfb1

File tree

2 files changed

+31
-14
lines changed

2 files changed

+31
-14
lines changed

src/app/DraggableWindow.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"use client";
22

3-
import React, { useRef } from "react";
3+
import React, { useRef, useEffect } from "react";
44

55
/**
66
* Lightweight draggable/resizable wrapper used when the react-rnd package
@@ -25,7 +25,10 @@ export function DraggableWindow({
2525

2626
const startDrag = (e) => {
2727
const handle = e.target.closest(".drag-title");
28-
if (!handle) return;
28+
if (!handle) {
29+
e.stopPropagation();
30+
return;
31+
}
2932
onFocus && onFocus();
3033
const startX = e.clientX;
3134
const startY = e.clientY;
@@ -55,6 +58,13 @@ export function DraggableWindow({
5558
document.addEventListener("mouseup", onUp);
5659
};
5760

61+
useEffect(() => {
62+
const title = ref.current?.querySelector(".drag-title");
63+
if (!title) return;
64+
title.addEventListener("mousedown", startDrag);
65+
return () => title.removeEventListener("mousedown", startDrag);
66+
}, [startDrag, children]);
67+
5868
const startResize = (e, dir) => {
5969
e.stopPropagation();
6070
onFocus && onFocus();
@@ -139,7 +149,6 @@ export function DraggableWindow({
139149
return (
140150
<div
141151
ref={ref}
142-
onMouseDown={startDrag}
143152
style={{
144153
position: "absolute",
145154
left: pos.x,

src/app/ExplorerContent.js

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,12 @@ export default function ExplorerContent() {
534534
}
535535

536536
function IRWindowBody({ irWin }) {
537+
const [localCmd, setLocalCmd] = useState(customToolCmd[irWin.id] || "");
538+
539+
useEffect(() => {
540+
setLocalCmd(customToolCmd[irWin.id] || "");
541+
}, [customToolCmd, irWin.id]);
542+
537543
return (
538544
<>
539545
<div
@@ -738,25 +744,27 @@ export default function ExplorerContent() {
738744
/>
739745
<Input
740746
placeholder="Call any tool in PATH + flags, e.g. `mlir-opt -convert-scf-to-cf` or `opt -O2 -S` and press `Enter`"
741-
value={customToolCmd[irWin.id] || ""}
742-
onChange={(e) =>
743-
updateActiveSource((s) => ({
744-
...s,
745-
customToolCmd: {
746-
...s.customToolCmd,
747-
[irWin.id]: e.target.value,
748-
},
749-
}))
750-
}
747+
value={localCmd}
748+
onChange={(e) => setLocalCmd(e.target.value)}
751749
onPressEnter={() => {
752-
const flags = (customToolCmd[irWin.id] || "").trim();
750+
const flags = localCmd.trim();
753751
if (!flags) return;
754752
handleAddCustomTool(irWin.id, flags);
753+
setLocalCmd("");
755754
updateActiveSource((s) => ({
756755
...s,
757756
customToolCmd: { ...s.customToolCmd, [irWin.id]: "" },
758757
}));
759758
}}
759+
onBlur={() =>
760+
updateActiveSource((s) => ({
761+
...s,
762+
customToolCmd: {
763+
...s.customToolCmd,
764+
[irWin.id]: localCmd,
765+
},
766+
}))
767+
}
760768
style={{
761769
width: "100%",
762770
marginBottom: "10px",

0 commit comments

Comments
 (0)