Make WordPress Core

Changeset 61579


Ignore:
Timestamp:
02/02/2026 08:01:18 PM (7 weeks ago)
Author:
westonruter
Message:

Code Editor: Fix keyboard accessibility of autocompletion for HTML attribute values and PHP keywords/variables.

Developed in https://github.com/WordPress/wordpress-develop/pull/10807

Follow-up to [41376].

Props siliconforks, joedolson, westonruter, afercia, jorbin.
Fixes #42822.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/js/_enqueues/wp/code-editor.js

    r48650 r61579  
    22 * @output wp-admin/js/code-editor.js
    33 */
     4
     5/* eslint-env es2020 */
    46
    57if ( 'undefined' === typeof window.wp ) {
     
    316318                lineBeforeCursor = codemirror.doc.getLine( codemirror.doc.getCursor().line ).substr( 0, codemirror.doc.getCursor().ch );
    317319                if ( 'html' === innerMode || 'xml' === innerMode ) {
    318                     shouldAutocomplete =
     320                    shouldAutocomplete = (
    319321                        '<' === 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                    );
    324330                } else if ( 'css' === innerMode ) {
    325331                    shouldAutocomplete =
    326332                        isAlphaKey ||
    327333                        ':' === event.key ||
    328                         ' ' === event.key && /:\s+$/.test( lineBeforeCursor );
     334                        ( ' ' === event.key && /:\s+$/.test( lineBeforeCursor ) );
    329335                } else if ( 'javascript' === innerMode ) {
    330336                    shouldAutocomplete = isAlphaKey || '.' === event.key;
    331337                } 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 );
    333339                }
    334340                if ( shouldAutocomplete ) {
Note: See TracChangeset for help on using the changeset viewer.