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);
|
||||
}),
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,11 +14,13 @@ pub struct EditorPane {
|
|||
path: PathBuf,
|
||||
symbols: Vec<Symbol>,
|
||||
buffer: Buffer<Self>,
|
||||
buffer_search: View<BufferSearch>,
|
||||
is_buffer_search_open: bool,
|
||||
}
|
||||
|
||||
impl EditorPane {
|
||||
pub fn new(
|
||||
cx: &mut WindowContext,
|
||||
tabs: Vec<Tab<Self>>,
|
||||
path: PathBuf,
|
||||
symbols: Vec<Symbol>,
|
||||
|
@ -29,6 +31,7 @@ impl EditorPane {
|
|||
path,
|
||||
symbols,
|
||||
buffer,
|
||||
buffer_search: BufferSearch::view(cx),
|
||||
is_buffer_search_open: false,
|
||||
}
|
||||
}
|
||||
|
@ -43,7 +46,7 @@ impl EditorPane {
|
|||
let theme = theme(cx);
|
||||
|
||||
view(
|
||||
cx.entity(|cx| hello_world_rust_editor_with_status_example(&theme)),
|
||||
cx.entity(|cx| hello_world_rust_editor_with_status_example(cx)),
|
||||
Self::render,
|
||||
)
|
||||
}
|
||||
|
@ -69,7 +72,7 @@ impl EditorPane {
|
|||
IconButton::new(Icon::MagicWand),
|
||||
]),
|
||||
)
|
||||
.children(Some(BufferSearch::new()).filter(|_| self.is_buffer_search_open))
|
||||
.children(Some(self.buffer_search.clone()).filter(|_| self.is_buffer_search_open))
|
||||
.child(self.buffer.clone())
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue