Skip to content

Commit

Permalink
Refresh reference and select boxes through mobx autorun and isDirty.
Browse files Browse the repository at this point in the history
  • Loading branch information
joswarmer committed Sep 30, 2024
1 parent 652450a commit f842521
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,11 @@
if (!!selectedOption) {
box.textHelper.setText(selectedOption.label);
setText(box.textHelper.getText());
} else {
box.textHelper.setText("");
setText(box.textHelper.getText());
}
selectedId = undefined
}
// because the box maybe a different one than we started with ...
// box.setFocus = setFocus; todo remove?
Expand Down
16 changes: 15 additions & 1 deletion packages/core/src/editor/boxes/AbstractChoiceBox.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { autorun } from "mobx"
import { FreNode } from "../../ast/index.js";
import { FreUtils } from "../../util/index.js";
import { BehaviorExecutionResult, FreCaret, FreKey } from "../util/index.js";
Expand Down Expand Up @@ -51,10 +52,23 @@ export abstract class AbstractChoiceBox extends Box {
set getSelectedOption( value: () => SelectOption | null) {
this._getSelectedOption = value
this.isDirty()
autorun( () => {
this._getSelectedOption()
this.isDirty()
})
}
get getSelectedOption(): () => SelectOption | null {
return this._getSelectedOption
}

// protected setSelectedOptionExec(value: () => SelectOption | null): SelectOption | null {
// this._getSelectedOption = value
// this.isDirty()
// autorun( () => {
// this._getSelectedOption()
// this.isDirty()
// })
// }

// @ts-ignore
// parameter is present to support subclasses
Expand All @@ -68,7 +82,7 @@ export abstract class AbstractChoiceBox extends Box {
console.error("AbstractChoiceBox.selectOption");
return BehaviorExecutionResult.NULL;
}

setCaret: (caret: FreCaret) => void = (caret: FreCaret) => {
if (!!this.textBox) {
this.textBox.setCaret(caret);
Expand Down

0 comments on commit f842521

Please sign in to comment.