Add state to BufferSearch
This commit is contained in:
parent
3c1ec2e9ca
commit
6891e86621
3 changed files with 49 additions and 20 deletions
|
@ -1,20 +1,32 @@
|
|||
use crate::prelude::*;
|
||||
use crate::{h_stack, EditorPane, Icon, IconButton, Input};
|
||||
use gpui3::{view, Context, View};
|
||||
|
||||
#[derive(Element)]
|
||||
#[element(view_state = "EditorPane")]
|
||||
pub struct BufferSearch {}
|
||||
use crate::prelude::*;
|
||||
use crate::{h_stack, Icon, IconButton, IconColor, Input};
|
||||
|
||||
pub struct BufferSearch {
|
||||
is_replace_open: bool,
|
||||
}
|
||||
|
||||
impl BufferSearch {
|
||||
pub fn new() -> Self {
|
||||
Self {}
|
||||
Self {
|
||||
is_replace_open: false,
|
||||
}
|
||||
}
|
||||
|
||||
fn render(
|
||||
&mut self,
|
||||
_view: &mut EditorPane,
|
||||
cx: &mut ViewContext<EditorPane>,
|
||||
) -> impl Element<ViewState = EditorPane> {
|
||||
fn toggle_replace(&mut self, cx: &mut ViewContext<Self>) {
|
||||
self.is_replace_open = !self.is_replace_open;
|
||||
|
||||
cx.notify();
|
||||
}
|
||||
|
||||
pub fn view(cx: &mut WindowContext) -> View<Self> {
|
||||
let theme = theme(cx);
|
||||
|
||||
view(cx.entity(|cx| Self::new()), Self::render)
|
||||
}
|
||||
|
||||
fn render(&mut self, cx: &mut ViewContext<Self>) -> impl Element<ViewState = Self> {
|
||||
let theme = theme(cx);
|
||||
|
||||
h_stack()
|
||||
|
@ -23,7 +35,13 @@ impl BufferSearch {
|
|||
.child(
|
||||
h_stack()
|
||||
.child(Input::new("Search (↑/↓ for previous/next query)"))
|
||||
.child(IconButton::new(Icon::Replace)),
|
||||
.child(
|
||||
IconButton::<Self>::new(Icon::Replace)
|
||||
.when(self.is_replace_open, |this| this.color(IconColor::Accent))
|
||||
.on_click(|buffer_search, cx| {
|
||||
buffer_search.toggle_replace(cx);
|
||||
}),
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue