Skip to content

Commit 373fcb8

Browse files
committed
Clearing list between plugin switches
1 parent d75992b commit 373fcb8

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

src/vonal_daemon/plugins/mod.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use egui::{Context, Ui};
44

55
use crate::{
66
config::{ConfigBuilder, ConfigError},
7+
theme::list::ListState,
78
GlutinWindowContext,
89
};
910

@@ -95,6 +96,8 @@ pub trait Plugin {
9596
pub struct PluginManager {
9697
plugins: Vec<Box<dyn Plugin>>,
9798
config_plugins: Vec<String>,
99+
/// the nth plugin returned PluginFlowControl::break during search
100+
flow_broke_at: usize,
98101
}
99102
impl PluginManager {
100103
pub fn new() -> Self {
@@ -153,9 +156,14 @@ impl PluginManager {
153156
return;
154157
}
155158

156-
for i in &mut self.plugins {
157-
i.search(ui, ctx);
159+
for (i, plugin) in &mut self.plugins.iter_mut().enumerate() {
160+
plugin.search(ui, ctx);
158161
if let PluginFlowControl::Break = ctx.flow {
162+
// Clear the list on switching between plugins
163+
if self.flow_broke_at != i {
164+
ListState::clear(ui.ctx());
165+
self.flow_broke_at = i;
166+
}
159167
break;
160168
}
161169
}

src/vonal_daemon/theme/list/list_state.rs

+6
Original file line numberDiff line numberDiff line change
@@ -95,4 +95,10 @@ impl ListState {
9595
pub fn reset(ctx: &Context, selected_row: i32) {
9696
ctx.data_mut(|d| d.insert_persisted(Id::new(LIST_ID), Self::new(selected_row)));
9797
}
98+
pub fn clear(ctx: &Context) {
99+
let current: Option<Self> = ctx.data_mut(|d| d.get_persisted(Id::new(LIST_ID)));
100+
if current.is_some() {
101+
ctx.data_mut(|d| d.remove::<Self>(Id::new(LIST_ID)));
102+
}
103+
}
98104
}

0 commit comments

Comments
 (0)