searchreplace.js
4.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
module("tinymce.plugins.SearchReplace", {
setupModule: function() {
QUnit.stop();
tinymce.init({
selector: "textarea",
plugins: "searchreplace",
elements: "elm1",
add_unload_trigger: false,
skin: false,
indent: false,
disable_nodechange: true,
valid_elements: 'b,i',
init_instance_callback : function(ed) {
window.editor = ed;
window.setTimeout(function() {
QUnit.start();
}, 0);
}
});
}
});
test('Find no match', function() {
editor.getBody().innerHTML = 'a';
equal(0, editor.plugins.searchreplace.find('x'));
});
test('Find single match', function() {
editor.getBody().innerHTML = 'a';
equal(1, editor.plugins.searchreplace.find('a'));
});
test('Find single match in multiple elements', function() {
editor.getBody().innerHTML = 't<b>e</b><i>xt</i>';
equal(1, editor.plugins.searchreplace.find('text'));
});
test('Find single match, match case: true', function() {
editor.getBody().innerHTML = 'a A';
equal(1, editor.plugins.searchreplace.find('A', true));
});
test('Find single match, whole words: true', function() {
editor.getBody().innerHTML = 'a Ax';
equal(1, editor.plugins.searchreplace.find('a', false, true));
});
test('Find multiple matches', function() {
editor.getBody().innerHTML = 'a b A';
equal(2, editor.plugins.searchreplace.find('a'));
});
test('Find and replace single match', function() {
editor.getBody().innerHTML = 'a';
editor.plugins.searchreplace.find('a');
ok(!editor.plugins.searchreplace.replace('x'));
equal("<p>x</p>", editor.getContent());
});
test('Find and replace first in multiple matches', function() {
editor.getBody().innerHTML = 'a b a';
editor.plugins.searchreplace.find('a');
ok(editor.plugins.searchreplace.replace('x'));
equal("<p>x b a</p>", editor.getContent());
});
test('Find and replace all in multiple matches', function() {
editor.getBody().innerHTML = 'a b a';
editor.plugins.searchreplace.find('a');
ok(!editor.plugins.searchreplace.replace('x', true, true));
equal("<p>x b x</p>", editor.getContent());
});
test('Find multiple matches, move to next and replace', function() {
editor.getBody().innerHTML = 'a a';
equal(2, editor.plugins.searchreplace.find('a'));
editor.plugins.searchreplace.next();
ok(!editor.plugins.searchreplace.replace('x'));
equal("<p>a x</p>", editor.getContent());
});
test('Find and replace fragmented match', function() {
editor.getBody().innerHTML = '<b>te<i>s</i>t</b><b>te<i>s</i>t</b>';
editor.plugins.searchreplace.find('test');
ok(editor.plugins.searchreplace.replace('abc'));
equal(editor.getContent(), "<p><b>abc</b><b>te<i>s</i>t</b></p>");
});
test('Find and replace all fragmented matches', function() {
editor.getBody().innerHTML = '<b>te<i>s</i>t</b><b>te<i>s</i>t</b>';
editor.plugins.searchreplace.find('test');
ok(!editor.plugins.searchreplace.replace('abc', true, true));
equal(editor.getContent(), "<p><b>abc</b><b>abc</b></p>");
});
test('Find multiple matches, move to next and replace backwards', function() {
editor.getBody().innerHTML = 'a a';
equal(2, editor.plugins.searchreplace.find('a'));
editor.plugins.searchreplace.next();
ok(editor.plugins.searchreplace.replace('x', false));
ok(!editor.plugins.searchreplace.replace('y', false));
equal("<p>y x</p>", editor.getContent());
});
test('Find multiple matches and unmark them', function() {
editor.getBody().innerHTML = 'a b a';
equal(2, editor.plugins.searchreplace.find('a'));
editor.plugins.searchreplace.done();
equal('a', editor.selection.getContent());
equal(0, editor.getBody().getElementsByTagName('span').length);
});
test('Find multiple matches with pre blocks', function() {
editor.getBody().innerHTML = 'abc<pre> abc </pre>abc';
equal(3, editor.plugins.searchreplace.find('b'));
equal(Utils.normalizeHtml(editor.getBody().innerHTML), (
'a<span class="mce-match-marker mce-match-marker-selected" data-mce-bogus="1" data-mce-index="0">b</span>c' +
'<pre> a<span class="mce-match-marker" data-mce-bogus="1" data-mce-index="1">b</span>c </pre>' +
'a<span class="mce-match-marker" data-mce-bogus="1" data-mce-index="2">b</span>c'
));
});