task: Make UseSelectedQuery modal action expand to full command (#9947)

Previously it expanded to a label, which was correct for oneshots, but
wrong for everything else.

Release Notes:

- Improved UseSelectedQuery (shift-enter) action for tasks modal by
making it substitute a full command and not the task label.
- Fixed one-shot tasks having duplicates in tasks modal.
This commit is contained in:
Piotr Osiewicz 2024-03-29 11:45:50 +01:00 committed by GitHub
parent c7f04691d9
commit 1360dffead
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 34 additions and 14 deletions

View file

@ -66,9 +66,14 @@ impl OneshotSource {
/// Spawns a certain task based on the user prompt.
pub fn spawn(&mut self, prompt: String) -> Arc<dyn Task> {
let ret = Arc::new(OneshotTask::new(prompt));
self.tasks.push(ret.clone());
ret
if let Some(task) = self.tasks.iter().find(|task| task.id().0 == prompt) {
// If we already have an oneshot task with that command, let's just reuse it.
task.clone()
} else {
let new_oneshot = Arc::new(OneshotTask::new(prompt));
self.tasks.push(new_oneshot.clone());
new_oneshot
}
}
}