11import { tr } from './translation' ;
2- import { genId } from './utils' ;
2+ import { genId , KEYS } from './utils' ;
33
44export default class Inserter {
55 constructor ( ) {
@@ -79,7 +79,7 @@ export default class Inserter {
7979 this . main = main ;
8080 this . worklog = main . worklog ;
8181 this . selector = main . wrapper . querySelector ( '.ptro-paster-select-wrapper' ) ;
82- this . selector . setAttribute ( 'hidden' , '' ) ;
82+ this . cancelChoosing ( ) ;
8383 this . img = null ;
8484 Object . keys ( this . pasteOptions ) . forEach ( ( k ) => {
8585 const o = this . pasteOptions [ k ] ;
@@ -89,7 +89,7 @@ export default class Inserter {
8989 } else {
9090 o . handle ( this . img ) ;
9191 }
92- this . selector . setAttribute ( 'hidden' , '' ) ;
92+ this . cancelChoosing ( ) ;
9393 } ;
9494 } ) ;
9595 this . loading = false ;
@@ -101,6 +101,11 @@ export default class Inserter {
101101 this . main . worklog . reCaptureState ( ) ;
102102 }
103103
104+ cancelChoosing ( ) {
105+ this . selector . setAttribute ( 'hidden' , '' ) ;
106+ this . waitChoice = false ;
107+ }
108+
104109 loaded ( img ) {
105110 this . img = img ;
106111 this . loading = false ;
@@ -125,6 +130,13 @@ export default class Inserter {
125130 img . src = source ;
126131 if ( ! empty ) {
127132 this . selector . removeAttribute ( 'hidden' ) ;
133+ this . waitChoice = true ;
134+ }
135+ }
136+
137+ handleKeyDown ( evt ) {
138+ if ( this . waitChoice && evt . keyCode === KEYS . esc ) {
139+ this . cancelChoosing ( ) ;
128140 }
129141 }
130142
@@ -161,8 +173,8 @@ export default class Inserter {
161173 `<div>${ tr ( `pasteOptions.${ k } ` ) } </div>` +
162174 '</button>' ;
163175 } ) ;
164- return ` <div class="ptro-paster-select-wrapper" hidden><div class="ptro-paster-select"><div class="ptro-in">${
165- buttons
166- } </div></div></div>`;
176+ return ' <div class="ptro-paster-select-wrapper" hidden><div class="ptro-paster-select"><div class="ptro-in">' +
177+ `<div class="ptro-paste-label"> ${ tr ( 'pasteOptions.how_to_paste' ) } </div> ${
178+ buttons } </div></div></div>`;
167179 }
168180}
0 commit comments