@@ -6,6 +6,7 @@ import actions, { key } from "./quickTools";
66
77const CONTEXT_MENU_TIMEOUT = 500 ;
88const MOVE_X_THRESHOLD = 50 ;
9+ const TOUCH_EVENT_OPTIONS = { passive : false } ;
910
1011let time ;
1112let moveX ;
@@ -73,17 +74,19 @@ export default function init() {
7374 else $footer . removeAttribute ( "data-meta" ) ;
7475 } ) ;
7576
76- editorManager . on ( [ "file-content-changed" , "switch-file" ] , ( ) => {
77- if ( editorManager . activeFile ?. isUnsaved ) {
78- $footer . setAttribute ( "data-unsaved" , "true" ) ;
79- } else {
80- $footer . removeAttribute ( "data-unsaved" ) ;
81- }
82- updateHistoryButtons ( ) ;
83- } ) ;
77+ editorManager . on (
78+ [
79+ "file-content-changed" ,
80+ "switch-file" ,
81+ "new-file" ,
82+ "file-loaded" ,
83+ "remove-file" ,
84+ ] ,
85+ scheduleUpdateQuickToolsState ,
86+ ) ;
8487
8588 editorManager . on ( "save-file" , ( ) => {
86- $footer . removeAttribute ( "data-unsaved" ) ;
89+ scheduleUpdateQuickToolsState ( ) ;
8790 } ) ;
8891
8992 editorManager . on ( "editor-state-changed" , updateHistoryButtons ) ;
@@ -97,7 +100,7 @@ export default function init() {
97100 root . appendOuter ( $toggler ) ;
98101 }
99102 document . body . append ( $input ) ;
100- setTimeout ( updateHistoryButtons , 0 ) ;
103+ scheduleUpdateQuickToolsState ( ) ;
101104
102105 if (
103106 appSettings . value . quickToolsTriggerMode ===
@@ -108,7 +111,7 @@ export default function init() {
108111 $footer . addEventListener ( "contextmenu" , oncontextmenu , true ) ;
109112 $footer . addEventListener ( "wheel" , onwheel , { passive : false } ) ;
110113 } else {
111- $footer . addEventListener ( "touchstart" , touchstart ) ;
114+ $footer . addEventListener ( "touchstart" , touchstart , TOUCH_EVENT_OPTIONS ) ;
112115 $footer . addEventListener ( "keydown" , touchstart ) ;
113116 }
114117
@@ -124,7 +127,7 @@ export default function init() {
124127 $footer . removeEventListener ( "click" , onclick ) ;
125128 $footer . removeEventListener ( "wheel" , onwheel ) ;
126129 $footer . addEventListener ( "keydown" , touchstart ) ;
127- $footer . addEventListener ( "touchstart" , touchstart ) ;
130+ $footer . addEventListener ( "touchstart" , touchstart , TOUCH_EVENT_OPTIONS ) ;
128131 }
129132 } ) ;
130133}
@@ -374,6 +377,22 @@ function click($el) {
374377 actions ( action , value ) ;
375378}
376379
380+ function scheduleUpdateQuickToolsState ( ) {
381+ setTimeout ( updateQuickToolsState , 0 ) ;
382+ }
383+
384+ function updateQuickToolsState ( ) {
385+ const { $footer } = quickTools ;
386+
387+ if ( editorManager . activeFile ?. isUnsaved ) {
388+ $footer . setAttribute ( "data-unsaved" , "true" ) ;
389+ } else {
390+ $footer . removeAttribute ( "data-unsaved" ) ;
391+ }
392+
393+ updateHistoryButtons ( ) ;
394+ }
395+
377396function updateHistoryButtons ( ) {
378397 const { editor, activeFile } = editorManager ;
379398 const disabled = ! editor || activeFile ?. type !== "editor" ;
@@ -383,10 +402,20 @@ function updateHistoryButtons() {
383402}
384403
385404function updateHistoryButton ( id , disabled ) {
386- quickTools . $footer
387- . querySelectorAll ( `[data-id="${ id } "]` )
388- . forEach ( ( $button ) => {
389- $button . disabled = disabled ;
390- $button . setAttribute ( "aria-disabled" , String ( disabled ) ) ;
405+ const buttons = new Set ( ) ;
406+
407+ for ( const $container of [
408+ quickTools . $footer ,
409+ quickTools . $row1 ,
410+ quickTools . $row2 ,
411+ ] ) {
412+ $container ?. querySelectorAll ( `[data-id="${ id } "]` ) ?. forEach ( ( $button ) => {
413+ buttons . add ( $button ) ;
391414 } ) ;
415+ }
416+
417+ buttons . forEach ( ( $button ) => {
418+ $button . disabled = disabled ;
419+ $button . setAttribute ( "aria-disabled" , String ( disabled ) ) ;
420+ } ) ;
392421}
0 commit comments