Compare commits

..

No commits in common. "feature/prompt-impovements" and "main" have entirely different histories.

5 changed files with 6 additions and 66 deletions

View file

@ -20,7 +20,7 @@
</div> </div>
</dialog> </dialog>
<dialog id="command-dialog" data-controller="commands" <dialog id="command-dialog" data-controller="commands"
data-action="dq-showcommands@window->commands#showCommands dq-rerunlastcommand@window->commands#rerunLastCommand dq-rerunlastcommand-line@window->commands#rerunLastCommandOnLine"> data-action="dq-showcommands@window->commands#showCommands dq-rerunlastcommand@window->commands#rerunLastCommand">
<div class="dialog-body"> <div class="dialog-body">
<div class="command-input"> <div class="command-input">
<input data-commands-target="commandInput" type="text" placeholder="Enter command" <input data-commands-target="commandInput" type="text" placeholder="Enter command"

View file

@ -46,14 +46,6 @@ export const commandPalette = keymap.of([{
return true; return true;
} }
}, { }, {
key: "Cmd-l",
run: () => {
let event = new CustomEvent('dq-rerunlastcommand-line');
window.dispatchEvent(event);
return true;
}
}, {
key: "Cmd-k", key: "Cmd-k",
run: (view) => { run: (view) => {
const {state} = view; const {state} = view;

View file

@ -10,10 +10,6 @@ export class CommandsController extends Controller {
"commandSelect", "commandSelect",
]; ];
initialize() {
this._lineModeOnce = false;
}
async connect() { async connect() {
this._lastCommand = null; this._lastCommand = null;
@ -51,7 +47,6 @@ export class CommandsController extends Controller {
runCommand(ev) { runCommand(ev) {
ev.preventDefault(); ev.preventDefault();
this._promptController()?.clearUseLastValue();
textProcessor.runTextCommand(this.commandSelectTarget.value); textProcessor.runTextCommand(this.commandSelectTarget.value);
this._lastCommand = this.commandSelectTarget.value; this._lastCommand = this.commandSelectTarget.value;
@ -65,21 +60,7 @@ export class CommandsController extends Controller {
return; return;
} }
this._promptController()?.useLastValueForNextPrompt(); textProcessor.runTextCommand(this._lastCommand);
const lineMode = this._lineModeOnce;
this._lineModeOnce = false;
textProcessor.runTextCommand(this._lastCommand, { lineMode });
}
rerunLastCommandOnLine(ev) {
this._lineModeOnce = true;
this.rerunLastCommand(ev);
}
_promptController() {
const el = document.getElementById("prompt-dialog");
if (!el) return null;
return this.application.getControllerForElementAndIdentifier(el, "prompt");
} }
_filterOptions(filterText) { _filterOptions(filterText) {

View file

@ -8,16 +8,8 @@ export class PromptController extends Controller {
connect() { connect() {
this._callback = null; this._callback = null;
this._lastValue = null;
this._useLastNext = false;
window.runtime.EventsOn("prompt-request", (data) => { 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) => { this.prompt(data.label, (res) => {
window.runtime.EventsEmit("prompt-response", res); window.runtime.EventsEmit("prompt-response", res);
}); });
@ -27,16 +19,14 @@ export class PromptController extends Controller {
prompt(label, callback) { prompt(label, callback) {
this._callback = callback; this._callback = callback;
this.labelTarget.textContent = label; this.labelTarget.textContent = label;
this.inputTarget.value = this._lastValue || ""; this.inputTarget.value = "";
this.element.showModal(); this.element.showModal();
this.inputTarget.select();
this.inputTarget.focus(); this.inputTarget.focus();
} }
submit(ev) { submit(ev) {
ev.preventDefault(); ev.preventDefault();
let value = this.inputTarget.value; let value = this.inputTarget.value;
this._lastValue = value;
this.element.close(); this.element.close();
if (this._callback) { if (this._callback) {
this._callback(value); this._callback(value);
@ -49,12 +39,4 @@ export class PromptController extends Controller {
this._callback = null; this._callback = null;
this.element.close(); this.element.close();
} }
useLastValueForNextPrompt() {
this._useLastNext = true;
}
clearUseLastValue() {
this._useLastNext = false;
}
} }

View file

@ -46,31 +46,16 @@ class TextProcessor {
}); });
} }
async runTextCommand(command, opts) { async runTextCommand(command) {
if (this._editor === undefined) { if (this._editor === undefined) {
return; return;
} }
const lineMode = opts && opts.lineMode;
let ranges = this._editor.state.selection.ranges; let ranges = this._editor.state.selection.ranges;
let hasSelection = ranges.some(r => r.from !== r.to); let shouldBeAll = ranges.reduce((a, r) => a && r.from === r.to, true);
let inputs = []; let inputs = [];
if (lineMode && !hasSelection) { if (shouldBeAll) {
this._appendInsertPos = undefined;
const doc = this._editor.state.doc;
const seen = new Set();
for (let r of ranges) {
const line = doc.lineAt(r.head);
if (seen.has(line.number)) continue;
seen.add(line.number);
inputs.push({
text: line.text,
pos: line.from,
len: line.to - line.from,
});
}
} else if (!hasSelection) {
this._appendInsertPos = this._editor.state.selection.main.head; this._appendInsertPos = this._editor.state.selection.main.head;
inputs.push({ inputs.push({
text: this._editor.state.doc.toString(), text: this._editor.state.doc.toString(),