-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:shirou/vscode-dired
- Loading branch information
Showing
7 changed files
with
216 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
{ | ||
"version": "0.1.0", | ||
"configurations": [ | ||
|
||
{ | ||
"name": "Launch Extension", | ||
"type": "extensionHost", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import * as vscode from 'vscode'; | ||
|
||
export function defaultFinishCondition(self: vscode.QuickPick<vscode.QuickPickItem>) { | ||
if (self.selectedItems.length == 0 || self.selectedItems[0].label == self.value) { | ||
return true; | ||
} | ||
else { | ||
self.value = self.selectedItems[0].label; | ||
return false; | ||
} | ||
} | ||
|
||
export async function autocompletedInputBox<T>( | ||
arg: { | ||
completion: (userinput: string) => Iterable<vscode.QuickPickItem>, | ||
withSelf?: undefined | ((self: vscode.QuickPick<vscode.QuickPickItem>) => any), | ||
stopWhen?: undefined | ((self: vscode.QuickPick<vscode.QuickPickItem>) => boolean) | ||
}) { | ||
const completionFunc = arg.completion; | ||
const processSelf = arg.withSelf; | ||
|
||
let finishCondition = defaultFinishCondition; | ||
if (arg.stopWhen != undefined) | ||
finishCondition = defaultFinishCondition | ||
|
||
|
||
const quickPick = vscode.window.createQuickPick(); | ||
quickPick.canSelectMany = false; | ||
let disposables: vscode.Disposable[] = []; | ||
let result = quickPick.value; | ||
if (processSelf !== undefined) | ||
processSelf(quickPick); | ||
|
||
let makeTask = () => new Promise<void>(resolve => { | ||
disposables.push( | ||
quickPick.onDidChangeValue(directoryOrFile => { | ||
quickPick.items = Array.from(completionFunc(quickPick.value)) | ||
return 0; | ||
}), | ||
quickPick.onDidAccept(() => { | ||
if (finishCondition(quickPick)) { | ||
result = quickPick.value; | ||
quickPick.hide(); | ||
resolve(); | ||
} | ||
}), | ||
quickPick.onDidHide(() => { | ||
quickPick.dispose(); | ||
resolve(); | ||
}) | ||
); | ||
quickPick.show(); | ||
}); | ||
try { | ||
await makeTask(); | ||
} | ||
finally { | ||
disposables.forEach(d => d.dispose()); | ||
} | ||
return quickPick.value; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.