Skip to content
This repository was archived by the owner on Dec 11, 2017. It is now read-only.
This repository was archived by the owner on Dec 11, 2017. It is now read-only.

Add autocomplete hinting #50

Closed
Closed

Description

@westonruter

Ideally there would be a dropdown with hinting suggestions that appears when typing, though it seems CodeMirror only supports showing ctrl+space by default to show the dropdown.

Activity

  1. westonruter commented on Aug 26, 2017

    @westonruter
    MemberAuthor

    This is working pretty well:

    --- a/better-code-editing.php
    +++ b/better-code-editing.php
    @@ -227,6 +227,8 @@ class Better_Code_Editing_Plugin {
     				'mode' => 'text/css',
     				'gutters' => array( 'CodeMirror-lint-markers' ),
     				'lint' => true,
    +				'hint' => 'auto',
    +				'extraKeys' => array( "Ctrl-Space" => "autocomplete" ),
     			) );
     		} elseif ( in_array( $extension, array( 'php', 'phtml', 'php3', 'php4', 'php5', 'php7', 'phps' ), true ) ) {
     			$settings['codemirror']['mode'] = 'application/x-httpd-php';
    @@ -325,6 +327,9 @@ class Better_Code_Editing_Plugin {
     					if ( ! empty( $settings['codemirror']['lint'] ) ) {
     						wp_enqueue_script( 'codemirror-addon-lint-css' );
     					}
    +					if ( ! empty( $settings['codemirror']['hint'] ) ) {
    +						wp_enqueue_script( 'codemirror-addon-hint-css' );
    +					}
     					break;
     			}
     
    diff --git a/wp-admin/js/code-editor.js b/wp-admin/js/code-editor.js
    index 7a229f2..621c20e 100644
    --- a/wp-admin/js/code-editor.js
    +++ b/wp-admin/js/code-editor.js
    @@ -98,6 +98,13 @@ if ( 'undefined' === typeof window.wp.codeEditor ) {
     		// Keep track of the instances that have been created.
     		wp.codeEditor.instances.push( editor );
     
    +		editor.on( 'keyup', function ( _editor, event ) {
    +			var enterKey = 13;
    +			if ( ! editor.state.completionActive && event.keyCode !== enterKey ) {
    +				CodeMirror.commands.autocomplete( editor, null, { completeSingle: false } );
    +			}
    +		});
    +
     		// Make sure the editor gets updated if the content was updated on the server (sanitization) but not updated in the editor since it was focused.
     		editor.on( 'blur', function() {
     			$textarea.data( 'next-tab-blurs', false );
  2. westonruter commented on Aug 26, 2017

    @westonruter
    MemberAuthor

    image

  3. westonruter commented on Aug 26, 2017

    @westonruter
    MemberAuthor

    Sourced from: https://stackoverflow.com/a/33021864/93579

    A problem with this is the autocomplete list is showing too aggressively. It should only be shown after typing letter, not Tab. Also, hitting Esc should maybe close the autocomplete suggestions.

  4. westonruter commented on Aug 27, 2017

    @westonruter
    MemberAuthor
    • Need to make sure that autocompletion for Additional CSS in the Customizer doesn't clash with autocomplete for Custom HTML widget.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions