Skip to content
Closed
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
1 change: 1 addition & 0 deletions linux/changelog.d/4121.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Open Quickly (Ctrl+Shift+O) finds tables and views across the connection’s schemas.
13 changes: 9 additions & 4 deletions linux/crates/app/src/application/accelerators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ use AcceleratorScope::{Application, Component, Local, Stock};
use ShortcutListing::{Listed, Unlisted};
use ShortcutOwner::{
AssistantComposer, BrowseTab, CellEditor, ConnectionTree, DiagramCanvas, DiagramTab, EditorResults, FilterStrip,
Grid, GridCell, HistoryRow, InlineSuggestion, PickerPage, PickerRow, SqlEditor, SqlEditorCursors, SqlEditorTab,
StructureTab, WorkspaceShell,
Grid, GridCell, HistoryRow, InlineSuggestion, PickerPage, PickerRow, QuickOpen, SqlEditor, SqlEditorCursors,
SqlEditorTab, StructureTab, WorkspaceShell,
};
use ShortcutSection::{BrowseTable, DataGrid, ErDiagram, General, TableStructure, Tabs};

Expand Down Expand Up @@ -73,6 +73,11 @@ pub const ACCELERATORS: &[Accelerator] = &[
application("app.new-window", &["<Primary><Shift>n"], General),
application("app.preferences", &["<Primary>comma"], General),
application("win.show-history", &["<Primary><Shift>h"], General),
// Matches Open Quickly in the macOS app.
application("win.quick-open", &["<Primary><Shift>o"], General),
component(QuickOpen, "quick-open.next", &["Down"], Unlisted),
component(QuickOpen, "quick-open.previous", &["Up"], Unlisted),
component(QuickOpen, "quick-open.structure", &["<Primary>Return"], Unlisted),
// As in GIMP and Inkscape.
application("win.export-results", &["<Primary><Shift>e"], General),
// As in GNOME Files.
Expand All @@ -88,8 +93,7 @@ pub const ACCELERATORS: &[Accelerator] = &[
application("win.reopen-closed-tab", &["<Primary><Shift>t"], Tabs),
// Ctrl+Tab stays the tab view's next tab, as across GNOME.
application("win.switch-recent-tab", &["<Primary>e"], Tabs),
// As in GNOME Web and Console.
application("win.show-tabs", &["<Primary><Shift>o"], Tabs),
application("win.show-tabs", &["<Primary><Alt>o"], Tabs),
// AdwTabView's own controller, which runs in the capture phase. The
// workspace removes its Ctrl+Home and Ctrl+End pairs, so the lists
// and the editor inside the tabs keep those keys.
Expand Down Expand Up @@ -563,6 +567,7 @@ pub fn local_shortcut_controller(owner: ShortcutOwner) -> gtk::ShortcutControlle
/// The name `local_shortcut_controller` gives the owner's controller.
pub const fn controller_name(owner: ShortcutOwner) -> &'static str {
match owner {
QuickOpen => "tablepro-quick-open-shortcuts",
WorkspaceShell => "tablepro-workspace-shell-shortcuts",
BrowseTab => "tablepro-browse-tab-shortcuts",
GridCell => "tablepro-grid-cell-shortcuts",
Expand Down
1 change: 1 addition & 0 deletions linux/crates/app/src/application/shortcut_owner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
pub enum ShortcutOwner {
WorkspaceShell,
BrowseTab,
QuickOpen,
/// A data grid's column view, ahead of the list's own key bindings.
GridCell,
/// A data grid's column view, after a focused editor had its turn.
Expand Down
1 change: 1 addition & 0 deletions linux/crates/app/src/ui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ mod name_entry;
mod picker;
mod plain_toast;
mod preferences_dialog;
mod quick_open;
mod result_pane;
pub(crate) mod safe_mode;
mod saved_queries_dialog;
Expand Down
75 changes: 75 additions & 0 deletions linux/crates/app/src/ui/quick_open/matching.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
pub(super) struct Rank(u8, usize);

pub(super) fn normalize(text: &str) -> Vec<char> {
text.chars().flat_map(char::to_lowercase).collect()
}

pub(super) fn rank(typed: &[char], name: &[char]) -> Option<Rank> {
if typed.is_empty() || name.starts_with(typed) {
return Some(Rank(0, 0));
}
if let Some(at) = name.windows(typed.len()).position(|window| window == typed) {
return Some(Rank(1, at));
}
// A qualified name must not pick up letters from a different identifier.
if typed.contains(&'.') {
return None;
}
let mut wanted = typed.iter();
let mut next = wanted.next();
let mut first = None;
for (position, letter) in name.iter().enumerate() {
if next == Some(letter) {
first.get_or_insert(position);
next = wanted.next();
if next.is_none() {
return Some(Rank(2, position - first.unwrap_or(position) + 1 - typed.len()));
}
}
}
None
}

#[cfg(test)]
mod tests {
use super::*;

fn score(typed: &str, name: &str) -> Option<Rank> {
rank(&normalize(typed.trim()), &normalize(name))
}

#[test]
fn classes_never_overlap_even_for_long_names() {
let prefix = score("ab", "ab").unwrap();
let inside = score("ab", &format!("{}ab", "x".repeat(2_000))).unwrap();
let scattered = score("ab", "axb").unwrap();
assert!(prefix < inside && inside < scattered);
}

#[test]
fn whitespace_case_unicode_and_order() {
assert_eq!(score(" ", "orders"), Some(Rank(0, 0)));
assert_eq!(score(" ÉT ", "Études"), Some(Rank(0, 0)));
assert_eq!(score("ods", "orders"), Some(Rank(2, 3)));
assert_eq!(score("sro", "orders"), None);
assert_eq!(score("longer", "a"), None);
assert_eq!(score("x", ""), None);
}

#[test]
fn dotted_searches_keep_the_identifier_contiguous() {
assert_eq!(score("sales.orders", "sales.orders"), Some(Rank(0, 0)));
assert_eq!(score("sales.ord", "sales.orders"), Some(Rank(0, 0)));
assert!(score("sales.orders", "SELECT * FROM sales.orders").is_some());
assert_eq!(score("sales.orders", "sales.order_items"), None);
assert_eq!(score("sales.orders", "sales_archive.orders"), None);
assert!(score("ods", "orders").is_some());
}

#[test]
fn nearer_substrings_and_tighter_subsequences_rank_first() {
assert!(score("ar", "bar").unwrap() < score("ar", "xxbar").unwrap());
assert!(score("ab", "axb").unwrap() < score("ab", "axxxb").unwrap());
}
}
Loading
Loading