Skip to content

Commit

Permalink
Fixes focusing filter or editor was setting the keybinding as text value
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgerojas26 committed Oct 17, 2023
1 parent 04daf6c commit 26bbccf
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 18 deletions.
19 changes: 8 additions & 11 deletions components/ResultsTable.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@ package components

import (
"fmt"
"lazysql/app"
"lazysql/drivers"
"strings"

"github.com/gdamore/tcell/v2"
"github.com/rivo/tview"
"golang.design/x/clipboard"

"lazysql/app"
"lazysql/drivers"
)

type ResultsTableState struct {
Expand Down Expand Up @@ -39,8 +38,10 @@ type ResultsTable struct {
Editor *SQLEditor
}

var ErrorModal = tview.NewModal()
var App = app.App
var (
ErrorModal = tview.NewModal()
App = app.App
)

func NewResultsTable() *ResultsTable {
state := &ResultsTableState{
Expand Down Expand Up @@ -109,7 +110,6 @@ func (table *ResultsTable) WithFilter() *ResultsTable {
go table.subscribeToFilterChanges()

return table

}

func (table *ResultsTable) WithEditor() *ResultsTable {
Expand All @@ -127,7 +127,6 @@ func (table *ResultsTable) WithEditor() *ResultsTable {
go table.subscribeToEditorChanges()

return table

}

func (table *ResultsTable) AddRows(rows [][]string) {
Expand Down Expand Up @@ -184,11 +183,10 @@ func (table *ResultsTable) tableInputCapture(event *tcell.EventKey) *tcell.Event
if event.Rune() == 47 { // / Key
if table.Editor != nil {
App.SetFocus(table.Editor)
table.Editor.Highlight()
table.RemoveHighlightTable()
table.SetIsFiltering(true)
if table.Editor.GetText() == "/" {
go table.Editor.SetText("", true)
}
return nil
} else {
App.SetFocus(table.Filter.Input)
table.RemoveHighlightTable()
Expand Down Expand Up @@ -740,5 +738,4 @@ func (table *ResultsTable) FetchRecords(tableName string) [][]string {
}

return [][]string{}

}
23 changes: 16 additions & 7 deletions pages/home.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package pages

import (
"github.com/gdamore/tcell/v2"
"github.com/rivo/tview"

"lazysql/app"
"lazysql/components"

"github.com/gdamore/tcell/v2"
"github.com/rivo/tview"
)

type Home struct {
Expand Down Expand Up @@ -46,12 +46,16 @@ func NewHomePage(name string) *Home {

if event.Rune() == '[' {
focusTab(tabbedPane.SwitchToPreviousTab())
return nil
} else if event.Rune() == ']' {
focusTab(tabbedPane.SwitchToNextTab())
return nil
} else if event.Rune() == '{' {
focusTab(tabbedPane.SwitchToFirstTab())
return nil
} else if event.Rune() == '}' {
focusTab(tabbedPane.SwitchToLastTab())
return nil
} else if event.Rune() == 'X' {
tabbedPane.RemoveCurrentTab()

Expand Down Expand Up @@ -98,7 +102,6 @@ func NewHomePage(name string) *Home {
home.AddItem(rightWrapper, 0, 5, false)

home.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey {

tab := tabbedPane.GetCurrentTab()

var table *components.ResultsTable = nil
Expand All @@ -123,6 +126,7 @@ func NewHomePage(name string) *Home {
} else {
tableWithEditor := components.NewResultsTable().WithEditor()
tabbedPane.AppendTab("Editor", tableWithEditor)
tableWithEditor.SetIsFiltering(true)
}
home.focusRightWrapper()
App.ForceDraw()
Expand Down Expand Up @@ -182,7 +186,6 @@ func (home *Home) subscribeToTreeChanges() {
table.FetchRecords(tableName)

app.App.ForceDraw()

}
}
}
Expand All @@ -209,8 +212,14 @@ func focusTab(tab *components.Tab) {

if table.GetIsFiltering() {
go func() {
App.SetFocus(table.Filter.Input)
table.Filter.HighlightLocal()
if table.Filter != nil {
App.SetFocus(table.Filter.Input)
table.Filter.HighlightLocal()
} else if table.Editor != nil {
App.SetFocus(table.Editor)
table.Editor.Highlight()
}

table.RemoveHighlightTable()
App.Draw()
}()
Expand Down

0 comments on commit 26bbccf

Please sign in to comment.