From f3b7364e0ec47dfdb77d4c528cdcc2aa56e82f47 Mon Sep 17 00:00:00 2001 From: Brandon Fulljames Date: Tue, 19 Apr 2022 22:23:40 +0900 Subject: [PATCH] Make blur keybind configurable --- table/keys.go | 11 ++++++++++- table/update.go | 2 +- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/table/keys.go b/table/keys.go index 861d4a6..dbf4c1b 100644 --- a/table/keys.go +++ b/table/keys.go @@ -14,7 +14,13 @@ type KeyMap struct { PageFirst key.Binding PageLast key.Binding - Filter key.Binding + // Filter allows the user to start typing and filter the rows. + Filter key.Binding + + // FilterBlur is the key that stops the user's input from typing into the filter. + FilterBlur key.Binding + + // FilterClear will clear the filter while it's blurred. FilterClear key.Binding } @@ -45,6 +51,9 @@ func DefaultKeyMap() KeyMap { Filter: key.NewBinding( key.WithKeys("/"), ), + FilterBlur: key.NewBinding( + key.WithKeys("enter", "esc"), + ), FilterClear: key.NewBinding( key.WithKeys("esc"), ), diff --git a/table/update.go b/table/update.go index f71e973..227c4ea 100644 --- a/table/update.go +++ b/table/update.go @@ -50,7 +50,7 @@ func (m Model) updateFilterTextInput(msg tea.Msg) (Model, tea.Cmd) { var cmd tea.Cmd switch msg := msg.(type) { case tea.KeyMsg: - if msg.Type == tea.KeyEnter || msg.Type == tea.KeyEscape { + if key.Matches(msg, m.keyMap.FilterBlur) { m.filterTextInput.Blur() } }