(core) Fixing bug in token field editor with moving choices.

Summary:
Sometimes when rearranging items in choice editor, user can
put the new item inside last entry element, which is not recognized as
a choice entry.

Test Plan: manual tests

Reviewers: georgegevoian

Reviewed By: georgegevoian

Differential Revision: https://phab.getgrist.com/D3519
This commit is contained in:
Jarosław Sadziński 2022-07-08 15:08:35 +02:00
parent 0bdc82a170
commit 8469b7ded0

View File

@ -525,8 +525,15 @@ export class TokenField<Token extends IToken = IToken> extends Disposable {
// Find the token before which we are inserting the dragged elements. If inserting at the // Find the token before which we are inserting the dragged elements. If inserting at the
// end (just before or over the input box), destToken will be undefined. // end (just before or over the input box), destToken will be undefined.
const index = allTargets.indexOf(ev.target as HTMLElement); let index = allTargets.indexOf(ev.target as HTMLElement);
if (index < 0) { return; } if (index < 0) {
// Sometimes we are at inner input element of the target (when dragging past the last element).
// In this case we need to test the parent.
if (ev.target instanceof HTMLInputElement && ev.target.parentElement) {
index = allTargets.indexOf(ev.target.parentElement);
}
if (index < 0) { return; }
}
const destToken: TokenWrap<Token>|undefined = this._tokens.get()[index]; const destToken: TokenWrap<Token>|undefined = this._tokens.get()[index];
const selection = this._selection.get(); const selection = this._selection.get();