Reuse last prompt value when rerunning last command
Co-authored-by: Shelley <shelley@exe.dev>
This commit is contained in:
parent
9f14a895fa
commit
7c9023ae20
|
|
@ -47,6 +47,7 @@ export class CommandsController extends Controller {
|
|||
runCommand(ev) {
|
||||
ev.preventDefault();
|
||||
|
||||
this._promptController()?.clearUseLastValue();
|
||||
textProcessor.runTextCommand(this.commandSelectTarget.value);
|
||||
this._lastCommand = this.commandSelectTarget.value;
|
||||
|
||||
|
|
@ -60,9 +61,16 @@ export class CommandsController extends Controller {
|
|||
return;
|
||||
}
|
||||
|
||||
this._promptController()?.useLastValueForNextPrompt();
|
||||
textProcessor.runTextCommand(this._lastCommand);
|
||||
}
|
||||
|
||||
_promptController() {
|
||||
const el = document.getElementById("prompt-dialog");
|
||||
if (!el) return null;
|
||||
return this.application.getControllerForElementAndIdentifier(el, "prompt");
|
||||
}
|
||||
|
||||
_filterOptions(filterText) {
|
||||
let inputText = filterText.toLowerCase();
|
||||
let inputTerms = filterText.toLowerCase().split(/\s+/).map(s => s.trim()).filter(s => s !== "");
|
||||
|
|
|
|||
|
|
@ -8,8 +8,16 @@ export class PromptController extends Controller {
|
|||
|
||||
connect() {
|
||||
this._callback = null;
|
||||
this._lastValue = null;
|
||||
this._useLastNext = false;
|
||||
|
||||
window.runtime.EventsOn("prompt-request", (data) => {
|
||||
if (this._useLastNext && this._lastValue !== null) {
|
||||
this._useLastNext = false;
|
||||
window.runtime.EventsEmit("prompt-response", this._lastValue);
|
||||
return;
|
||||
}
|
||||
this._useLastNext = false;
|
||||
this.prompt(data.label, (res) => {
|
||||
window.runtime.EventsEmit("prompt-response", res);
|
||||
});
|
||||
|
|
@ -19,14 +27,16 @@ export class PromptController extends Controller {
|
|||
prompt(label, callback) {
|
||||
this._callback = callback;
|
||||
this.labelTarget.textContent = label;
|
||||
this.inputTarget.value = "";
|
||||
this.inputTarget.value = this._lastValue || "";
|
||||
this.element.showModal();
|
||||
this.inputTarget.select();
|
||||
this.inputTarget.focus();
|
||||
}
|
||||
|
||||
submit(ev) {
|
||||
ev.preventDefault();
|
||||
let value = this.inputTarget.value;
|
||||
this._lastValue = value;
|
||||
this.element.close();
|
||||
if (this._callback) {
|
||||
this._callback(value);
|
||||
|
|
@ -39,4 +49,12 @@ export class PromptController extends Controller {
|
|||
this._callback = null;
|
||||
this.element.close();
|
||||
}
|
||||
|
||||
useLastValueForNextPrompt() {
|
||||
this._useLastNext = true;
|
||||
}
|
||||
|
||||
clearUseLastValue() {
|
||||
this._useLastNext = false;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue