Skip to content

Commit

Permalink
fix selection bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Kr0nox committed Jan 15, 2025
1 parent da8d15e commit 9584ebf
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 14 deletions.
2 changes: 2 additions & 0 deletions src/features/constraintMenu/AutoCompletion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ export class AutoCompleteTree {
if (index >= this.content.length) {
if (nodes.length == 0 || comesFromFinal) {
return [];
} else {
return [{ message: "Unexpected end of line", startColumn: this.length, endColumn: this.length }];
}
}

Expand Down
25 changes: 15 additions & 10 deletions src/features/constraintMenu/ConstraintMenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ export class ConstraintMenu extends AbstractUIExtension implements Switchable {
this.constraintRegistry = constraintRegistry;
this.tree = new AutoCompleteTree(TreeBuilder.buildTree(modelSource, labelTypeRegistry));
this.forceReadOnly = editorModeController?.getCurrentMode() !== "edit";
editorModeController?.onModeChange((mode) => {
this.forceReadOnly = mode !== "edit";
editorModeController?.onModeChange((_) => {
this.forceReadOnly = editorModeController!.isReadOnly();
});
}

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

this.editor?.setValue(
this.constraintRegistry.getConstraints()[0]?.constraint ?? "Select or create a constraint to edit",
);

this.editor?.onDidChangeModelContent(() => {
if (this.selectedConstraint) {
this.selectedConstraint.constraint = this.editor?.getValue() ?? "";
Expand Down Expand Up @@ -189,20 +193,21 @@ export class ConstraintMenu extends AbstractUIExtension implements Switchable {

const deleteButton = document.createElement("button");
deleteButton.innerHTML = '<span class="codicon codicon-trash"></span>';
deleteButton.onclick = () => {
this.constraintRegistry.unregisterConstraint(constraint);
this.rerenderConstraintList();
if (this.selectedConstraint === constraint) {
deleteButton.onclick = (e) => {
e.stopPropagation();
if (this.selectedConstraint?.id === constraint.id) {
this.selectConstraintListItem(undefined);
}
this.constraintRegistry.unregisterConstraint(constraint);
this.rerenderConstraintList();
};
valueElement.appendChild(deleteButton);
return valueElement;
}

private selectConstraintListItem(constraint?: Constraint): void {
this.selectedConstraint = constraint;
this.editor?.setValue(constraint?.constraint ?? "");
this.editor?.setValue(constraint?.constraint ?? "Select or create a constraint to edit");
this.editor?.updateOptions({ readOnly: constraint === undefined || this.forceReadOnly });
}

Expand All @@ -220,9 +225,9 @@ export class ConstraintMenu extends AbstractUIExtension implements Switchable {
addButton.classList.add("constraint-add");
addButton.innerHTML = '<span class="codicon codicon-add"></span> Constraint';
addButton.onclick = () => {
/*if (this.editorModeController?.isReadOnly()) {
if (this.forceReadOnly) {
return;
}*/
}
if (!list) {
return;
}
Expand Down
4 changes: 0 additions & 4 deletions src/features/constraintMenu/constraintMenu.css
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,6 @@ div.constraint-menu {
grid-column-start: 2;
}

#constraint-menu-expand-label {
/*padding-right: 2em;*/
}

.constrain-label input {
background-color: var(--color-background);
text-align: center;
Expand Down

0 comments on commit 9584ebf

Please sign in to comment.