Skip to content

Commit

Permalink
Allow for tab completion in path entry
Browse files Browse the repository at this point in the history
  • Loading branch information
kra-mo committed Dec 27, 2023
1 parent 47d53d7 commit 3f26853
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion hyperplane/path_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"""An entry for navigating to paths or tags."""
from typing import Any

from gi.repository import Gio, GObject, Gtk
from gi.repository import Gdk, Gio, GObject, Gtk

from hyperplane import shared

Expand All @@ -40,6 +40,11 @@ def __init__(self, **kwargs) -> None:
self.prev_text = ""
self.prev_completion = ""

# Capture the tab key
controller = Gtk.EventControllerKey.new()
controller.connect("key-pressed", self.__key_pressed)
self.add_controller(controller)

@GObject.Signal(name="hide-entry")
def hide(self) -> None:
"""
Expand All @@ -48,6 +53,24 @@ def hide(self) -> None:
Containers of this widget should connect to it and react accordingly.
"""

# https://github.com/GNOME/nautilus/blob/5e8037c109fc00ba3778193404914db73f8fe95c/src/nautilus-location-entry.c#L511
def __key_pressed(
self,
_controller: Gtk.EventControllerKey,
keyval: int,
_keycode: int,
_state: Gdk.ModifierType,
) -> None:
if keyval == Gdk.KEY_Tab:
if self.get_selection_bounds():
self.select_region(-1, -1)
else:
self.error_bell()

return Gdk.EVENT_STOP

return Gdk.EVENT_PROPAGATE

def __complete(self, *_args: Any) -> None:
text = self.get_text()

Expand Down

0 comments on commit 3f26853

Please sign in to comment.