@@ -127,58 +127,85 @@ const StatusLine = Module("statusline", {
127
127
128
128
// set the visibility of the statusline
129
129
setVisibility : function ( request ) {
130
- if ( typeof this . setVisibility . currVisibility == 'undefined' ) {
131
- this . setVisibility . currVisibility = true ;
132
- this . setVisibility . prevVisibility = true ;
133
- this . setVisibility . contentSeparator
134
- = highlight . get ( 'ContentSeparator' ) . value ;
135
-
136
- // kinds of requests
137
- this . setVisibility . MODE_ON = 0 ; // commandline active
138
- this . setVisibility . MODE_OFF = 1 ; // commandline inactive
139
- this . setVisibility . TOGGLE = 2 ; // toggle on or off
140
- this . setVisibility . FULLSCREEN = 3 ; // in or out of fullscreen
130
+ if ( typeof this . setVisibility . UPDATE == 'undefined' ) { // TODO proper initialization
131
+ this . setVisibility . UPDATE = 0 ; // Apply current configuration
132
+ this . setVisibility . SHOW = 1 ; // Temporarily show statusline
133
+ this . setVisibility . HIDE = 2 ; // Temporarily hide statusline
134
+ this . setVisibility . TOGGLE = 3 ; // Cycle through all three modes (auto, visible, hidden)
135
+
136
+ this . setVisibility . contentSeparator = highlight . get ( 'ContentSeparator' ) . value ;
137
+ this . setVisibility . isVisible = true ;
141
138
}
142
139
143
140
const bb = document . getElementById ( "liberator-bottombar" ) ;
144
141
const sv = this . setVisibility ;
145
142
146
143
if ( ! bb ) return ;
147
144
148
- var toggle_off = function ( ) {
145
+ var hideStatusline = function ( ) {
146
+ // Do nothing if statusline is invisible, because it would store an invalid version of ContentSeparator.
147
+ // Do nothing if we are in commandline mode, because the user interacts with the statusline.
148
+ if ( ! sv . isVisible || liberator . mode == modes . COMMAND_LINE ) {
149
+ return ;
150
+ }
151
+
149
152
bb . style . height = '0px' ;
150
153
bb . style . overflow = 'hidden' ;
154
+ sv . contentSeparator = highlight . get ( 'ContentSeparator' ) . value ;
151
155
highlight . set ( 'ContentSeparator' , 'display: none;' ) ;
156
+ sv . isVisible = false ;
152
157
} ;
153
158
154
- var toggle_on = function ( ) {
159
+ var showStatusline = function ( ) {
160
+ if ( sv . isVisible ) {
161
+ return ;
162
+ }
163
+
155
164
bb . style . height = '' ;
156
165
bb . style . overflow = '' ;
157
166
highlight . set ( 'ContentSeparator' , sv . contentSeparator ) ;
167
+ sv . isVisible = true ;
158
168
} ;
159
169
170
+ let mode = options [ "statuslinevisibility" ] ;
171
+
160
172
switch ( request ) {
161
- case sv . TOGGLE :
162
- sv . currVisibility = ! sv . currVisibility ;
163
- if ( sv . currVisibility ) toggle_on ( ) ;
164
- else toggle_off ( ) ;
165
- break ;
166
- case sv . FULLSCREEN :
167
- if ( window . fullScreen ) {
168
- sv . prevVisibility = sv . currVisibility ;
169
- sv . currVisibility = false ;
170
- toggle_off ( ) ;
171
- } else {
172
- sv . currVisibility = sv . currVisibility || sv . prevVisibility ;
173
- if ( sv . currVisibility ) toggle_on ( ) ;
174
- }
175
- break ;
176
- case sv . MODE_ON :
177
- if ( ! sv . currVisibility ) toggle_on ( ) ;
178
- break ;
179
- case sv . MODE_OFF :
180
- if ( ! sv . currVisibility ) toggle_off ( ) ;
181
- break ;
173
+ case sv . UPDATE :
174
+ switch ( mode ) {
175
+ case "auto" :
176
+ if ( window . fullScreen ) {
177
+ hideStatusline ( ) ;
178
+ } else {
179
+ showStatusline ( ) ;
180
+ }
181
+ break ;
182
+ case "visible" :
183
+ showStatusline ( ) ;
184
+ break ;
185
+ case "hidden" :
186
+ hideStatusline ( ) ;
187
+ break ;
188
+ }
189
+ break ;
190
+
191
+ case sv . SHOW :
192
+ showStatusline ( ) ;
193
+ break ;
194
+
195
+ case sv . HIDE :
196
+ // Only hide when in auto+fullscreen or hidden.
197
+ if ( ( mode == "auto" && window . fullScreen ) || mode == "hidden" ) {
198
+ hideStatusline ( ) ;
199
+ }
200
+ break ;
201
+
202
+ case sv . TOGGLE :
203
+ switch ( mode ) {
204
+ case "auto" : options [ "statuslinevisibility" ] = "visible" ; break ;
205
+ case "visible" : options [ "statuslinevisibility" ] = "hidden" ; break ;
206
+ case "hidden" : options [ "statuslinevisibility" ] = "auto" ; break ;
207
+ }
208
+ break ;
182
209
}
183
210
} ,
184
211
@@ -381,6 +408,23 @@ const StatusLine = Module("statusline", {
381
408
return [ [ name , fields [ name ] . description ] for ( name of Object . keys ( fields ) ) ] ;
382
409
} ,
383
410
} ) ;
411
+
412
+ options . add ( [ "statuslinevisibility" , "slv" ] ,
413
+ "Control the visibility of the statusline" ,
414
+ "string" , "auto" ,
415
+ {
416
+ setter : function setter ( value ) {
417
+ statusline . setVisibility ( statusline . setVisibility . UPDATE ) ;
418
+ return value ;
419
+ } ,
420
+ completer : function completer ( context ) {
421
+ return [
422
+ [ "auto" , "Hide statusline in fullscreen automatically" ] ,
423
+ [ "visible" , "Always show the statusline" ] ,
424
+ [ "hidden" , "Never show the statusline" ]
425
+ ] ;
426
+ } ,
427
+ } ) ;
384
428
}
385
429
} ) ;
386
430
0 commit comments