@@ -14,12 +14,11 @@ import { setCommands, setKeyBindings } from 'ace/commands';
1414import { HARDKEYBOARDHIDDEN_NO , getSystemConfiguration } from './systemConfiguration' ;
1515import SideButton , { sideButtonContainer } from 'components/sideButton' ;
1616
17- //TODO: Add option to work multiple files at same time in large display.
18-
1917/**
20- *
21- * @param {HTMLElement } $header
22- * @param {HTMLElement } $body
18+ * Represents an editor manager that handles multiple files and provides various editor configurations and event listeners.
19+ * @param {HTMLElement } $header - The header element.
20+ * @param {HTMLElement } $body - The body element.
21+ * @returns {Promise<Object> } A promise that resolves to the editor manager object.
2322 */
2423async function EditorManager ( $header , $body ) {
2524 /**
@@ -231,8 +230,8 @@ async function EditorManager($header, $body) {
231230 return manager ;
232231
233232 /**
234- *
235- * @param {EditorFile } file
233+ * Adds a file to the manager's file list and updates the UI.
234+ * @param {File } file - The file to be added.
236235 */
237236 function addFile ( file ) {
238237 if ( manager . files . includes ( file ) ) return ;
@@ -241,6 +240,10 @@ async function EditorManager($header, $body) {
241240 $header . text = file . name ;
242241 }
243242
243+ /**
244+ * Sets up the editor with various configurations and event listeners.
245+ * @returns {Promise<void> } A promise that resolves once the editor is set up.
246+ */
244247 async function setupEditor ( ) {
245248 const Emmet = ace . require ( 'ace/ext/emmet' ) ;
246249 const textInput = editor . textInput . getElement ( ) ;
@@ -386,6 +389,9 @@ async function EditorManager($header, $body) {
386389 ) ;
387390 }
388391
392+ /**
393+ * Scrolls the cursor into view if it is not currently visible.
394+ */
389395 function scrollCursorIntoView ( ) {
390396 keyboardHandler . off ( 'keyboardShow' , scrollCursorIntoView ) ;
391397 if ( isCursorVisible ( ) ) return ;
@@ -411,7 +417,7 @@ async function EditorManager($header, $body) {
411417 }
412418
413419 /**
414- * Callback function
420+ * Sets the vertical scroll value of the editor. This is called when the editor is scrolled horizontally using the scrollbar.
415421 * @param {Number } value
416422 */
417423 function onscrollV ( value ) {
@@ -425,13 +431,17 @@ async function EditorManager($header, $body) {
425431 cancelAnimationFrame ( scrollAnimationFrame ) ;
426432 }
427433
434+ /**
435+ * Handles the onscroll event for the vend element.
436+ */
428437 function onscrollVend ( ) {
429438 preventScrollbarV = false ;
430439 }
431440
441+
432442 /**
433- * Callback function
434- * @param {Number } value
443+ * Sets the horizontal scroll value of the editor. This is called when the editor is scrolled vertically using the scrollbar.
444+ * @param {number } value - The scroll value.
435445 */
436446 function onscrollH ( value ) {
437447 preventScrollbarH = true ;
@@ -444,12 +454,15 @@ async function EditorManager($header, $body) {
444454 cancelAnimationFrame ( scrollAnimationFrame ) ;
445455 }
446456
457+ /**
458+ * Handles the event when the horizontal scrollbar reaches the end.
459+ */
447460 function onscrollHEnd ( ) {
448461 preventScrollbarH = false ;
449462 }
450463
451464 /**
452- * Callback function called on scroll vertically
465+ * Sets scrollbars value based on the editor's scroll position.
453466 */
454467 function setHScrollValue ( ) {
455468 if ( appSettings . value . textWrap || preventScrollbarH ) return ;
@@ -466,13 +479,17 @@ async function EditorManager($header, $body) {
466479 editor . _emit ( 'scroll' , 'horizontal' ) ;
467480 }
468481
482+ /**
483+ * Handles the scroll left event.
484+ * Updates the horizontal scroll value and renders the horizontal scrollbar.
485+ */
469486 function onscrollleft ( ) {
470487 setHScrollValue ( ) ;
471488 $hScrollbar . render ( ) ;
472489 }
473490
474491 /**
475- * Callback function called on scroll vertically
492+ * Sets scrollbars value based on the editor's scroll position.
476493 */
477494 function setVScrollValue ( ) {
478495 if ( preventScrollbarV ) return ;
@@ -489,11 +506,19 @@ async function EditorManager($header, $body) {
489506 editor . _emit ( 'scroll' , 'vertical' ) ;
490507 }
491508
509+ /**
510+ * Handles the scroll top event.
511+ * Updates the vertical scroll value and renders the vertical scrollbar.
512+ */
492513 function onscrolltop ( ) {
493514 setVScrollValue ( ) ;
494515 $vScrollbar . render ( ) ;
495516 }
496517
518+ /**
519+ * Updates the floating button visibility based on the provided show parameter.
520+ * @param {boolean } [show=false] - Indicates whether to show the floating button.
521+ */
497522 function updateFloatingButton ( show = false ) {
498523 const { $headerToggler } = acode ;
499524 const { $toggler } = quickTools ;
@@ -513,25 +538,30 @@ async function EditorManager($header, $body) {
513538 $headerToggler . classList . remove ( 'hide' ) ;
514539 root . appendOuter ( $headerToggler ) ;
515540 }
516- } else {
517- if ( ! scrollBarVisibilityCount ) {
518- if ( $toggler . isConnected ) {
519- $toggler . classList . add ( 'hide' ) ;
520- timeoutQuicktoolsToggler = setTimeout (
521- ( ) => $toggler . remove ( ) ,
522- 300 ,
523- ) ;
524- }
525- if ( $headerToggler . isConnected ) {
526- $headerToggler . classList . add ( 'hide' ) ;
527- timeoutHeaderToggler = setTimeout ( ( ) => $headerToggler . remove ( ) , 300 ) ;
528- }
529- }
530541
531- ++ scrollBarVisibilityCount ;
542+ return ;
543+ }
544+
545+ if ( ! scrollBarVisibilityCount ) {
546+ if ( $toggler . isConnected ) {
547+ $toggler . classList . add ( 'hide' ) ;
548+ timeoutQuicktoolsToggler = setTimeout (
549+ ( ) => $toggler . remove ( ) ,
550+ 300 ,
551+ ) ;
552+ }
553+ if ( $headerToggler . isConnected ) {
554+ $headerToggler . classList . add ( 'hide' ) ;
555+ timeoutHeaderToggler = setTimeout ( ( ) => $headerToggler . remove ( ) , 300 ) ;
556+ }
532557 }
558+
559+ ++ scrollBarVisibilityCount ;
533560 }
534561
562+ /**
563+ * Toggles the visibility of the problem button based on the presence of annotations in the files.
564+ */
535565 function toggleProblemButton ( ) {
536566 const fileWithProblems = manager . files . find ( ( file ) => {
537567 const annotations = file . session . getAnnotations ( ) ;
@@ -545,6 +575,11 @@ async function EditorManager($header, $body) {
545575 }
546576 }
547577
578+ /**
579+ * Updates the side button container based on the value of `showSideButtons` in `appSettings`.
580+ * If `showSideButtons` is `false`, the side button container is removed from the DOM.
581+ * If `showSideButtons` is `true`, the side button container is appended to the body element.
582+ */
548583 function updateSideButtonContainer ( ) {
549584 const { showSideButtons } = appSettings . value ;
550585 if ( ! showSideButtons ) {
@@ -555,6 +590,10 @@ async function EditorManager($header, $body) {
555590 $body . append ( sideButtonContainer ) ;
556591 }
557592
593+ /**
594+ * Updates the margin of the editor and optionally updates the gutter settings.
595+ * @param {boolean } [updateGutter=false] - Whether to update the gutter settings.
596+ */
558597 function updateMargin ( updateGutter = false ) {
559598 const { showSideButtons, linenumbers, showAnnotations } = appSettings . value ;
560599 const top = 0 ;
@@ -576,6 +615,10 @@ async function EditorManager($header, $body) {
576615 } ) ;
577616 }
578617
618+ /**
619+ * Switches the active file in the editor.
620+ * @param {string } id - The ID of the file to switch to.
621+ */
579622 function switchFile ( id ) {
580623 const { id : activeFileId } = manager . activeFile || { } ;
581624 if ( activeFileId === id ) return ;
@@ -587,8 +630,8 @@ async function EditorManager($header, $body) {
587630 editor . setSession ( file . session ) ;
588631 $header . text = file . filename ;
589632
590- $hScrollbar . remove ( ) ;
591- $vScrollbar . remove ( ) ;
633+ $hScrollbar . hideImmediately ( ) ;
634+ $vScrollbar . hideImmediately ( ) ;
592635
593636 setVScrollValue ( ) ;
594637 if ( ! appSettings . value . textWrap ) {
@@ -601,6 +644,9 @@ async function EditorManager($header, $body) {
601644 events . emit ( 'switch-file' , file ) ;
602645 }
603646
647+ /**
648+ * Initializes the file tab container.
649+ */
604650 function initFileTabContainer ( ) {
605651 let $list ;
606652
@@ -656,6 +702,10 @@ async function EditorManager($header, $body) {
656702 manager . emit ( 'int-open-file-list' , openFileListPos ) ;
657703 }
658704
705+ /**
706+ * Checks if there are any unsaved files in the manager.
707+ * @returns {number } The number of unsaved files.
708+ */
659709 function hasUnsavedFiles ( ) {
660710 const unsavedFiles = manager . files . filter ( ( file ) => file . isUnsaved ) ;
661711 return unsavedFiles . length ;
0 commit comments