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

Commit 9584ebf

Browse files
committed
fix selection bug
1 parent da8d15e commit 9584ebf

File tree

3 files changed

+17
-14
lines changed

3 files changed

+17
-14
lines changed

src/features/constraintMenu/AutoCompletion.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,8 @@ export class AutoCompleteTree {
129129
if (index >= this.content.length) {
130130
if (nodes.length == 0 || comesFromFinal) {
131131
return [];
132+
} else {
133+
return [{ message: "Unexpected end of line", startColumn: this.length, endColumn: this.length }];
132134
}
133135
}
134136

src/features/constraintMenu/ConstraintMenu.ts

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ export class ConstraintMenu extends AbstractUIExtension implements Switchable {
4242
this.constraintRegistry = constraintRegistry;
4343
this.tree = new AutoCompleteTree(TreeBuilder.buildTree(modelSource, labelTypeRegistry));
4444
this.forceReadOnly = editorModeController?.getCurrentMode() !== "edit";
45-
editorModeController?.onModeChange((mode) => {
46-
this.forceReadOnly = mode !== "edit";
45+
editorModeController?.onModeChange((_) => {
46+
this.forceReadOnly = editorModeController!.isReadOnly();
4747
});
4848
}
4949

@@ -58,7 +58,7 @@ export class ConstraintMenu extends AbstractUIExtension implements Switchable {
5858
containerElement.innerHTML = `
5959
<input type="checkbox" id="expand-state-constraint" class="accordion-state" hidden>
6060
<label id="constraint-menu-expand-label" for="expand-state-constraint">
61-
<div class="accordion-button cevron-left" id="constraint-menu-expand-title">
61+
<div class="accordion-button cevron-left flip-arrow" id="constraint-menu-expand-title">
6262
Constraints
6363
</div>
6464
</label>
@@ -110,6 +110,10 @@ export class ConstraintMenu extends AbstractUIExtension implements Switchable {
110110
readOnly: this.constraintRegistry.getConstraints().length === 0 || this.forceReadOnly,
111111
});
112112

113+
this.editor?.setValue(
114+
this.constraintRegistry.getConstraints()[0]?.constraint ?? "Select or create a constraint to edit",
115+
);
116+
113117
this.editor?.onDidChangeModelContent(() => {
114118
if (this.selectedConstraint) {
115119
this.selectedConstraint.constraint = this.editor?.getValue() ?? "";
@@ -189,20 +193,21 @@ export class ConstraintMenu extends AbstractUIExtension implements Switchable {
189193

190194
const deleteButton = document.createElement("button");
191195
deleteButton.innerHTML = '<span class="codicon codicon-trash"></span>';
192-
deleteButton.onclick = () => {
193-
this.constraintRegistry.unregisterConstraint(constraint);
194-
this.rerenderConstraintList();
195-
if (this.selectedConstraint === constraint) {
196+
deleteButton.onclick = (e) => {
197+
e.stopPropagation();
198+
if (this.selectedConstraint?.id === constraint.id) {
196199
this.selectConstraintListItem(undefined);
197200
}
201+
this.constraintRegistry.unregisterConstraint(constraint);
202+
this.rerenderConstraintList();
198203
};
199204
valueElement.appendChild(deleteButton);
200205
return valueElement;
201206
}
202207

203208
private selectConstraintListItem(constraint?: Constraint): void {
204209
this.selectedConstraint = constraint;
205-
this.editor?.setValue(constraint?.constraint ?? "");
210+
this.editor?.setValue(constraint?.constraint ?? "Select or create a constraint to edit");
206211
this.editor?.updateOptions({ readOnly: constraint === undefined || this.forceReadOnly });
207212
}
208213

@@ -220,9 +225,9 @@ export class ConstraintMenu extends AbstractUIExtension implements Switchable {
220225
addButton.classList.add("constraint-add");
221226
addButton.innerHTML = '<span class="codicon codicon-add"></span> Constraint';
222227
addButton.onclick = () => {
223-
/*if (this.editorModeController?.isReadOnly()) {
228+
if (this.forceReadOnly) {
224229
return;
225-
}*/
230+
}
226231
if (!list) {
227232
return;
228233
}

src/features/constraintMenu/constraintMenu.css

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,6 @@ div.constraint-menu {
6060
grid-column-start: 2;
6161
}
6262

63-
#constraint-menu-expand-label {
64-
/*padding-right: 2em;*/
65-
}
66-
6763
.constrain-label input {
6864
background-color: var(--color-background);
6965
text-align: center;

0 commit comments

Comments
 (0)