Skip to content

Commit

Permalink
Merge pull request #466 from unchartedsoftware/bugfix/453
Browse files Browse the repository at this point in the history
Bugfix/453
  • Loading branch information
Ghnuberath authored Apr 26, 2019
2 parents d40ee77 + 453aaf8 commit 8a5149b
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 13 deletions.
5 changes: 1 addition & 4 deletions src/components/search-bar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -467,10 +467,7 @@ export class SearchBar extends Component {
editing: this.state.tokenValues,
tokenValues: [...this.state.tokenValues.slice(0, idx), ...this.state.tokenValues.slice(idx + 1)]
});
this.state.activeMachine.bindValues(toEdit.value).then(() => {
// hack to push the current value back into the archive when editing starts in the multivalue case
if (this.state.activeMachine.state.isMultivalue) this.state.activeMachine.archive();
});
this.state.activeMachine.bindValues(toEdit.value, false, true);
} else if (this.state.active) {
this.setState({
flashActive: false
Expand Down
5 changes: 3 additions & 2 deletions src/lib/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -587,9 +587,10 @@ export class State extends EventEmitter {
* Moves the current value to the archive, and resets the current value.
*
* @param {Object} context - The current boxed value of the containing `TokenStateMachine` (all `State`s up to and including this one).
* @param {boolean} skipValidation - Whether or not to skip validation.
*/
archiveValue (context) { // eslint-disable-line no-unused-vars
if (!this.isValid) {
archiveValue (context, skipValidation = false) { // eslint-disable-line no-unused-vars
if (!skipValidation && !this.isValid) {
throw new ValueArchiveError(`Cannot archive invalid value for current state: ${JSON.stringify(this.value)}`);
} else if (this.multivalueLimit && this.archive.length === this.multivalueLimit) {
throw new ValueArchiveError(`Multivalue size limit reached for state ${this.name}`);
Expand Down
4 changes: 2 additions & 2 deletions src/lib/states/generic/value-state.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,8 @@ export class ValueState extends State {
}
}

archiveValue (context) {
super.archiveValue(context);
archiveValue (context, skipValidation) {
super.archiveValue(context, skipValidation);
}

removeArchivedValue (idx, context) {
Expand Down
16 changes: 11 additions & 5 deletions src/lib/token-state-machine.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,9 @@ export class TokenStateMachine extends EventEmitter {
*
* @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.
* @param {boolean} finalTransition - Whether or not to apply the final transition.
* @param {boolean} editing - Whether or not the token we're binding to is being edited.
*/
async bindValues (values, finalTransition = false) {
async bindValues (values, finalTransition = false, editing = false) {
try {
// bind to states
if (values !== undefined) {
Expand All @@ -65,6 +66,7 @@ export class TokenStateMachine extends EventEmitter {
delete copy.actionValues; // we don't need actionValues in copy.
while (Object.keys(copy).length > 0) {
const v = copy[this.state.vkey];
this.state.reset();
if (v === undefined) {
await this.state.doInitialize(this.boxedValue);
break; // we're missing a value for the current state, so break out.
Expand All @@ -76,9 +78,11 @@ export class TokenStateMachine extends EventEmitter {
}
for (const x of v) {
this.state.value = x;
this.state.archiveValue();
this.state.archiveValue(this.boxedValue, true);
}
if (!editing) {
this.state.unarchiveValue(); // make the last value the "active" one
}
this.state.unarchiveValue(); // make the last value the "active" one
} else {
await this.state.doInitialize(this.boxedValue, [this.state.unboxValue(v)]);
this.state.value = v;
Expand Down Expand Up @@ -173,10 +177,12 @@ export class TokenStateMachine extends EventEmitter {
/**
* Rather than transitioning to the next state, supply a new value for this `State`
* and save the current one in the `State`'s archive.
*
* @param {boolean} skipValidation - Whether or not to skip validation. `false` by default.
*/
archive () {
archive (skipValidation = false) {
try {
this.state.archiveValue(this.boxedValue);
this.state.archiveValue(this.boxedValue, skipValidation);
this.emit('state changed', this.state, this.state);
} catch (err) {
this.emit('state change failed', err);
Expand Down
3 changes: 3 additions & 0 deletions src/style/lex.scss
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ div.lex-box div.token, ul.entered-values li.entered-value {

&.active {
padding: $lex-token-padding ($lex-token-padding + 16px) $lex-token-padding ($lex-token-padding + 2px);
.token-input {
cursor: text;
}
}

&.editing {
Expand Down

0 comments on commit 8a5149b

Please sign in to comment.