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

feat: Make command palette scrollable, other UI improvements #447

Merged
merged 1 commit into from
Nov 2, 2024
Merged
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
22 changes: 21 additions & 1 deletion src/biscuit/common/palette/palette.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,13 @@ def __init__(self, master: App, width=80, *args, **kwargs) -> None:

self.row = 1
self.selected = 0
self.start_index = 0

self.shown_items = []

self.actionsets = []
self.active_set = None
self.active_items = None

self.searchbar = SearchBar(self)
self.searchbar.grid(row=0, sticky=tk.EW, in_=self.container, pady=(0, 2))
Expand Down Expand Up @@ -121,6 +123,19 @@ def configure_bindings(self) -> None:
self.row += 1
self.refresh_selected()

def reset_start_index(self) -> None:
self.start_index = 0

def on_mousewheel(self, event) -> str:
if not self.active_items:
return "break"

# start_index must be between 0 and len(active_items) - 10
self.start_index = min(
max(0, self.start_index - event.delta // 120), len(self.active_items) - 10
)
self.show_items(self.active_items)

def pick_actionset(self, actionset: ActionSet) -> None:
"""Picks an actionset to display in the palette

Expand Down Expand Up @@ -159,6 +174,8 @@ def hide(self, *args) -> None:
self.withdraw()
self.reset()

self.container.unbind_all("<MouseWheel>")

def hide_all_items(self) -> None:
"""Hides all items in the palette"""

Expand Down Expand Up @@ -226,8 +243,9 @@ def show_items(self, items: list[PaletteItem]) -> None:
items (list[PaletteItem]): The items to display in the palette"""

self.hide_all_items()
self.active_items = items

for i in items[:10]:
for i in self.active_items[self.start_index : self.start_index + 10]:
item = self.add_item(*i)
item.mark_term(self.searchbar.term)

Expand Down Expand Up @@ -256,3 +274,5 @@ def show(self, prefix: str = None, default: str = None) -> None:

if default:
self.searchbar.set_search_term(default)

self.container.bind_all("<MouseWheel>", self.on_mousewheel)
1 change: 1 addition & 0 deletions src/biscuit/common/palette/searchbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ def filter(self, *args) -> None:
includes.append(i)

new = list(chain(actionset.get_pinned(term), exact, starts, includes))
self.master.reset_start_index()
if any(new):
self.master.show_items(new)
else:
Expand Down
Loading