Skip to content

Commit 3362178

Browse files
committed
[search addon] Further simplify dialog building, fix bug in replace dialog
Issue #6746
1 parent 68d3399 commit 3362178

File tree

1 file changed

+24
-34
lines changed

1 file changed

+24
-34
lines changed

addon/search/search.js

Lines changed: 24 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,8 @@
189189
if (state.annotate) { state.annotate.clear(); state.annotate = null; }
190190
});}
191191

192-
function el(tag, attrs, content) {
193-
var element = document.createElement(tag);
192+
function el(tag, attrs) {
193+
var element = tag ? document.createElement(tag) : document.createDocumentFragment();
194194
for (var key in attrs) {
195195
element[key] = attrs[key];
196196
}
@@ -202,41 +202,30 @@
202202
}
203203

204204
function getQueryDialog(cm) {
205-
var fragment = document.createDocumentFragment();
206-
fragment.appendChild(el('span', {className: 'CodeMirror-search-label'}, cm.phrase("Search:")));
207-
fragment.appendChild(document.createTextNode(' '));
208-
fragment.appendChild(el('input', {type: 'text', 'style': 'width: 10em', className: 'CodeMirror-search-field'}));
209-
fragment.appendChild(document.createTextNode(' '));
210-
fragment.appendChild(el('span', {style: 'color: #888', className: 'CodeMirror-search-hint'}, cm.phrase("(Use /re/ syntax for regexp search)")));
211-
return fragment;
205+
return el("", null,
206+
el("span", {className: "CodeMirror-search-label"}, cm.phrase("Search:")), " ",
207+
el("input", {type: "text", "style": "width: 10em", className: "CodeMirror-search-field"}), " ",
208+
el("span", {style: "color: #888", className: "CodeMirror-search-hint"},
209+
cm.phrase("(Use /re/ syntax for regexp search)")));
212210
}
213211
function getReplaceQueryDialog(cm) {
214-
var fragment = document.createDocumentFragment();
215-
fragment.appendChild(document.createTextNode(' '));
216-
fragment.appendChild(el('input', {type: 'text', 'style': 'width: 10em', className: 'CodeMirror-search-field'}));
217-
fragment.appendChild(document.createTextNode(' '));
218-
fragment.appendChild(el('span', {style: 'color: #888', className: 'CodeMirror-search-hint'}, cm.phrase("(Use /re/ syntax for regexp search)")));
219-
return fragment;
212+
return el("", null, " ",
213+
el("input", {type: "text", "style": "width: 10em", className: "CodeMirror-search-field"}), " ",
214+
el("span", {style: "color: #888", className: "CodeMirror-search-hint"},
215+
cm.phrase("(Use /re/ syntax for regexp search)")));
220216
}
221217
function getReplacementQueryDialog(cm) {
222-
var fragment = document.createDocumentFragment();
223-
fragment.appendChild(el('span', {className: 'CodeMirror-search-label'}, cm.phrase("With:")));
224-
fragment.appendChild(document.createTextNode(' '));
225-
fragment.appendChild(el('input', {type: 'text', 'style': 'width: 10em', className: 'CodeMirror-search-field'}));
226-
return fragment;
218+
return el("", null,
219+
el("span", {className: "CodeMirror-search-label"}, cm.phrase("With:")), " ",
220+
el("input", {type: "text", "style": "width: 10em", className: "CodeMirror-search-field"}));
227221
}
228222
function getDoReplaceConfirm(cm) {
229-
var fragment = document.createDocumentFragment();
230-
fragment.appendChild(el('span', {className: 'CodeMirror-search-label'}, cm.phrase("Replace?")));
231-
fragment.appendChild(document.createTextNode(' '));
232-
fragment.appendChild(el('button', {}, cm.phrase("Yes")));
233-
fragment.appendChild(document.createTextNode(' '));
234-
fragment.appendChild(el('button', {}, cm.phrase("No")));
235-
fragment.appendChild(document.createTextNode(' '));
236-
fragment.appendChild(el('button', {}, cm.phrase("All")));
237-
fragment.appendChild(document.createTextNode(' '));
238-
fragment.appendChild(el('button', {}, cm.phrase("Stop")));
239-
return fragment;
223+
return el("", null,
224+
el("span", {className: "CodeMirror-search-label"}, cm.phrase("Replace?")), " ",
225+
el("button", {}, cm.phrase("Yes")), " ",
226+
el("button", {}, cm.phrase("No")), " ",
227+
el("button", {}, cm.phrase("All")), " ",
228+
el("button", {}, cm.phrase("Stop")));
240229
}
241230

242231
function replaceAll(cm, query, text) {
@@ -253,9 +242,10 @@
253242
function replace(cm, all) {
254243
if (cm.getOption("readOnly")) return;
255244
var query = cm.getSelection() || getSearchState(cm).lastQuery;
256-
var fragment = document.createDocumentFragment();
257-
fragment.appendChild(el('span', {className: 'CodeMirror-search-label'}, (all ? cm.phrase("Replace all:") : cm.phrase("Replace:"))));
258-
fragment.appendChild(getReplaceQueryDialog(cm));
245+
var dialogText = all ? cm.phrase("Replace all:") : cm.phrase("Replace:")
246+
var fragment = el("", null,
247+
el("span", {className: "CodeMirror-search-label"}, dialogText),
248+
getReplaceQueryDialog(cm))
259249
dialog(cm, fragment, dialogText, query, function(query) {
260250
if (!query) return;
261251
query = parseQuery(query);

0 commit comments

Comments
 (0)