Repository: hedhyw/json-log-viewer (go)

Issue:
fix: filtering is not working by rune 'q'

Pull request description:
fix: hotkeys in filter
Closes #13

Patch:
diff --git a/internal/app/action.go b/internal/app/action.go
index b6d2a80..fa52d43 100644
--- a/internal/app/action.go
+++ b/internal/app/action.go
@@ -31,7 +31,19 @@ func (m Model) quit() (Model, tea.Cmd) {
 	return m, tea.Quit
 }
 
+func (m Model) quitByRune() (tea.Model, tea.Cmd) {
+	if m.IsFilterShown() {
+		return nil, nil
+	}
+
+	return m, tea.Quit
+}
+
 func (m Model) showFilter() (tea.Model, tea.Cmd) {
+	if m.IsFilterShown() {
+		return nil, nil
+	}
+
 	if !m.IsTableShown() {
 		return nil, nil
 	}
diff --git a/internal/app/handler.go b/internal/app/handler.go
index 0d0e7f6..ef95ee6 100644
--- a/internal/app/handler.go
+++ b/internal/app/handler.go
@@ -12,8 +12,10 @@ func (m Model) handleKeyMsg(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
 	switch msg.String() {
 	case "esc":
 		return m.back()
-	case "q", "ctrl+c":
+	case "ctrl+c":
 		return m.quit()
+	case "q":
+		return m.quitByRune()
 	case "enter":
 		return m.handleEnter()
 	case "f":


Test patch:
diff --git a/internal/app/app_test.go b/internal/app/app_test.go
index c356da5..d019895 100644
--- a/internal/app/app_test.go
+++ b/internal/app/app_test.go
@@ -104,6 +104,19 @@ func TestAppQuit(t *testing.T) {
 			assert.Equal(t, tea.Quit(), cmd())
 		}
 	})
+
+	t.Run("q", func(t *testing.T) {
+		t.Parallel()
+
+		_, cmd := toAppModel(appModel.Update(tea.KeyMsg{
+			Type:  tea.KeyRunes,
+			Runes: []rune{'q'},
+		}))
+
+		if assert.NotNil(t, cmd) {
+			assert.Equal(t, tea.Quit(), cmd())
+		}
+	})
 }
 
 func newTestModel(tb testing.TB, content []byte) app.Model {
@@ -124,3 +137,26 @@ func toAppModel(teaModel tea.Model, cmd tea.Cmd) (app.Model, tea.Cmd) {
 
 	return appModel, cmd
 }
+
+func TestAppViewFiltereRunes(t *testing.T) {
+	appModel := newTestModel(t, assets.ExampleJSONLog())
+
+	appModel, _ = toAppModel(appModel.Update(tea.KeyMsg{
+		Type:  tea.KeyRunes,
+		Runes: []rune{'f'},
+	}))
+	assert.True(t, appModel.IsFilterShown(), appModel.View())
+
+	appModel, cmd := toAppModel(appModel.Update(tea.KeyMsg{
+		Type:  tea.KeyRunes,
+		Runes: []rune{'q'},
+	}))
+	assert.NotEqual(t, tea.Quit(), cmd())
+
+	appModel, cmd = toAppModel(appModel.Update(tea.KeyMsg{
+		Type:  tea.KeyRunes,
+		Runes: []rune{'f'},
+	}))
+	assert.NotEqual(t, tea.Quit(), cmd())
+	assert.True(t, appModel.IsFilterShown(), appModel.View())
+}