Skip to content

Commit ed128e5

Browse files
committed
Added a separate replace all button
1 parent 0035037 commit ed128e5

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

client/utils/codemirror-search.js

+21-2
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,11 @@ export default function(CodeMirror) {
7171
var state = getSearchState(cm);
7272

7373
CodeMirror.on(searchField, "keyup", function (e) {
74-
if (e.keyCode !== 13 && searchField.value.length > 1) { // not enter and more than 1 character to search
74+
if (e.keyCode === 13) {
75+
// If enter is pressed, then shift focus to replace field
76+
replaceField.focus();
77+
}
78+
else if (e.keyCode !== 13 && searchField.value.length > 1) { // not enter and more than 1 character to search
7579
startSearch(cm, getSearchState(cm), searchField.value);
7680
} else if (searchField.value.length <= 1) {
7781
cm.display.wrapper.querySelector('.CodeMirror-search-results').innerText = '';
@@ -157,7 +161,7 @@ export default function(CodeMirror) {
157161

158162
var replaceField = document.getElementById('Replace-input-field');
159163
CodeMirror.on(replaceField, "keyup", function (e) {
160-
if (e.keyCode == 13) // if enter
164+
if (e.keyCode === 13) // if enter
161165
{
162166
startSearch(cm, getSearchState(cm), searchField.value);
163167
replace(cm, parseString(searchField.value), parseString(replaceField.value));
@@ -170,6 +174,12 @@ export default function(CodeMirror) {
170174
replace(cm, parseString(searchField.value), parseString(replaceField.value));
171175
})
172176

177+
var doReplaceAllButton = document.getElementById('Btn-replace-all');
178+
CodeMirror.on(doReplaceAllButton, "click", function(e) {
179+
startSearch(cm, getSearchState(cm), searchField.value);
180+
replace(cm, parseString(searchField.value), parseString(replaceField.value), true);
181+
})
182+
173183
} else {
174184
searchField.focus();
175185
searchField.select();
@@ -483,6 +493,15 @@ export default function(CodeMirror) {
483493
>
484494
<span aria-hidden="true" class="button">Replace</span>
485495
</button>
496+
<button
497+
title="Replace All"
498+
aria-label="Replace All"
499+
role="button"
500+
id="Btn-replace-all"
501+
class="CodeMirror-search-modifier-button CodeMirror-replace-button"
502+
>
503+
<span aria-hidden="true" class="button">Replace All</span>
504+
</button>
486505
</div>
487506
`;
488507

0 commit comments

Comments
 (0)