未验证 提交 9eb56691 编写于 作者: A Alex Ross 提交者: GitHub

File picker undo should work (#70302)

Use execCommand to ensurse that file picker auto complete is added to undo buffer
上级 a774363d
......@@ -195,6 +195,8 @@ export interface IQuickPick<T extends IQuickPickItem> extends IQuickInput {
valueSelection: Readonly<[number, number]> | undefined;
validationMessage: string | undefined;
inputHasFocus(): boolean;
}
export interface IInputBox extends IQuickInput {
......
......@@ -463,6 +463,10 @@ class QuickPick<T extends IQuickPickItem> extends QuickInput implements IQuickPi
this.update();
}
public inputHasFocus(): boolean {
return this.visible ? this.ui.inputBox.hasFocus() : false;
}
onDidChangeSelection = this.onDidChangeSelectionEmitter.event;
onDidTriggerItemButton = this.onDidTriggerItemButtonEmitter.event;
......
......@@ -81,6 +81,10 @@ export class QuickInputBox {
this.inputBox.setEnabled(enabled);
}
hasFocus(): boolean {
return this.inputBox.hasFocus();
}
setAttribute(name: string, value: string) {
this.inputBox.inputElement.setAttribute(name, value);
}
......
......@@ -47,6 +47,7 @@ export class RemoteFileDialog {
private userValue: string;
private scheme: string = REMOTE_HOST_SCHEME;
private shouldOverwriteFile: boolean = false;
private autoComplete: string;
constructor(
@IFileService private readonly fileService: IFileService,
......@@ -222,18 +223,21 @@ export class RemoteFileDialog {
});
this.filePickBox.onDidChangeValue(async value => {
if (value !== this.userValue) {
this.filePickBox.validationMessage = undefined;
this.shouldOverwriteFile = false;
const trimmedPickBoxValue = ((this.filePickBox.value.length > 1) && this.endsWithSlash(this.filePickBox.value)) ? this.filePickBox.value.substr(0, this.filePickBox.value.length - 1) : this.filePickBox.value;
const valueUri = this.remoteUriFrom(trimmedPickBoxValue);
if (!resources.isEqual(this.currentFolder, valueUri, true)) {
await this.tryUpdateItems(value, this.remoteUriFrom(this.filePickBox.value));
// onDidChangeValue can also be triggered by the auto complete, so if it looks like the auto complete, don't do anything
if (!this.autoComplete || (value !== this.autoComplete)) {
if (value !== this.userValue) {
this.filePickBox.validationMessage = undefined;
this.shouldOverwriteFile = false;
const trimmedPickBoxValue = ((this.filePickBox.value.length > 1) && this.endsWithSlash(this.filePickBox.value)) ? this.filePickBox.value.substr(0, this.filePickBox.value.length - 1) : this.filePickBox.value;
const valueUri = this.remoteUriFrom(trimmedPickBoxValue);
if (!resources.isEqual(this.currentFolder, valueUri, true)) {
await this.tryUpdateItems(value, this.remoteUriFrom(this.filePickBox.value));
}
this.setActiveItems(value);
this.userValue = value;
} else {
this.filePickBox.activeItems = [];
}
this.setActiveItems(value);
this.userValue = value;
} else {
this.filePickBox.activeItems = [];
}
});
this.filePickBox.onDidHide(() => {
......@@ -356,8 +360,12 @@ export class RemoteFileDialog {
const itemBasename = (item.label === '..') ? item.label : resources.basename(item.uri);
if ((itemBasename.length >= inputBasename.length) && (itemBasename.substr(0, inputBasename.length).toLowerCase() === inputBasename.toLowerCase())) {
this.filePickBox.activeItems = [item];
this.filePickBox.value = this.filePickBox.value + itemBasename.substr(inputBasename.length);
this.filePickBox.valueSelection = [value.length, this.filePickBox.value.length];
const insertValue = itemBasename.substr(inputBasename.length);
this.autoComplete = value + insertValue;
if (this.filePickBox.inputHasFocus()) {
document.execCommand('insertText', false, insertValue);
this.filePickBox.valueSelection = [value.length, this.filePickBox.value.length];
}
hasMatch = true;
break;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册