@@ -837,29 +837,40 @@ func (a *App) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
837837 }
838838 }
839839
840- // If SQL editor is focused and expanded, route input there
841- if a .isSQLEditorFocused () && a . sqlEditor . IsExpanded () {
840+ // If SQL editor is focused, handle input
841+ if a .isSQLEditorFocused () {
842842 // Handle escape to unfocus
843843 if msg .String () == "esc" {
844- a .sqlEditor .Collapse ()
844+ if a .sqlEditor .IsExpanded () {
845+ a .sqlEditor .Collapse ()
846+ }
845847 a .state .FocusArea = models .FocusDataPanel
846848 a .updatePanelStyles ()
847849 return a , nil
848850 }
849851
850- // Handle ctrl+e to collapse
852+ // Handle ctrl+e to toggle expand/ collapse
851853 if msg .String () == "ctrl+e" {
852- a .sqlEditor .Collapse ()
853- a .state .FocusArea = models .FocusDataPanel
854- a .updatePanelStyles ()
854+ if a .sqlEditor .IsExpanded () {
855+ a .sqlEditor .Collapse ()
856+ a .state .FocusArea = models .FocusDataPanel
857+ a .updatePanelStyles ()
858+ } else {
859+ a .sqlEditor .Expand ()
860+ }
855861 return a , nil
856862 }
857863
858- // Tab is handled in the unified Tab case below when not editing
864+ // Tab is handled in the unified Tab case below for focus cycling
859865 if msg .String () == "tab" || msg .String () == "shift+tab" || msg .String () == "backtab" {
860866 // Let Tab fall through to the switch case for focus cycling
861- } else {
862- // Route other keys to SQL editor
867+ } else if a .sqlEditor .IsExpanded () {
868+ // Route other keys to SQL editor when expanded
869+ _ , cmd := a .sqlEditor .Update (msg )
870+ return a , cmd
871+ } else if isPrintableInput (msg .String ()) {
872+ // Auto-expand and route printable input when collapsed but focused
873+ a .sqlEditor .Expand ()
863874 _ , cmd := a .sqlEditor .Update (msg )
864875 return a , cmd
865876 }
@@ -2334,6 +2345,42 @@ func (a *App) isSQLEditorFocused() bool {
23342345 return a .state .FocusArea == models .FocusSQLEditor
23352346}
23362347
2348+ // isPrintableInput checks if a key message is a printable character input
2349+ // that should trigger auto-expand in SQL editor (not a control/shortcut key)
2350+ func isPrintableInput (key string ) bool {
2351+ // Blacklist: keys that should always be shortcuts, not input
2352+ blacklist := map [string ]bool {
2353+ "tab" : true , "shift+tab" : true , "backtab" : true ,
2354+ "esc" : true , "escape" : true ,
2355+ "[" : true , "]" : true ,
2356+ "up" : true , "down" : true , "left" : true , "right" : true ,
2357+ "home" : true , "end" : true , "pgup" : true , "pgdown" : true ,
2358+ "f1" : true , "f2" : true , "f3" : true , "f4" : true , "f5" : true ,
2359+ "f6" : true , "f7" : true , "f8" : true , "f9" : true , "f10" : true ,
2360+ "f11" : true , "f12" : true ,
2361+ }
2362+
2363+ if blacklist [key ] {
2364+ return false
2365+ }
2366+
2367+ // Any key with Ctrl or Alt modifier is a shortcut
2368+ if strings .HasPrefix (key , "ctrl+" ) || strings .HasPrefix (key , "alt+" ) {
2369+ return false
2370+ }
2371+
2372+ // Single printable characters, space, enter, backspace are input
2373+ if len (key ) == 1 {
2374+ return true
2375+ }
2376+
2377+ // Special input keys
2378+ inputKeys := map [string ]bool {
2379+ "enter" : true , "space" : true , "backspace" : true , "delete" : true ,
2380+ }
2381+ return inputKeys [key ]
2382+ }
2383+
23372384// handleMouseEvent processes mouse events for scrolling and clicking using bubblezone
23382385func (a * App ) handleMouseEvent (msg tea.MouseMsg ) (tea.Model , tea.Cmd ) {
23392386 // Handle connection dialog mouse events
0 commit comments