Skip to content

Commit

Permalink
Merge branch 't/11697'
Browse files Browse the repository at this point in the history
  • Loading branch information
mlewand committed Apr 7, 2016
2 parents 3078f8e + d5291a8 commit 0f2ef4c
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Expand Up @@ -5,6 +5,7 @@ CKEditor 4 Changelog

Fixed Issues:

* [#11697](http://dev.ckeditor.com/ticket/11697): Fixed: It is possible to replace content with wrong letter case.
* [#13886](http://dev.ckeditor.com/ticket/13886): Fixed: Invalid handling of [`CKEDITOR.style`](http://docs.ckeditor.com/#!/api/CKEDITOR.style) instance with `styles` property by [`CKEDITOR.filter`](http://docs.ckeditor.com/#!/api/CKEDITOR.filter).
* [#14535](http://dev.ckeditor.com/ticket/14535): Fixed: CSS syntax corrections. Thanks to [mdjdenormandie](https://github.com/mdjdenormandie)!

Expand Down
25 changes: 21 additions & 4 deletions plugins/find/dialogs/find.js
@@ -1,4 +1,4 @@
/**
/**
* @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
* For licensing, see LICENSE.md or http://ckeditor.com/license
*/
Expand Down Expand Up @@ -464,11 +464,12 @@
isReplace = 1;

// Successiveness of current replace/find.
var result = 0;
var result = 0,
matchOptionsChanged = this.hasMatchOptionsChanged( pattern, matchCase, matchWord );

// 1. Perform the replace when there's already a match here.
// 1. Perform the replace when there's already a match here and match options hasn't change since previous find.
// 2. Otherwise perform the find but don't replace it immediately.
if ( this.matchRange && this.matchRange.isMatched() && !this.matchRange._.isReplaced && !this.matchRange.isReadOnly() ) {
if ( this.matchRange && this.matchRange.isMatched() && !this.matchRange._.isReplaced && !this.matchRange.isReadOnly() && !matchOptionsChanged ) {
// Turn off highlight for a while when saving snapshots.
this.matchRange.removeHighlight();
var domRange = this.matchRange.toDomRange();
Expand All @@ -492,12 +493,28 @@
this.replaceCounter++;
result = 1;
} else {
// Reset match range so new search starts from primary cursor position (not an end of selection). (#11697)
if ( matchOptionsChanged && this.matchRange ) {
this.matchRange.clearMatched();
this.matchRange.removeHighlight();
this.matchRange = null;
}
result = this.find( pattern, matchCase, matchWord, matchCyclic, !isReplaceAll );
}

isReplace = 0;

return result;
},

// Check if pattern or match options changed since last find. (#11697)
matchOptions: null,
hasMatchOptionsChanged: function( pattern, matchCase, matchWord ) {
var matchOptions = [ pattern, matchCase, matchWord ].join( '.' ),
changed = this.matchOptions && this.matchOptions != matchOptions;

this.matchOptions = matchOptions;
return changed;
}
};

Expand Down
67 changes: 67 additions & 0 deletions tests/plugins/find/find.js
Expand Up @@ -79,5 +79,72 @@ bender.test( {
dialog.getButton( 'cancel' ).click();
} );
} );
},

// #11697
'test find and replace with pattern change - replace text after selection': function() {
var bot = this.editorBot;

bot.setHtmlWithSelection( '<p>example text <strong>example</strong> text</p>' );
bot.dialog( 'replace', function( dialog ) {
dialog.setValueOf( 'replace', 'txtFindReplace', 'example' );
dialog.getContentElement( 'replace', 'btnFindReplace' ).click();
dialog.setValueOf( 'replace', 'txtFindReplace', 'ext example' );
dialog.getContentElement( 'replace', 'btnFindReplace' ).click();

assert.areSame( '<p>example t<span title="highlight">ext </span><strong><span title="highlight">example</span></strong> text</p>',
bot.getData( true ), 'Text after previous selection was correctly highlighted.' );

dialog.setValueOf( 'replace', 'txtReplace', 'example2' );
dialog.getContentElement( 'replace', 'btnFindReplace' ).click();
assert.areSame( '<p>example t<span title="highlight">example2</span> text</p>', bot.getData( true ),
'Highlighted text was correctly replaced.' );

dialog.getButton( 'cancel' ).click();
} );
},

// #11697
'test find and replace with pattern change - replace text before selection': function() {
var bot = this.editorBot;

bot.setHtmlWithSelection( '<p>Apollo 11 was the spaceflight that...</p>' );
bot.dialog( 'replace', function( dialog ) {
dialog.setValueOf( 'replace', 'txtFindReplace', 'was the' );
dialog.getContentElement( 'replace', 'btnFindReplace' ).click();
dialog.setValueOf( 'replace', 'txtFindReplace', 'Apollo 11 was the space' );
dialog.getContentElement( 'replace', 'btnFindReplace' ).click();

assert.areSame( '<p><span title="highlight">apollo 11 was the space</span>flight that...</p>',
bot.getData( true ), 'Text before previous selection was correctly highlighted.' );

dialog.setValueOf( 'replace', 'txtReplace', 'A ' );
dialog.getContentElement( 'replace', 'btnFindReplace' ).click();
assert.areSame( '<p><span title="highlight">a </span>flight that...</p>', bot.getData( true ),
'Highlighted text was correctly replaced.' );

dialog.getButton( 'cancel' ).click();
} );
},

// #11697
'test find and replace with options change': function() {
var bot = this.editorBot;

bot.setHtmlWithSelection( '<p>example text</p>' );
bot.dialog( 'replace', function( dialog ) {
dialog.setValueOf( 'replace', 'txtFindReplace', 'EXAMPLE' );
dialog.getContentElement( 'replace', 'btnFindReplace' ).click();
dialog.setValueOf( 'replace', 'txtReplaceCaseChk', true );
dialog.getContentElement( 'replace', 'btnFindReplace' ).click();

assert.areSame( '<p>example text</p>', bot.getData( true ), 'Text was not replace with case sensitive find.' );

dialog.getContentElement( 'replace', 'btnFindReplace' ).click();

assert.areSame( '<p>example text</p>', bot.getData( true ), 'Text was not replace with case sensitive find.' );

dialog.getButton( 'cancel' ).click();
} );
}
} );
6 changes: 6 additions & 0 deletions tests/plugins/find/manual/dialogreplaceselectionupdate.html
@@ -0,0 +1,6 @@
<textarea cols="80" id="editor1" name="editor1" rows="10">
&lt;p&gt;Apollo 11 was the spaceflight that landed the first humans...&lt;/p&gt;
</textarea>
<script>
CKEDITOR.replace( 'editor1' );
</script>
17 changes: 17 additions & 0 deletions tests/plugins/find/manual/dialogreplaceselectionupdate.md
@@ -0,0 +1,17 @@
@bender-tags: tc, 4.5.9, 11697
@bender-ui: collapsed
@bender-ckeditor-plugins: find, wysiwygarea, toolbar

1. Open *Replace* dialog.
1. Type "apollo" in *Find what* field.
1. Click *Replace* button.
* **Expected:** "Apollo" was highlighted inside editor.
1. Check *Match case* checkbox.
1. Click *Replace* button.
* **Expected** "The specified text was not found." message was displayed.
1. Type "Apollo" in *Find what* field.
1. Click *Replace* button.
* **Expected:** "Apollo" was highlighted inside editor.
1. Type "Foo" in *Replace with* field.
1. Click *Replace* button.
* **Expected** Highlighted text changed to "Foo".

0 comments on commit 0f2ef4c

Please sign in to comment.