@@ -26,12 +26,52 @@ function isSerialVisible() {
2626 return serialPage . classList . contains ( 'active' ) ;
2727}
2828
29+ function setupPanelFocusHandlers ( ) {
30+ console . log ( "Setting up panel focus handlers" ) ;
31+ serialPage . removeEventListener ( 'click' , handleActivePanel ) ;
32+ serialPage . addEventListener ( 'click' , handleActivePanel ) ;
33+ editorPage . removeEventListener ( 'click' , handleActivePanel ) ;
34+ editorPage . addEventListener ( 'click' , handleActivePanel ) ;
35+ }
36+
37+ function handleActivePanel ( event ) {
38+ const panel = event . currentTarget ;
39+ setActivePanel ( panel ) ;
40+ }
41+
42+ function setActivePanel ( panel ) {
43+ if ( panel === serialPage && isSerialVisible ( ) ) {
44+ // Serial panel requested and visible
45+ serialPage . classList . add ( 'focused-panel' ) ;
46+ editorPage . classList . remove ( 'focused-panel' ) ;
47+ console . log ( "Serial panel focused" ) ;
48+ } else if ( panel === editorPage && isEditorVisible ( ) ) {
49+ // Editor panel requested and visible
50+ editorPage . classList . add ( 'focused-panel' ) ;
51+ serialPage . classList . remove ( 'focused-panel' ) ;
52+ console . log ( "Editor panel focused" ) ;
53+ } else {
54+ // Requested panel is not visible, set other panel as focused
55+ if ( isEditorVisible ( ) ) {
56+ editorPage . classList . add ( 'focused-panel' ) ;
57+ serialPage . classList . remove ( 'focused-panel' ) ;
58+ console . log ( "Editor panel focused (default)" ) ;
59+ } else {
60+ serialPage . classList . add ( 'focused-panel' ) ;
61+ editorPage . classList . remove ( 'focused-panel' ) ;
62+ console . log ( "Serial panel focused (default)" ) ;
63+ }
64+ }
65+ }
66+
2967async function toggleEditor ( ) {
3068 if ( isSerialVisible ( ) ) {
3169 editorPage . classList . toggle ( 'active' ) ;
3270 saveSetting ( SETTING_EDITOR_VISIBLE , isEditorVisible ( ) ) ;
3371 updatePageLayout ( UPDATE_TYPE_EDITOR ) ;
3472 }
73+ setupPanelFocusHandlers ( ) ;
74+ setActivePanel ( editorPage ) ;
3575}
3676
3777async function toggleSerial ( ) {
@@ -40,6 +80,8 @@ async function toggleSerial() {
4080 saveSetting ( SETTING_TERMINAL_VISIBLE , isSerialVisible ( ) ) ;
4181 updatePageLayout ( UPDATE_TYPE_SERIAL ) ;
4282 }
83+ setupPanelFocusHandlers ( ) ;
84+ setActivePanel ( serialPage ) ;
4385}
4486
4587btnModeEditor . removeEventListener ( 'click' , toggleEditor ) ;
@@ -229,4 +271,6 @@ pageSeparator.addEventListener('mousedown', async function (e) {
229271
230272fixViewportHeight ( ) ;
231273window . addEventListener ( "resize" , fixViewportHeight ) ;
232- loadPanelSettings ( ) ;
274+ loadPanelSettings ( ) ;
275+ setupPanelFocusHandlers ( ) ;
276+ setActivePanel ( editorPage ) ;
0 commit comments