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

Commit 8a5149b

Browse files
authored
Merge pull request #466 from unchartedsoftware/bugfix/453
Bugfix/453
2 parents d40ee77 + 453aaf8 commit 8a5149b

File tree

5 files changed

+20
-13
lines changed

5 files changed

+20
-13
lines changed

src/components/search-bar.jsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -467,10 +467,7 @@ export class SearchBar extends Component {
467467
editing: this.state.tokenValues,
468468
tokenValues: [...this.state.tokenValues.slice(0, idx), ...this.state.tokenValues.slice(idx + 1)]
469469
});
470-
this.state.activeMachine.bindValues(toEdit.value).then(() => {
471-
// hack to push the current value back into the archive when editing starts in the multivalue case
472-
if (this.state.activeMachine.state.isMultivalue) this.state.activeMachine.archive();
473-
});
470+
this.state.activeMachine.bindValues(toEdit.value, false, true);
474471
} else if (this.state.active) {
475472
this.setState({
476473
flashActive: false

src/lib/state.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -587,9 +587,10 @@ export class State extends EventEmitter {
587587
* Moves the current value to the archive, and resets the current value.
588588
*
589589
* @param {Object} context - The current boxed value of the containing `TokenStateMachine` (all `State`s up to and including this one).
590+
* @param {boolean} skipValidation - Whether or not to skip validation.
590591
*/
591-
archiveValue (context) { // eslint-disable-line no-unused-vars
592-
if (!this.isValid) {
592+
archiveValue (context, skipValidation = false) { // eslint-disable-line no-unused-vars
593+
if (!skipValidation && !this.isValid) {
593594
throw new ValueArchiveError(`Cannot archive invalid value for current state: ${JSON.stringify(this.value)}`);
594595
} else if (this.multivalueLimit && this.archive.length === this.multivalueLimit) {
595596
throw new ValueArchiveError(`Multivalue size limit reached for state ${this.name}`);

src/lib/states/generic/value-state.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,8 @@ export class ValueState extends State {
168168
}
169169
}
170170

171-
archiveValue (context) {
172-
super.archiveValue(context);
171+
archiveValue (context, skipValidation) {
172+
super.archiveValue(context, skipValidation);
173173
}
174174

175175
removeArchivedValue (idx, context) {

src/lib/token-state-machine.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,9 @@ export class TokenStateMachine extends EventEmitter {
5555
*
5656
* @param {Object | undefined} values - A optional array of (boxed) values to apply to the machine's states (applied from the root state onward). If any value is an array, all but the final value are added to the `State` archive.
5757
* @param {boolean} finalTransition - Whether or not to apply the final transition.
58+
* @param {boolean} editing - Whether or not the token we're binding to is being edited.
5859
*/
59-
async bindValues (values, finalTransition = false) {
60+
async bindValues (values, finalTransition = false, editing = false) {
6061
try {
6162
// bind to states
6263
if (values !== undefined) {
@@ -65,6 +66,7 @@ export class TokenStateMachine extends EventEmitter {
6566
delete copy.actionValues; // we don't need actionValues in copy.
6667
while (Object.keys(copy).length > 0) {
6768
const v = copy[this.state.vkey];
69+
this.state.reset();
6870
if (v === undefined) {
6971
await this.state.doInitialize(this.boxedValue);
7072
break; // we're missing a value for the current state, so break out.
@@ -76,9 +78,11 @@ export class TokenStateMachine extends EventEmitter {
7678
}
7779
for (const x of v) {
7880
this.state.value = x;
79-
this.state.archiveValue();
81+
this.state.archiveValue(this.boxedValue, true);
82+
}
83+
if (!editing) {
84+
this.state.unarchiveValue(); // make the last value the "active" one
8085
}
81-
this.state.unarchiveValue(); // make the last value the "active" one
8286
} else {
8387
await this.state.doInitialize(this.boxedValue, [this.state.unboxValue(v)]);
8488
this.state.value = v;
@@ -173,10 +177,12 @@ export class TokenStateMachine extends EventEmitter {
173177
/**
174178
* Rather than transitioning to the next state, supply a new value for this `State`
175179
* and save the current one in the `State`'s archive.
180+
*
181+
* @param {boolean} skipValidation - Whether or not to skip validation. `false` by default.
176182
*/
177-
archive () {
183+
archive (skipValidation = false) {
178184
try {
179-
this.state.archiveValue(this.boxedValue);
185+
this.state.archiveValue(this.boxedValue, skipValidation);
180186
this.emit('state changed', this.state, this.state);
181187
} catch (err) {
182188
this.emit('state change failed', err);

src/style/lex.scss

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ div.lex-box div.token, ul.entered-values li.entered-value {
8383

8484
&.active {
8585
padding: $lex-token-padding ($lex-token-padding + 16px) $lex-token-padding ($lex-token-padding + 2px);
86+
.token-input {
87+
cursor: text;
88+
}
8689
}
8790

8891
&.editing {

0 commit comments

Comments
 (0)