|
2 | 2 | * @output wp-admin/js/code-editor.js |
3 | 3 | */ |
4 | 4 |
|
| 5 | +/* eslint-env es2020 */ |
| 6 | + |
5 | 7 | if ( 'undefined' === typeof window.wp ) { |
6 | 8 | /** |
7 | 9 | * @namespace wp |
@@ -315,21 +317,25 @@ if ( 'undefined' === typeof window.wp.codeEditor ) { |
315 | 317 | innerMode = wp.CodeMirror.innerMode( codemirror.getMode(), token.state ).mode.name; |
316 | 318 | lineBeforeCursor = codemirror.doc.getLine( codemirror.doc.getCursor().line ).substr( 0, codemirror.doc.getCursor().ch ); |
317 | 319 | if ( 'html' === innerMode || 'xml' === innerMode ) { |
318 | | - shouldAutocomplete = |
| 320 | + shouldAutocomplete = ( |
319 | 321 | '<' === event.key || |
320 | | - '/' === event.key && 'tag' === token.type || |
321 | | - isAlphaKey && 'tag' === token.type || |
322 | | - isAlphaKey && 'attribute' === token.type || |
323 | | - '=' === token.string && token.state.htmlState && token.state.htmlState.tagName; |
| 322 | + ( '/' === event.key && 'tag' === token.type ) || |
| 323 | + ( isAlphaKey && 'tag' === token.type ) || |
| 324 | + ( isAlphaKey && 'attribute' === token.type ) || |
| 325 | + ( '=' === event.key && ( |
| 326 | + token.state.htmlState?.tagName || |
| 327 | + token.state.curState?.htmlState?.tagName |
| 328 | + ) ) |
| 329 | + ); |
324 | 330 | } else if ( 'css' === innerMode ) { |
325 | 331 | shouldAutocomplete = |
326 | 332 | isAlphaKey || |
327 | 333 | ':' === event.key || |
328 | | - ' ' === event.key && /:\s+$/.test( lineBeforeCursor ); |
| 334 | + ( ' ' === event.key && /:\s+$/.test( lineBeforeCursor ) ); |
329 | 335 | } else if ( 'javascript' === innerMode ) { |
330 | 336 | shouldAutocomplete = isAlphaKey || '.' === event.key; |
331 | 337 | } else if ( 'clike' === innerMode && 'php' === codemirror.options.mode ) { |
332 | | - shouldAutocomplete = 'keyword' === token.type || 'variable' === token.type; |
| 338 | + shouldAutocomplete = isAlphaKey && ( 'keyword' === token.type || 'variable' === token.type ); |
333 | 339 | } |
334 | 340 | if ( shouldAutocomplete ) { |
335 | 341 | codemirror.showHint( { completeSingle: false } ); |
|
0 commit comments