Simplify NoAction filtering logic
co-authored-by: Max Brunsfeld <max@zed.dev>
This commit is contained in:
parent
4cc06748c9
commit
a4bf19c5bd
2 changed files with 7 additions and 8 deletions
|
@ -14,8 +14,8 @@ use crate::{
|
||||||
text_layout::TextLayoutCache,
|
text_layout::TextLayoutCache,
|
||||||
util::post_inc,
|
util::post_inc,
|
||||||
Action, AnyView, AnyViewHandle, AppContext, BorrowAppContext, BorrowWindowContext, Effect,
|
Action, AnyView, AnyViewHandle, AppContext, BorrowAppContext, BorrowWindowContext, Effect,
|
||||||
Element, Entity, Handle, LayoutContext, MouseRegion, MouseRegionId, NoAction, SceneBuilder,
|
Element, Entity, Handle, LayoutContext, MouseRegion, MouseRegionId, SceneBuilder, Subscription,
|
||||||
Subscription, View, ViewContext, ViewHandle, WindowInvalidation,
|
View, ViewContext, ViewHandle, WindowInvalidation,
|
||||||
};
|
};
|
||||||
use anyhow::{anyhow, bail, Result};
|
use anyhow::{anyhow, bail, Result};
|
||||||
use collections::{HashMap, HashSet};
|
use collections::{HashMap, HashSet};
|
||||||
|
@ -430,11 +430,7 @@ impl<'a> WindowContext<'a> {
|
||||||
MatchResult::None => false,
|
MatchResult::None => false,
|
||||||
MatchResult::Pending => true,
|
MatchResult::Pending => true,
|
||||||
MatchResult::Matches(matches) => {
|
MatchResult::Matches(matches) => {
|
||||||
let no_action_id = (NoAction {}).id();
|
|
||||||
for (view_id, action) in matches {
|
for (view_id, action) in matches {
|
||||||
if action.id() == no_action_id {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if self.dispatch_action(Some(*view_id), action.as_ref()) {
|
if self.dispatch_action(Some(*view_id), action.as_ref()) {
|
||||||
self.keystroke_matcher.clear_pending();
|
self.keystroke_matcher.clear_pending();
|
||||||
handled_by = Some(action.boxed_clone());
|
handled_by = Some(action.boxed_clone());
|
||||||
|
|
|
@ -8,7 +8,7 @@ use std::{any::TypeId, fmt::Debug};
|
||||||
use collections::HashMap;
|
use collections::HashMap;
|
||||||
use smallvec::SmallVec;
|
use smallvec::SmallVec;
|
||||||
|
|
||||||
use crate::Action;
|
use crate::{Action, NoAction};
|
||||||
|
|
||||||
pub use binding::{Binding, BindingMatchResult};
|
pub use binding::{Binding, BindingMatchResult};
|
||||||
pub use keymap::Keymap;
|
pub use keymap::Keymap;
|
||||||
|
@ -81,6 +81,7 @@ impl KeymapMatcher {
|
||||||
// The key is the reverse position of the binding in the bindings list so that later bindings
|
// The key is the reverse position of the binding in the bindings list so that later bindings
|
||||||
// match before earlier ones in the user's config
|
// match before earlier ones in the user's config
|
||||||
let mut matched_bindings: Vec<(usize, Box<dyn Action>)> = Default::default();
|
let mut matched_bindings: Vec<(usize, Box<dyn Action>)> = Default::default();
|
||||||
|
let no_action_id = (NoAction {}).id();
|
||||||
|
|
||||||
let first_keystroke = self.pending_keystrokes.is_empty();
|
let first_keystroke = self.pending_keystrokes.is_empty();
|
||||||
self.pending_keystrokes.push(keystroke.clone());
|
self.pending_keystrokes.push(keystroke.clone());
|
||||||
|
@ -108,7 +109,9 @@ impl KeymapMatcher {
|
||||||
match binding.match_keys_and_context(&self.pending_keystrokes, &self.contexts[i..])
|
match binding.match_keys_and_context(&self.pending_keystrokes, &self.contexts[i..])
|
||||||
{
|
{
|
||||||
BindingMatchResult::Complete(action) => {
|
BindingMatchResult::Complete(action) => {
|
||||||
matched_bindings.push((*view_id, action));
|
if action.id() != no_action_id {
|
||||||
|
matched_bindings.push((*view_id, action));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
BindingMatchResult::Partial => {
|
BindingMatchResult::Partial => {
|
||||||
self.pending_views
|
self.pending_views
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue