Skip to content

Commit

Permalink
Merge pull request #149 from squidowl/fix/input-history-multi-buffer
Browse files Browse the repository at this point in the history
Only allow input history if buffer is focused
  • Loading branch information
tarkah authored Jul 12, 2023
2 parents 883812b + 1a383fa commit a78540b
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 14 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Fixed:
- Changes done in the config file are now properly applied to the old buffers
- Text and colors on light themes will no longer appear washed out
- All WHOIS responses are now properly routed to the buffer where the request was made (text input or via context menu)
- Accessing text input history will only populate the current buffer, not all of them

# 2023.2 (2023-07-07)

Expand Down
2 changes: 1 addition & 1 deletion src/buffer/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ pub fn view<'a>(
let text_input = show_text_input.then(|| {
column![
vertical_space(4),
input_view::view(&state.input_view, buffer, users, input_history)
input_view::view(&state.input_view, buffer, users, input_history, is_focused)
.map(Message::InputView)
]
});
Expand Down
2 changes: 2 additions & 0 deletions src/buffer/input_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@ pub fn view<'a>(
buffer: Buffer,
users: &'a [User],
history: &'a [String],
buffer_focused: bool,
) -> Element<'a, Message> {
input(
state.input_id.clone(),
buffer,
&state.input,
users,
history,
buffer_focused,
Message::Input,
Message::Send,
Message::Completion,
Expand Down
3 changes: 2 additions & 1 deletion src/buffer/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ pub fn view<'a>(
let text_input = show_text_input.then(|| {
column![
vertical_space(4),
input_view::view(&state.input_view, buffer, &[], input_history).map(Message::InputView)
input_view::view(&state.input_view, buffer, &[], input_history, is_focused)
.map(Message::InputView)
]
});

Expand Down
3 changes: 2 additions & 1 deletion src/buffer/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ pub fn view<'a>(
let text_input = show_text_input.then(|| {
column![
vertical_space(4),
input_view::view(&state.input_view, buffer, &[], input_history).map(Message::InputView)
input_view::view(&state.input_view, buffer, &[], input_history, is_focused)
.map(Message::InputView)
]
});

Expand Down
27 changes: 16 additions & 11 deletions src/widget/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ pub fn input<'a, Message>(
input: &'a str,
users: &'a [User],
history: &'a [String],
buffer_focused: bool,
on_input: impl Fn(String) -> Message + 'a,
on_submit: impl Fn(data::Input) -> Message + 'a,
on_completion: impl Fn(String) -> Message + 'a,
Expand All @@ -31,6 +32,7 @@ where
input,
users,
history,
buffer_focused,
on_input: Box::new(on_input),
on_submit: Box::new(on_submit),
on_completion: Box::new(on_completion),
Expand Down Expand Up @@ -59,6 +61,7 @@ pub struct Input<'a, Message> {
input: &'a str,
users: &'a [User],
history: &'a [String],
buffer_focused: bool,
on_input: Box<dyn Fn(String) -> Message + 'a>,
on_submit: Box<dyn Fn(data::Input) -> Message + 'a>,
on_completion: Box<dyn Fn(String) -> Message + 'a>,
Expand Down Expand Up @@ -183,25 +186,27 @@ where
.style(style);

// Add tab support
let input = key_press(
let mut 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(
key_press(
input,
key_press::KeyCode::Up,
if self.buffer_focused {
input = key_press(
key_press(
input,
key_press::KeyCode::Up,
key_press::Modifiers::default(),
Event::Up,
),
key_press::KeyCode::Down,
key_press::Modifiers::default(),
Event::Up,
),
key_press::KeyCode::Down,
key_press::Modifiers::default(),
Event::Down,
);
Event::Down,
);
}

let overlay = state
.error
Expand Down

0 comments on commit a78540b

Please sign in to comment.