Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use BTreeSet for scopes #123

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions leptos_hotkeys/src/context.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use leptos::html::ElementDescriptor;
use leptos::*;
use std::collections::HashSet;
use std::collections::BTreeSet;
#[cfg(not(feature = "ssr"))]
use wasm_bindgen::JsCast;

Expand All @@ -15,7 +15,7 @@ pub struct HotkeysContext {
#[cfg(not(feature = "ssr"))]
pub set_ref_target: Callback<Option<web_sys::EventTarget>>,

pub active_scopes: RwSignal<HashSet<String>>,
pub active_scopes: RwSignal<BTreeSet<String>>,
pub enable_scope: Callback<String>,
pub disable_scope: Callback<String>,
pub toggle_scope: Callback<String>,
Expand All @@ -24,7 +24,7 @@ pub struct HotkeysContext {
pub fn provide_hotkeys_context<T>(
#[cfg_attr(feature = "ssr", allow(unused_variables))] node_ref: NodeRef<T>,
#[cfg_attr(feature = "ssr", allow(unused_variables))] allow_blur_event: bool,
initially_active_scopes: HashSet<String>,
initially_active_scopes: BTreeSet<String>,
) -> HotkeysContext
where
T: ElementDescriptor + 'static + Clone,
Expand All @@ -41,7 +41,7 @@ where
let pressed_keys: RwSignal<std::collections::HashMap<String, web_sys::KeyboardEvent>> =
RwSignal::new(std::collections::HashMap::new());

let active_scopes: RwSignal<HashSet<String>> = RwSignal::new(initially_active_scopes);
let active_scopes: RwSignal<BTreeSet<String>> = RwSignal::new(initially_active_scopes);

let enable_scope = Callback::new(move |scope: String| {
active_scopes.update(|scopes| {
Expand Down
6 changes: 3 additions & 3 deletions leptos_hotkeys/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
macro_rules! scopes {
() => {
{
let mut set = std::collections::HashSet::<String>::new();
let mut set = std::collections::BTreeSet::<String>::new();
set.insert("*".to_string());
set
}
};

($($lit:literal),+ $(,)?) => {
{
let mut temp_set = std::collections::HashSet::<String>::new();
let mut temp_set = std::collections::BTreeSet::<String>::new();
temp_set.insert("*".to_string());
$(
temp_set.insert($lit.to_string());
Expand All @@ -21,7 +21,7 @@ macro_rules! scopes {

($($expr:expr),+ $(,)?) => {
{
let mut temp_set = std::collections::HashSet::<String>::new();
let mut temp_set = std::collections::BTreeSet::<String>::new();
temp_set.insert("*".to_string());
$(
temp_set.insert($expr);
Expand Down
Loading