Skip to content
This repository was archived by the owner on Oct 21, 2025. It is now read-only.

Commit ed33261

Browse files
committed
handle add on click
1 parent ac996e1 commit ed33261

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

src/features/labels/labelTypeEditor.ts

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
TYPES,
1212
} from "sprotty";
1313
import { LabelAssignment, LabelType, LabelTypeRegistry, LabelTypeValue } from "./labelTypeRegistry";
14-
import { DeleteLabelTypeAction, DeleteLabelTypeValueAction } from "./commands";
14+
import { AddLabelAssignmentAction, DeleteLabelTypeAction, DeleteLabelTypeValueAction } from "./commands";
1515
import { LABEL_ASSIGNMENT_MIME_TYPE } from "./dropListener";
1616
import { Action } from "sprotty-protocol";
1717
import { snapPortsOfNode } from "../dfdElements/portSnapper";
@@ -261,6 +261,36 @@ export class LabelTypeEditorUI extends AbstractUIExtension implements KeyListene
261261
event.dataTransfer?.setData(LABEL_ASSIGNMENT_MIME_TYPE, assignmentJson);
262262
};
263263

264+
valueInput.onclick = () => {
265+
if (valueInput.getAttribute("clicked") === "true") {
266+
return;
267+
}
268+
269+
valueInput.setAttribute("clicked", "true");
270+
setTimeout(() => {
271+
if (valueInput.getAttribute("clicked") === "true") {
272+
this.actionDispatcher.dispatch(
273+
AddLabelAssignmentAction.create({
274+
labelTypeId: labelType.id,
275+
labelTypeValueId: labelTypeValue.id,
276+
}),
277+
);
278+
valueInput.removeAttribute("clicked");
279+
}
280+
}, 500);
281+
};
282+
valueInput.ondblclick = () => {
283+
valueInput.removeAttribute("clicked");
284+
valueInput.focus();
285+
};
286+
valueInput.onfocus = (event) => {
287+
// we check for the single click here, since this gets triggered before the ondblclick event
288+
if (valueInput.getAttribute("clicked") !== "true") {
289+
event.preventDefault();
290+
valueInput.blur();
291+
}
292+
};
293+
264294
valueElement.appendChild(valueInput);
265295

266296
const deleteButton = document.createElement("button");

0 commit comments

Comments
 (0)