@@ -3,10 +3,10 @@ import * as monaco from 'monaco-editor/esm/vs/editor/editor.api';
33
44let debounce = ( func , wait , immediate ) => {
55 var timeout ;
6- return function ( ) {
6+ return function ( ) {
77 var context = this ,
88 args = arguments ;
9- var later = function ( ) {
9+ var later = function ( ) {
1010 timeout = null ;
1111 if ( ! immediate ) func . apply ( context , args ) ;
1212 } ;
@@ -122,11 +122,18 @@ export class EditorElement extends LitElement {
122122 this . editor = monaco . editor . create ( htmlElement , {
123123 model : this . currentEditorState . model ,
124124 scrollBeyondLastLine : false ,
125+ readOnly : true ,
125126 minimap : {
126127 enabled : false
127128 }
128129 } ) ;
129130
131+ // Exit the current editor
132+ this . editor . addCommand ( monaco . KeyCode . Escape , ( ) => {
133+ this . editor . updateOptions ( { readOnly : true } ) ;
134+ this . shadowRoot . getElementById ( this . currentType ) . focus ( ) ;
135+ } ) ;
136+
130137 const changeViewZones = ( ) => {
131138 this . editor . changeViewZones ( changeAccessor => {
132139 const domNode = document . createElement ( 'div' ) ;
@@ -170,7 +177,10 @@ export class EditorElement extends LitElement {
170177 window . removeEventListener ( 'resize' , this . handleResize ) ;
171178 }
172179
173- showTab ( type ) {
180+ showTab ( type , event ) {
181+ this . editor . updateOptions ( { readOnly : false } ) ;
182+ if ( event && event . keyCode != 13 ) return ;
183+
174184 this . currentType = type ;
175185 if ( this . files && typeof this . files [ type ] !== 'undefined' ) {
176186 this . currentEditorState . state = this . editor . saveViewState ( ) ;
@@ -185,11 +195,16 @@ export class EditorElement extends LitElement {
185195
186196 render ( ) {
187197 return html `
188- < div class ="root ">
189- < div class ="tab-root ">
198+ < div class ="root " tabindex = 0 >
199+ < div class ="tab-root " tabindex = 0 " >
190200 ${ this . fileTypes . map (
191201 type => html `
192- < div @click ="${ _ => this . showTab ( type ) } " class ="tab ${ type === this . currentType ? 'selected' : '' } ">
202+ < div
203+ @keydown =${ e => this . showTab ( type , e ) }
204+ tabindex =0
205+ @click="${ _ => this . showTab ( type ) } "
206+ id="${ type } "
207+ class="tab ${ type === this . currentType ? 'selected' : '' } ">
193208 ${ type }
194209 </ div >
195210 `
0 commit comments