logiguard fork: GPUI xdg-activation keyboard-focus serial fix
Some checks failed
Update All Top Ranking Issues / update_top_ranking_issues (push) Has been cancelled
Triage Project Sync (#84) / Sync triage project (push) Has been cancelled
release_nightly / notify_on_failure (push) Has been cancelled
release_nightly / check_style (push) Has been cancelled
release_nightly / run_tests_windows (push) Has been cancelled
release_nightly / clippy_windows (push) Has been cancelled
release_nightly / bundle_linux_aarch64 (push) Has been cancelled
release_nightly / bundle_linux_x86_64 (push) Has been cancelled
release_nightly / bundle_mac_aarch64 (push) Has been cancelled
release_nightly / bundle_mac_x86_64 (push) Has been cancelled
release_nightly / bundle_windows_aarch64 (push) Has been cancelled
release_nightly / bundle_windows_x86_64 (push) Has been cancelled
release_nightly / build_nix_linux_x86_64 (push) Has been cancelled
release_nightly / build_nix_mac_aarch64 (push) Has been cancelled
release_nightly / update_nightly_tag (push) Has been cancelled
Hotfix Review Monitor / check-hotfix-reviews (push) Has been cancelled
Stale PR Review Reminder / check-stale-prs (push) Has been cancelled
Update Weekly Top Ranking Issues / update_top_ranking_issues (push) Has been cancelled
Bump collab-staging Tag / update-collab-staging-tag (push) Has been cancelled
compliance_check / scheduled_compliance_check (push) Has been cancelled
Some checks failed
Update All Top Ranking Issues / update_top_ranking_issues (push) Has been cancelled
Triage Project Sync (#84) / Sync triage project (push) Has been cancelled
release_nightly / notify_on_failure (push) Has been cancelled
release_nightly / check_style (push) Has been cancelled
release_nightly / run_tests_windows (push) Has been cancelled
release_nightly / clippy_windows (push) Has been cancelled
release_nightly / bundle_linux_aarch64 (push) Has been cancelled
release_nightly / bundle_linux_x86_64 (push) Has been cancelled
release_nightly / bundle_mac_aarch64 (push) Has been cancelled
release_nightly / bundle_mac_x86_64 (push) Has been cancelled
release_nightly / bundle_windows_aarch64 (push) Has been cancelled
release_nightly / bundle_windows_x86_64 (push) Has been cancelled
release_nightly / build_nix_linux_x86_64 (push) Has been cancelled
release_nightly / build_nix_mac_aarch64 (push) Has been cancelled
release_nightly / update_nightly_tag (push) Has been cancelled
Hotfix Review Monitor / check-hotfix-reviews (push) Has been cancelled
Stale PR Review Reminder / check-stale-prs (push) Has been cancelled
Update Weekly Top Ranking Issues / update_top_ranking_issues (push) Has been cancelled
Bump collab-staging Tag / update-collab-staging-tag (push) Has been cancelled
compliance_check / scheduled_compliance_check (push) Has been cancelled
Single-commit orphan branch: full zed-industries/zed @ 8c74db0 source tree with a 3-file patch applied (no upstream history). Patch (crates/gpui_linux/src/linux/wayland/): - serial.rs: add SerialKind::KeyboardEnter - client.rs: store wl_keyboard.enter serial; add latest_serial_of() - window.rs: activate() uses keyboard-enter serial (Mutter focus gate) Mutter honors window activation only when the token carries the keyboard- focus serial from wl_keyboard.enter; GPUI used a stale mouse-press serial. See docs/tray-window-focus-wayland.md in logiguard. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
19
crates/command_palette_hooks/Cargo.toml
Normal file
19
crates/command_palette_hooks/Cargo.toml
Normal file
@@ -0,0 +1,19 @@
|
||||
[package]
|
||||
name = "command_palette_hooks"
|
||||
version = "0.1.0"
|
||||
edition.workspace = true
|
||||
publish.workspace = true
|
||||
license = "GPL-3.0-or-later"
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
|
||||
[lib]
|
||||
path = "src/command_palette_hooks.rs"
|
||||
doctest = false
|
||||
|
||||
[dependencies]
|
||||
collections.workspace = true
|
||||
derive_more.workspace = true
|
||||
gpui.workspace = true
|
||||
workspace.workspace = true
|
||||
1
crates/command_palette_hooks/LICENSE-GPL
Symbolic link
1
crates/command_palette_hooks/LICENSE-GPL
Symbolic link
@@ -0,0 +1 @@
|
||||
../../LICENSE-GPL
|
||||
153
crates/command_palette_hooks/src/command_palette_hooks.rs
Normal file
153
crates/command_palette_hooks/src/command_palette_hooks.rs
Normal file
@@ -0,0 +1,153 @@
|
||||
//! Provides hooks for customizing the behavior of the command palette.
|
||||
|
||||
#![deny(missing_docs)]
|
||||
|
||||
use std::{any::TypeId, rc::Rc};
|
||||
|
||||
use collections::HashSet;
|
||||
use derive_more::{Deref, DerefMut};
|
||||
use gpui::{Action, App, BorrowAppContext, Global, Task, WeakEntity};
|
||||
use workspace::Workspace;
|
||||
|
||||
/// Initializes the command palette hooks.
|
||||
pub fn init(cx: &mut App) {
|
||||
cx.set_global(GlobalCommandPaletteFilter::default());
|
||||
}
|
||||
|
||||
/// A filter for the command palette.
|
||||
#[derive(Default)]
|
||||
pub struct CommandPaletteFilter {
|
||||
hidden_namespaces: HashSet<&'static str>,
|
||||
hidden_action_types: HashSet<TypeId>,
|
||||
/// Actions that have explicitly been shown. These should be shown even if
|
||||
/// they are in a hidden namespace.
|
||||
shown_action_types: HashSet<TypeId>,
|
||||
}
|
||||
|
||||
#[derive(Deref, DerefMut, Default)]
|
||||
struct GlobalCommandPaletteFilter(CommandPaletteFilter);
|
||||
|
||||
impl Global for GlobalCommandPaletteFilter {}
|
||||
|
||||
impl CommandPaletteFilter {
|
||||
/// Returns the global [`CommandPaletteFilter`], if one is set.
|
||||
pub fn try_global(cx: &App) -> Option<&CommandPaletteFilter> {
|
||||
cx.try_global::<GlobalCommandPaletteFilter>()
|
||||
.map(|filter| &filter.0)
|
||||
}
|
||||
|
||||
/// Returns a mutable reference to the global [`CommandPaletteFilter`].
|
||||
pub fn global_mut(cx: &mut App) -> &mut Self {
|
||||
cx.global_mut::<GlobalCommandPaletteFilter>()
|
||||
}
|
||||
|
||||
/// Updates the global [`CommandPaletteFilter`] using the given closure.
|
||||
pub fn update_global<F>(cx: &mut App, update: F)
|
||||
where
|
||||
F: FnOnce(&mut Self, &mut App),
|
||||
{
|
||||
if cx.has_global::<GlobalCommandPaletteFilter>() {
|
||||
cx.update_global(|this: &mut GlobalCommandPaletteFilter, cx| update(&mut this.0, cx))
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns whether the given [`Action`] is hidden by the filter.
|
||||
pub fn is_hidden(&self, action: &dyn Action) -> bool {
|
||||
let name = action.name();
|
||||
let namespace = name.split("::").next().unwrap_or("malformed action name");
|
||||
|
||||
// If this action has specifically been shown then it should be visible.
|
||||
if self.shown_action_types.contains(&action.type_id()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
self.hidden_namespaces.contains(namespace)
|
||||
|| self.hidden_action_types.contains(&action.type_id())
|
||||
}
|
||||
|
||||
/// Hides all actions in the given namespace.
|
||||
pub fn hide_namespace(&mut self, namespace: &'static str) {
|
||||
self.hidden_namespaces.insert(namespace);
|
||||
}
|
||||
|
||||
/// Shows all actions in the given namespace.
|
||||
pub fn show_namespace(&mut self, namespace: &'static str) {
|
||||
self.hidden_namespaces.remove(namespace);
|
||||
}
|
||||
|
||||
/// Hides all actions with the given types.
|
||||
pub fn hide_action_types<'a>(&mut self, action_types: impl IntoIterator<Item = &'a TypeId>) {
|
||||
for action_type in action_types {
|
||||
self.hidden_action_types.insert(*action_type);
|
||||
self.shown_action_types.remove(action_type);
|
||||
}
|
||||
}
|
||||
|
||||
/// Shows all actions with the given types.
|
||||
pub fn show_action_types<'a>(&mut self, action_types: impl IntoIterator<Item = &'a TypeId>) {
|
||||
for action_type in action_types {
|
||||
self.shown_action_types.insert(*action_type);
|
||||
self.hidden_action_types.remove(action_type);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The result of intercepting a command palette command.
|
||||
#[derive(Debug)]
|
||||
pub struct CommandInterceptItem {
|
||||
/// The action produced as a result of the interception.
|
||||
pub action: Box<dyn Action>,
|
||||
/// The display string to show in the command palette for this result.
|
||||
pub string: String,
|
||||
/// The character positions in the string that match the query.
|
||||
/// Used for highlighting matched characters in the command palette UI.
|
||||
pub positions: Vec<usize>,
|
||||
}
|
||||
|
||||
/// The result of intercepting a command palette command.
|
||||
#[derive(Default, Debug)]
|
||||
pub struct CommandInterceptResult {
|
||||
/// The items
|
||||
pub results: Vec<CommandInterceptItem>,
|
||||
/// Whether or not to continue to show the normal matches
|
||||
pub exclusive: bool,
|
||||
}
|
||||
|
||||
/// An interceptor for the command palette.
|
||||
#[derive(Clone)]
|
||||
pub struct GlobalCommandPaletteInterceptor(
|
||||
Rc<dyn Fn(&str, WeakEntity<Workspace>, &mut App) -> Task<CommandInterceptResult>>,
|
||||
);
|
||||
|
||||
impl Global for GlobalCommandPaletteInterceptor {}
|
||||
|
||||
impl GlobalCommandPaletteInterceptor {
|
||||
/// Sets the global interceptor.
|
||||
///
|
||||
/// This will override the previous interceptor, if it exists.
|
||||
pub fn set(
|
||||
cx: &mut App,
|
||||
interceptor: impl Fn(&str, WeakEntity<Workspace>, &mut App) -> Task<CommandInterceptResult>
|
||||
+ 'static,
|
||||
) {
|
||||
cx.set_global(Self(Rc::new(interceptor)));
|
||||
}
|
||||
|
||||
/// Clears the global interceptor.
|
||||
pub fn clear(cx: &mut App) {
|
||||
if cx.has_global::<Self>() {
|
||||
cx.remove_global::<Self>();
|
||||
}
|
||||
}
|
||||
|
||||
/// Intercepts the given query from the command palette.
|
||||
pub fn intercept(
|
||||
query: &str,
|
||||
workspace: WeakEntity<Workspace>,
|
||||
cx: &mut App,
|
||||
) -> Option<Task<CommandInterceptResult>> {
|
||||
let interceptor = cx.try_global::<Self>()?;
|
||||
let handler = interceptor.0.clone();
|
||||
Some(handler(query, workspace, cx))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user