Clear highlighted matches when dismissing FindBar
This commit is contained in:
parent
b1639e5677
commit
611538f6bd
2 changed files with 56 additions and 27 deletions
|
@ -20,7 +20,7 @@ use std::{
|
||||||
use workspace::{ItemViewHandle, Pane, Settings, Toolbar, Workspace};
|
use workspace::{ItemViewHandle, Pane, Settings, Toolbar, Workspace};
|
||||||
|
|
||||||
action!(Deploy, bool);
|
action!(Deploy, bool);
|
||||||
action!(Cancel);
|
action!(Dismiss);
|
||||||
action!(FocusEditor);
|
action!(FocusEditor);
|
||||||
action!(ToggleMode, SearchMode);
|
action!(ToggleMode, SearchMode);
|
||||||
action!(GoToMatch, Direction);
|
action!(GoToMatch, Direction);
|
||||||
|
@ -42,7 +42,7 @@ pub fn init(cx: &mut MutableAppContext) {
|
||||||
cx.add_bindings([
|
cx.add_bindings([
|
||||||
Binding::new("cmd-f", Deploy(true), Some("Editor && mode == full")),
|
Binding::new("cmd-f", Deploy(true), Some("Editor && mode == full")),
|
||||||
Binding::new("cmd-e", Deploy(false), Some("Editor && mode == full")),
|
Binding::new("cmd-e", Deploy(false), Some("Editor && mode == full")),
|
||||||
Binding::new("escape", Cancel, Some("FindBar")),
|
Binding::new("escape", Dismiss, Some("FindBar")),
|
||||||
Binding::new("cmd-f", FocusEditor, Some("FindBar")),
|
Binding::new("cmd-f", FocusEditor, Some("FindBar")),
|
||||||
Binding::new("enter", GoToMatch(Direction::Next), Some("FindBar")),
|
Binding::new("enter", GoToMatch(Direction::Next), Some("FindBar")),
|
||||||
Binding::new("shift-enter", GoToMatch(Direction::Prev), Some("FindBar")),
|
Binding::new("shift-enter", GoToMatch(Direction::Prev), Some("FindBar")),
|
||||||
|
@ -50,7 +50,7 @@ pub fn init(cx: &mut MutableAppContext) {
|
||||||
Binding::new("cmd-shift-G", GoToMatch(Direction::Prev), Some("Pane")),
|
Binding::new("cmd-shift-G", GoToMatch(Direction::Prev), Some("Pane")),
|
||||||
]);
|
]);
|
||||||
cx.add_action(FindBar::deploy);
|
cx.add_action(FindBar::deploy);
|
||||||
cx.add_action(FindBar::cancel);
|
cx.add_action(FindBar::dismiss);
|
||||||
cx.add_action(FindBar::focus_editor);
|
cx.add_action(FindBar::focus_editor);
|
||||||
cx.add_action(FindBar::toggle_mode);
|
cx.add_action(FindBar::toggle_mode);
|
||||||
cx.add_action(FindBar::go_to_match);
|
cx.add_action(FindBar::go_to_match);
|
||||||
|
@ -157,6 +157,14 @@ impl Toolbar for FindBar {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn on_dismiss(&mut self, cx: &mut ViewContext<Self>) {
|
||||||
|
self.active_editor.take();
|
||||||
|
self.active_editor_subscription.take();
|
||||||
|
self.active_match_index.take();
|
||||||
|
self.pending_search.take();
|
||||||
|
self.clear_matches(cx);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FindBar {
|
impl FindBar {
|
||||||
|
@ -312,10 +320,10 @@ impl FindBar {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
fn cancel(workspace: &mut Workspace, _: &Cancel, cx: &mut ViewContext<Workspace>) {
|
fn dismiss(workspace: &mut Workspace, _: &Dismiss, cx: &mut ViewContext<Workspace>) {
|
||||||
workspace
|
workspace
|
||||||
.active_pane()
|
.active_pane()
|
||||||
.update(cx, |pane, cx| pane.hide_toolbar(cx));
|
.update(cx, |pane, cx| pane.dismiss_toolbar(cx));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn focus_editor(&mut self, _: &FocusEditor, cx: &mut ViewContext<Self>) {
|
fn focus_editor(&mut self, _: &FocusEditor, cx: &mut ViewContext<Self>) {
|
||||||
|
@ -403,16 +411,8 @@ impl FindBar {
|
||||||
) {
|
) {
|
||||||
match event {
|
match event {
|
||||||
editor::Event::Edited => {
|
editor::Event::Edited => {
|
||||||
for editor in self.highlighted_editors.drain() {
|
|
||||||
if let Some(editor) = editor.upgrade(cx) {
|
|
||||||
if Some(&editor) != self.active_editor.as_ref() {
|
|
||||||
editor.update(cx, |editor, cx| {
|
|
||||||
editor.clear_highlighted_ranges::<Self>(cx)
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
self.query_contains_error = false;
|
self.query_contains_error = false;
|
||||||
|
self.clear_matches(cx);
|
||||||
self.update_matches(cx);
|
self.update_matches(cx);
|
||||||
cx.notify();
|
cx.notify();
|
||||||
}
|
}
|
||||||
|
@ -433,6 +433,16 @@ impl FindBar {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn clear_matches(&mut self, cx: &mut ViewContext<Self>) {
|
||||||
|
for editor in self.highlighted_editors.drain() {
|
||||||
|
if let Some(editor) = editor.upgrade(cx) {
|
||||||
|
if Some(&editor) != self.active_editor.as_ref() {
|
||||||
|
editor.update(cx, |editor, cx| editor.clear_highlighted_ranges::<Self>(cx));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn update_matches(&mut self, cx: &mut ViewContext<Self>) {
|
fn update_matches(&mut self, cx: &mut ViewContext<Self>) {
|
||||||
let query = self.query_editor.read(cx).text(cx);
|
let query = self.query_editor.read(cx).text(cx);
|
||||||
self.pending_search.take();
|
self.pending_search.take();
|
||||||
|
|
|
@ -92,6 +92,7 @@ pub trait Toolbar: View {
|
||||||
item: Option<Box<dyn ItemViewHandle>>,
|
item: Option<Box<dyn ItemViewHandle>>,
|
||||||
cx: &mut ViewContext<Self>,
|
cx: &mut ViewContext<Self>,
|
||||||
) -> bool;
|
) -> bool;
|
||||||
|
fn on_dismiss(&mut self, cx: &mut ViewContext<Self>);
|
||||||
}
|
}
|
||||||
|
|
||||||
trait ToolbarHandle {
|
trait ToolbarHandle {
|
||||||
|
@ -100,6 +101,7 @@ trait ToolbarHandle {
|
||||||
item: Option<Box<dyn ItemViewHandle>>,
|
item: Option<Box<dyn ItemViewHandle>>,
|
||||||
cx: &mut MutableAppContext,
|
cx: &mut MutableAppContext,
|
||||||
) -> bool;
|
) -> bool;
|
||||||
|
fn on_dismiss(&self, cx: &mut MutableAppContext);
|
||||||
fn to_any(&self) -> AnyViewHandle;
|
fn to_any(&self) -> AnyViewHandle;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -401,20 +403,31 @@ impl Pane {
|
||||||
V: Toolbar,
|
V: Toolbar,
|
||||||
{
|
{
|
||||||
let type_id = TypeId::of::<V>();
|
let type_id = TypeId::of::<V>();
|
||||||
let active_item = self.active_item();
|
if self.active_toolbar_type != Some(type_id) {
|
||||||
self.toolbars
|
self.dismiss_toolbar(cx);
|
||||||
.entry(type_id)
|
|
||||||
.or_insert_with(|| Box::new(cx.add_view(build_toolbar)));
|
let active_item = self.active_item();
|
||||||
self.active_toolbar_type = Some(type_id);
|
self.toolbars
|
||||||
self.active_toolbar_visible = self.toolbars[&type_id].active_item_changed(active_item, cx);
|
.entry(type_id)
|
||||||
cx.notify();
|
.or_insert_with(|| Box::new(cx.add_view(build_toolbar)));
|
||||||
|
|
||||||
|
self.active_toolbar_type = Some(type_id);
|
||||||
|
self.active_toolbar_visible =
|
||||||
|
self.toolbars[&type_id].active_item_changed(active_item, cx);
|
||||||
|
cx.notify();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn hide_toolbar(&mut self, cx: &mut ViewContext<Self>) {
|
pub fn dismiss_toolbar(&mut self, cx: &mut ViewContext<Self>) {
|
||||||
self.active_toolbar_type = None;
|
if let Some(active_toolbar_type) = self.active_toolbar_type.take() {
|
||||||
self.active_toolbar_visible = false;
|
self.toolbars
|
||||||
self.focus_active_item(cx);
|
.get_mut(&active_toolbar_type)
|
||||||
cx.notify();
|
.unwrap()
|
||||||
|
.on_dismiss(cx);
|
||||||
|
self.active_toolbar_visible = false;
|
||||||
|
self.focus_active_item(cx);
|
||||||
|
cx.notify();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn toolbar<T: Toolbar>(&self) -> Option<ViewHandle<T>> {
|
pub fn toolbar<T: Toolbar>(&self) -> Option<ViewHandle<T>> {
|
||||||
|
@ -437,7 +450,9 @@ impl Pane {
|
||||||
if let Some(type_id) = self.active_toolbar_type {
|
if let Some(type_id) = self.active_toolbar_type {
|
||||||
if let Some(toolbar) = self.toolbars.get(&type_id) {
|
if let Some(toolbar) = self.toolbars.get(&type_id) {
|
||||||
self.active_toolbar_visible = toolbar.active_item_changed(
|
self.active_toolbar_visible = toolbar.active_item_changed(
|
||||||
Some(self.item_views[self.active_item_index].1.clone()),
|
self.item_views
|
||||||
|
.get(self.active_item_index)
|
||||||
|
.map(|i| i.1.clone()),
|
||||||
cx,
|
cx,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -621,6 +636,10 @@ impl<T: Toolbar> ToolbarHandle for ViewHandle<T> {
|
||||||
self.update(cx, |this, cx| this.active_item_changed(item, cx))
|
self.update(cx, |this, cx| this.active_item_changed(item, cx))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn on_dismiss(&self, cx: &mut MutableAppContext) {
|
||||||
|
self.update(cx, |this, cx| this.on_dismiss(cx));
|
||||||
|
}
|
||||||
|
|
||||||
fn to_any(&self) -> AnyViewHandle {
|
fn to_any(&self) -> AnyViewHandle {
|
||||||
self.into()
|
self.into()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue