Make WordPress Core


Ignore:
Timestamp:
11/01/2016 08:05:48 PM (7 years ago)
Author:
iseulde
Message:

TinyMCE: wptextpattern: Handle unconverted inline patterns

Make sure the right text is matched when it already contains characters of the pattern.
Adds two more unit tests.

Fixes #37693.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/qunit/wp-includes/js/tinymce/plugins/wptextpattern/plugin.js

    r37668 r39075  
    156156                    skin: false,
    157157                    plugins: 'wptextpattern',
     158                    wptextpattern: {
     159                        inline: [
     160                            { start: '`', end: '`', format: 'code' },
     161                            { start: '``', end: '``', format: 'bold' }
     162                        ]
     163                    },
    158164                    init_instance_callback: function() {
    159165                        editor = arguments[0];
     
    300306    } );
    301307
    302     QUnit.test( 'Inline: single.', function( assert ) {
     308    QUnit.test( 'Inline: single character.', function( assert ) {
    303309        type( '`test`', function() {
    304310            assert.equal( editor.getContent(), '<p><code>test</code></p>' );
     
    307313    } );
    308314
     315    QUnit.test( 'Inline: two characters.', function( assert ) {
     316        type( '``test``', function() {
     317            assert.equal( editor.getContent(), '<p><strong>test</strong></p>' );
     318            assert.equal( editor.selection.getRng().startOffset, 1 );
     319        }, assert.async() );
     320    } );
     321
    309322    QUnit.test( 'Inline: after typing.', function( assert ) {
    310323        editor.setContent( '<p>test test test</p>' );
     
    312325
    313326        type( '`', function() {
    314             editor.selection.setCursorLocation( editor.$( 'p' )[0].firstChild, 11 );
     327            editor.selection.setCursorLocation( editor.$( 'p' )[0].firstChild, 10 );
    315328        }, '`', function() {
    316329            assert.equal( editor.getContent(), '<p>test <code>test</code> test</p>' );
     
    324337        }, assert.async() );
    325338    } );
     339
     340    QUnit.test( 'Convert with previously unconverted pattern', function( assert ) {
     341        editor.setContent( '<p>`test` test&nbsp;</p>' );
     342        editor.selection.setCursorLocation( editor.$( 'p' )[0].firstChild, 12 );
     343
     344        type( '`test`', function() {
     345            assert.equal( editor.getContent(), '<p>`test` test&nbsp;<code>test</code></p>' );
     346        }, assert.async() );
     347    } );
    326348} )( window.jQuery, window.QUnit, window.tinymce, window.setTimeout );
Note: See TracChangeset for help on using the changeset viewer.