@@ -149,6 +149,8 @@ export class DraggableDialog {
149149 protected static keyActions : Map < string , keyMapping > = new Map ( [
150150 [ 'Escape' , ( dialog , event ) => dialog . escKey ( event ) ] ,
151151 [ 'a' , ( dialog , event ) => dialog . aKey ( event ) ] ,
152+ [ 'm' , ( dialog , event ) => dialog . mKey ( event ) ] ,
153+ [ 's' , ( dialog , event ) => dialog . sKey ( event ) ] ,
152154 [ 'ArrowRight' , ( dialog , event ) => dialog . arrowKey ( event , 'right' ) ] ,
153155 [ 'ArrowLeft' , ( dialog , event ) => dialog . arrowKey ( event , 'left' ) ] ,
154156 [ 'ArrowUp' , ( dialog , event ) => dialog . arrowKey ( event , 'up' ) ] ,
@@ -414,21 +416,39 @@ export class DraggableDialog {
414416 changes the two sides that meet at that corner. Dragging elsewhere on
415417 the dialog frame will move the dialog without changing its size.</p>
416418
417- <p>For keyboard users, to change the dialog size, hold the
418- <kbd>alt</kbd> or <kbd>option</kbd> key and press any of the arrow
419- keys to enlarge or shrink the dialog box. Left and right move the
420- right-hand edge of the dialog, while up and down move the bottom edge
421- of the dialog. Hold the <kbd>Win</kbd> or <kbd>Command</kbd> key and
422- press any of the arrow keys to move the dialog box in the given direction.
423- Holding a <kbd>shift</kbd> key as well will make larger changes
424- in the size or position.</p>
425-
426- <p>Use <kbd>Tab</kbd> to move among the text and buttons and links
419+ <p>For keyboard users, there are two ways to adjust the position
420+ and size of the dialog box. The first is to hold the
421+ <kbd>Alt</kbd> or <kbd>Option</kbd> key and press any of the arrow
422+ keys to move the dialog box in the given direction. Hold the
423+ <kbd>Win</kbd> or <kbd>Command</kbd> key and press any of the
424+ arrow keys to enlarge or shrink the dialog box. Left and right
425+ move the right-hand edge of the dialog, while up and down move the
426+ bottom edge of the dialog.
427+ </p>
428+
429+ <p>For some users, holding two keys down at once may be difficult,
430+ so the second way is to press the <kbd>m</kbd> to start "move"
431+ mode, then use the arrow keys to move the dialog box in the given
432+ direction. Press <kbd>m</kbd> again to stop moving the dialog.
433+ Similarly, press <kbd>s</kbd> to start and stop "sizing" mode,
434+ where the arrows will change the size of the dialog box.</p>
435+
436+ <p>Holding a <kbd>shift</kbd> key along with the arrow key will
437+ make larger changes in the size or position, for either method
438+ described above.</p>
439+
440+ <p>Use <kbd>Tab</kbd> to move among the text, buttons, and links
427441 within the dialog. The <kbd>Enter</kbd> or <kbd>Space</kbd> key
428442 activates the focused item. The <kbd>Escape</kbd> key closes the
429- dialog, as does clicking outside the dialog box.</p>
443+ dialog, as does clicking outside the dialog box, or clicking the
444+ "\u00D7" icon in the upper right-hand corner of the dialog.</p>
430445 ` ;
431446
447+ /**
448+ * When moving/sizing by keyboard, this gives which is being adjusted.
449+ */
450+ protected mode : string = '' ;
451+
432452 /**
433453 * @param {DialogArgs } args The data describing the dialog
434454 */
@@ -621,6 +641,10 @@ export class DraggableDialog {
621641 this . background . append ( this . dialog ) ;
622642 document . body . append ( this . background ) ;
623643 }
644+ context . window . addEventListener (
645+ 'visibilitychange' ,
646+ this . Visibility . bind ( this )
647+ ) ;
624648 //
625649 // Adjust the min width and height, if the initial dialog is small
626650 //
@@ -849,6 +873,16 @@ export class DraggableDialog {
849873 }
850874 }
851875
876+ /**
877+ * Close the dialog if the pages becomes hidden (e.g., moving
878+ * foreward or backward in the window's history).
879+ */
880+ protected Visibility ( ) {
881+ if ( context . document . hidden ) {
882+ this . closeDialog ( ) ;
883+ }
884+ }
885+
852886 /**
853887 * Handle a keydown event
854888 *
@@ -883,6 +917,26 @@ export class DraggableDialog {
883917 }
884918 }
885919
920+ /**
921+ * Start or stop moving the dialog via arrow keys
922+ *
923+ * @param {KeyboardEvent } event The key event to handle
924+ */
925+ protected mKey ( event : KeyboardEvent ) {
926+ this . mode = this . mode === 'move' ? '' : 'move' ;
927+ this . stop ( event ) ;
928+ }
929+
930+ /**
931+ * Start or stop sizing the dialog via arrow keys
932+ *
933+ * @param {KeyboardEvent } event The key event to handle
934+ */
935+ protected sKey ( event : KeyboardEvent ) {
936+ this . mode = this . mode === 'size' ? '' : 'size' ;
937+ this . stop ( event ) ;
938+ }
939+
886940 /**
887941 * Handle the arrow keys
888942 *
@@ -893,12 +947,12 @@ export class DraggableDialog {
893947 if ( event . ctrlKey || this . dragging ) return ;
894948 this . action = direction ;
895949 this . getWH ( ) ;
896- if ( event . altKey ) {
897- this . dragAction ( event . shiftKey ? 'bigsize' : 'keysize' ) ;
898- this . stop ( event ) ;
899- } else if ( event . metaKey ) {
950+ if ( event . altKey || this . mode === 'move' ) {
900951 this . dragAction ( event . shiftKey ? 'bigmove' : 'keymove' ) ;
901952 this . stop ( event ) ;
953+ } else if ( event . metaKey || this . mode === 'size' ) {
954+ this . dragAction ( event . shiftKey ? 'bigsize' : 'keysize' ) ;
955+ this . stop ( event ) ;
902956 }
903957 this . action = '' ;
904958 }
@@ -992,15 +1046,17 @@ export class DraggableDialog {
9921046 *
9931047 * @param {Event } event The event that caused the closure
9941048 */
995- protected closeDialog ( event : Event ) {
1049+ protected closeDialog ( event ? : Event ) {
9961050 if ( isDialog ) {
9971051 this . dialog . close ( ) ;
9981052 this . dialog . remove ( ) ;
9991053 } else {
10001054 this . background . remove ( ) ;
10011055 }
10021056 this . node ?. focus ( ) ;
1003- this . stop ( event ) ;
1057+ if ( event ) {
1058+ this . stop ( event ) ;
1059+ }
10041060 }
10051061
10061062 /**
0 commit comments