Skip to content

Commit

Permalink
Refactor completion to better support command & user
Browse files Browse the repository at this point in the history
  • Loading branch information
tarkah committed Jul 6, 2023
1 parent b4c380a commit d2ca1c5
Show file tree
Hide file tree
Showing 4 changed files with 366 additions and 357 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ chrono = { version = "0.4", features = ['serde'] }
fern = "0.6.1"
iced = { version = "0.9", features = ["tokio", "lazy", "advanced", "image"] }
log = "0.4.16"
once_cell = "1.18"
palette = "=0.7.2"
thiserror = "1.0.30"
tokio = { version = "1.0", features = ["rt", "fs", "process"] }
Expand Down
38 changes: 15 additions & 23 deletions src/widget/input.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use data::{input, user::User, Buffer, Command};
use std::collections::VecDeque;

use data::user::User;
use data::{input, Buffer, Command};
use iced::advanced::widget::{self, Operation};
pub use iced::widget::text_input::{focus, move_cursor_to_end};
use iced::widget::{component, container, row, text, text_input, Component};
use std::collections::VecDeque;

use self::completion::Completion;
use super::{anchored_overlay, key_press, Element, Renderer};
Expand Down Expand Up @@ -118,14 +120,9 @@ where
}
}
Event::Tab => {
state.completion.tab();
if let Some(entry) = state.completion.select() {
if entry.is_user() {
state.input = entry.complete_input(&state.input);
Some(self.on_completion.clone())
} else {
None
}
if let Some(entry) = state.completion.tab() {
state.input = entry.complete_input(&state.input);
Some(self.on_completion.clone())
} else {
None
}
Expand Down Expand Up @@ -185,20 +182,15 @@ where
.on_submit(Event::Send)
.id(self.id.clone())
.padding(8)
.style(style)
.into();
.style(style);

// Add tab support if selecting a completion
let input = if state.completion.is_selecting() {
key_press(
text_input,
key_press::KeyCode::Tab,
key_press::Modifiers::default(),
Event::Tab,
)
} else {
text_input
};
// Add tab support
let input = key_press(
text_input,
key_press::KeyCode::Tab,
key_press::Modifiers::default(),
Event::Tab,
);

// Add up / down support for history cycling
let input = key_press(
Expand Down
Loading

0 comments on commit d2ca1c5

Please sign in to comment.