Et2VfsSelectButton passes in value (reference). Take care to keep that reference, or value can get lost.

Fixes Link to -> copy from VFS sometimes fails
This commit is contained in:
nathan 2024-11-18 13:45:56 -07:00
parent 0a4b08a170
commit f6874330fc
2 changed files with 12 additions and 9 deletions

View File

@ -262,7 +262,7 @@ export class Et2VfsSelectDialog
if(this.value.length && path != oldValue) if(this.value.length && path != oldValue)
{ {
const length = this.value.length; const length = this.value.length;
this.value = []; this.value.length = 0;
this.updateComplete.then(() => this.updateComplete.then(() =>
{ {
render(html` render(html`
@ -431,11 +431,14 @@ export class Et2VfsSelectDialog
{ {
case "select-dir": case "select-dir":
// If they didn't pick a specific directory and didn't cancel, use the current directory // If they didn't pick a specific directory and didn't cancel, use the current directory
this.value = this.value.length ? this.value : [this.path]; if(this.value.length == 0)
{
this.value.splice(0, 0, this.path)
}
break; break;
case "saveas": case "saveas":
// Saveas wants a full path, including filename // Saveas wants a full path, including filename
this.value = [this.path + "/" + this._filenameNode.value ?? this.filename]; this.value.splice(0, this.value.length, this.path + "/" + this._filenameNode.value ?? this.filename);
// Check for existing file, ask what to do // Check for existing file, ask what to do
if(this.fileInfo(this.value[0])) if(this.fileInfo(this.value[0]))
@ -445,7 +448,7 @@ export class Et2VfsSelectDialog
{ {
return; return;
} }
this.value = [this.path + "/" + result]; this.value.splice(0, this.value.length, this.path + "/" + result);
} }
break; break;
} }
@ -562,11 +565,11 @@ export class Et2VfsSelectDialog
// Update the value // Update the value
if(this.multiple) if(this.multiple)
{ {
this.value = this.selectedResults.map(el => el.value.path); this.value.splice(0, this.value.length, ...this.selectedResults.map(el => el.value.path));
} }
else else
{ {
this.value = (this.selectedResults?.length ? [this.selectedResults[0].value.path] : []) ?? []; this.value.splice(0, this.value.length, ...(this.selectedResults?.length ? [this.selectedResults[0].value.path] : []) ?? []);
} }
} }
@ -714,7 +717,7 @@ export class Et2VfsSelectDialog
super.handleSearchKeyDown(event); super.handleSearchKeyDown(event);
event.preventDefault(); event.preventDefault();
this.value = []; this.value.length = 0;
this.hide(); this.hide();
return; return;
} }

View File

@ -499,11 +499,11 @@ export const SearchMixin = <T extends Constructor<Et2InputWidgetInterface &
* eg: * eg:
if(this.multiple && typeof this.value !== "undefined") if(this.multiple && typeof this.value !== "undefined")
{ {
this.value = this.selectedResults.map(el => el.value); this.value.splice(0, this.value.length, ...this.selectedResults.map(el => el.value));
} }
else if (typeof this.value !== "undefined") else if (typeof this.value !== "undefined")
{ {
this.value = [this.selectedResults[0]?.value] ?? []; this.value.splice(0,this.value.length, ...(this.selectedResults[0]?.value ?? []));
} }
// Dispatch the change event // Dispatch the change event
this.updateComplete.then(() => this.updateComplete.then(() =>