@@ -127,58 +127,119 @@ const StatusLine = Module("statusline", {
127127
128128 // set the visibility of the statusline
129129 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 . MODE_AUTO == 'undefined' ) { // TODO proper initialization
131+ /*
132+ * There are three modes:
133+ *
134+ * AUTO: This shows or hides the statusline depending on the fullscreen state.
135+ * ON: Here the statusline is always visible, even in fullscreen.
136+ * OFF: The statusline is hidden, only the commandline is shown after typing a colon.
137+ */
138+ this . setVisibility . MODE_AUTO = 0 ;
139+ this . setVisibility . MODE_ON = 1 ;
140+ this . setVisibility . MODE_OFF = 2 ;
141+
142+ /*
143+ * Several events can happen:
144+ *
145+ * FULLSCREEN: Whenever the fullscreen state changes.
146+ * TOGGLE: Cycles through all three modes. Currently there's no indicator, so it's not easy with three modes instead of two.
147+ * SHOW and HIDE: These are emitted when entering or leaving the commandline.
148+ */
149+ this . setVisibility . EVENT_TOGGLE = 3 ;
150+ this . setVisibility . EVENT_FULLSCREEN = 4 ;
151+ this . setVisibility . EVENT_SHOW = 5 ;
152+ this . setVisibility . EVENT_HIDE = 6 ;
153+
154+ this . setVisibility . contentSeparator = highlight . get ( 'ContentSeparator' ) . value ;
155+ this . setVisibility . mode = this . setVisibility . MODE_AUTO ;
156+ this . setVisibility . isVisible = true ;
141157 }
142158
143159 const bb = document . getElementById ( "liberator-bottombar" ) ;
144160 const sv = this . setVisibility ;
145161
146162 if ( ! bb ) return ;
147163
148- var toggle_off = function ( ) {
164+ var hideStatusline = function ( ) {
165+ // Do nothing if statusline is invisible, because it would store an invalid version of ContentSeparator.
166+ // Do nothing if we are in commandline mode, because the user interacts with the statusline.
167+ if ( ! sv . isVisible || liberator . mode == modes . COMMAND_LINE ) {
168+ return ;
169+ }
170+
149171 bb . style . height = '0px' ;
150172 bb . style . overflow = 'hidden' ;
173+ sv . contentSeparator = highlight . get ( 'ContentSeparator' ) . value ;
151174 highlight . set ( 'ContentSeparator' , 'display: none;' ) ;
175+ sv . isVisible = false ;
152176 } ;
153177
154- var toggle_on = function ( ) {
178+ var showStatusline = function ( ) {
179+ if ( sv . isVisible ) {
180+ return ;
181+ }
182+
155183 bb . style . height = '' ;
156184 bb . style . overflow = '' ;
157185 highlight . set ( 'ContentSeparator' , sv . contentSeparator ) ;
186+ sv . isVisible = true ;
158187 } ;
159188
160189 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 ;
190+ case sv . MODE_AUTO :
191+ sv . mode = sv . MODE_AUTO ;
192+ statusline . setVisibility ( sv . EVENT_FULLSCREEN ) ;
193+ break ;
194+
195+ case sv . MODE_ON :
196+ sv . mode = sv . MODE_ON ;
197+ showStatusline ( ) ;
198+ break ;
199+
200+ case sv . MODE_OFF :
201+ sv . mode = sv . MODE_OFF ;
202+ hideStatusline ( ) ;
203+ break ;
204+
205+ case sv . EVENT_FULLSCREEN :
206+ // Ignore fullscreen event if we are not in AUTO mode, visiblity was set manually.
207+ if ( sv . mode != sv . MODE_AUTO ) {
208+ break ;
209+ }
210+
211+ if ( window . fullScreen ) {
212+ hideStatusline ( ) ;
213+ } else {
214+ showStatusline ( ) ;
215+ }
216+ break ;
217+
218+ case sv . EVENT_TOGGLE :
219+ // Cycle through all available modes.
220+ switch ( sv . mode ) {
221+ case sv . MODE_AUTO :
222+ statusline . setVisibility ( sv . MODE_ON ) ;
223+ break ;
224+ case sv . MODE_ON :
225+ statusline . setVisibility ( sv . MODE_OFF ) ;
226+ break ;
227+ case sv . MODE_OFF :
228+ statusline . setVisibility ( sv . MODE_AUTO ) ;
229+ break ;
230+ }
231+ break ;
232+
233+ case sv . EVENT_SHOW :
234+ showStatusline ( ) ;
235+ break ;
236+
237+ case sv . EVENT_HIDE :
238+ // Only hide when in AUTO+fullscreen or OFF.
239+ if ( ( sv . mode == sv . MODE_AUTO && window . fullScreen ) || sv . mode == sv . MODE_OFF ) {
240+ hideStatusline ( ) ;
241+ }
242+ break ;
182243 }
183244 } ,
184245
0 commit comments