Skip to content

Commit

Permalink
Debounce query text box
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasPickering committed Dec 2, 2024
1 parent 2c2be56 commit decd2d1
Show file tree
Hide file tree
Showing 8 changed files with 253 additions and 75 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),

## [Unreleased] - ReleaseDate

### Changed

- Improve UX of query text box
- The query is now auto-applied when changed (with a 500ms debounce), and drops focus on the text box when Enter is pressed

## [2.3.0] - 2024-11-11

### Added
Expand Down
6 changes: 4 additions & 2 deletions crates/tui/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,14 +262,14 @@ impl Tui {
)?;
}

Message::EditFile { path, on_complete } => {
Message::FileEdit { path, on_complete } => {
let command = get_editor_command(&path)?;
self.run_command(command)?;
on_complete(path);
// The callback may queue an event to read the file, so we can't
// delete it yet. Caller is responsible for cleaning up
}
Message::ViewFile { path } => {
Message::FileView { path } => {
let command = get_viewer_command(&path)?;
self.run_command(command)?;
// We don't need to read the contents back so we can clean up
Expand Down Expand Up @@ -316,6 +316,8 @@ impl Tui {
self.view.handle_input(event, action);
}

Message::Local(event) => self.view.local(event),

Message::Notify(message) => self.view.notify(message),
Message::PromptStart(prompt) => {
self.view.open_modal(prompt);
Expand Down
17 changes: 10 additions & 7 deletions crates/tui/src/message.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Async message passing! This is how inputs and other external events trigger
//! state updates.
use crate::view::Confirm;
use crate::view::{Confirm, LocalEvent};
use anyhow::Context;
use derive_more::From;
use slumber_config::Action;
Expand All @@ -14,7 +14,7 @@ use slumber_core::{
template::{Prompt, Prompter, Select, Template, TemplateChunk},
util::ResultTraced,
};
use std::{path::PathBuf, sync::Arc};
use std::{fmt::Debug, path::PathBuf, sync::Arc};
use tokio::sync::mpsc::UnboundedSender;
use tracing::trace;

Expand Down Expand Up @@ -78,19 +78,19 @@ pub enum Message {
/// Copy some text to the clipboard
CopyText(String),

/// An error occurred in some async process and should be shown to the user
Error { error: anyhow::Error },

/// Open a file in the user's external editor
EditFile {
FileEdit {
path: PathBuf,
/// Function to call once the edit is done. The original path will be
/// passed back
#[debug(skip)]
on_complete: Callback<PathBuf>,
},
/// Open a file to be viewed in the user's external viewer
ViewFile { path: PathBuf },

/// An error occurred in some async process and should be shown to the user
Error { error: anyhow::Error },
FileView { path: PathBuf },

/// Launch an HTTP request from the given recipe/profile.
HttpBeginRequest(RequestConfig),
Expand All @@ -113,6 +113,9 @@ pub enum Message {
action: Option<Action>,
},

/// Trigger a localized UI event
Local(Box<dyn 'static + LocalEvent + Send + Sync>),

/// Send an informational notification to the user
Notify(String),

Expand Down
6 changes: 6 additions & 0 deletions crates/tui/src/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ mod util;

pub use common::modal::{IntoModal, ModalPriority};
pub use context::{UpdateContext, ViewContext};
pub use event::LocalEvent;
pub use styles::Styles;
pub use util::{Confirm, PreviewPrompter};

Expand Down Expand Up @@ -141,6 +142,11 @@ impl View {
ViewContext::push_event(Event::Notify(notification));
}

/// Trigger a localized UI event
pub fn local(&mut self, event: Box<dyn LocalEvent>) {
ViewContext::push_event(Event::Local(event));
}

/// Queue an event to update the view according to an input event from the
/// user. If possible, a bound action is provided which tells us what
/// abstract action the input maps to.
Expand Down
Loading

0 comments on commit decd2d1

Please sign in to comment.