Skip to content
This repository was archived by the owner on Sep 6, 2021. It is now read-only.

Commit 2e800ef

Browse files
committed
Merge pull request #5002 from rajeshsegu/newFeature
[UX] Issue #4174 - Add find next / previous buttons for easy navigation
2 parents 0da888c + 821fc91 commit 2e800ef

File tree

3 files changed

+51
-4
lines changed

3 files changed

+51
-4
lines changed

src/nls/root/strings.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,11 @@ define({
120120
"BUTTON_REPLACE_ALL" : "All\u2026",
121121
"BUTTON_STOP" : "Stop",
122122
"BUTTON_REPLACE" : "Replace",
123+
124+
"BUTTON_NEXT" : "\u25B6",
125+
"BUTTON_PREV" : "\u25C0",
126+
"BUTTON_NEXT_HINT" : "Next Match",
127+
"BUTTON_PREV_HINT" : "Previous Match",
123128

124129
"OPEN_FILE" : "Open File",
125130
"SAVE_FILE_AS" : "Save File",

src/search/FindReplace.js

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,16 @@ define(function (require, exports, module) {
182182
}
183183

184184
var queryDialog = Strings.CMD_FIND +
185-
": <input type='text' style='width: 10em'/> <div class='message'><span id='find-counter'></span> " +
186-
"<span style='color: #888'>(" + Strings.SEARCH_REGEXP_INFO + ")</span></div><div class='error'></div>";
185+
": <input type='text' style='width: 10em'/>" +
186+
"<div class='navigator'>" +
187+
"<button id='find-prev' class='btn' title='" + Strings.BUTTON_PREV_HINT + "'>" + Strings.BUTTON_PREV + "</button>" +
188+
"<button id='find-next' class='btn' title='" + Strings.BUTTON_NEXT_HINT + "'>" + Strings.BUTTON_NEXT + "</button>" +
189+
"</div>" +
190+
"<div class='message'>" +
191+
"<span id='find-counter'></span> " +
192+
"<span style='color: #888'>(" + Strings.SEARCH_REGEXP_INFO + ")</span>" +
193+
"</div>" +
194+
"<div class='error'></div>";
187195

188196
/**
189197
* If no search pending, opens the search dialog. If search is already open, moves to
@@ -203,6 +211,15 @@ define(function (require, exports, module) {
203211
// occurrence.
204212
var searchStartPos = cm.getCursor(true);
205213

214+
//Helper method to enable next / prev navigation in Find modal bar.
215+
function enableFindNavigator(show) {
216+
if (show) {
217+
$(".modal-bar .navigator").css("display", "inline-block");
218+
} else {
219+
$(".modal-bar .navigator").css("display", "none");
220+
}
221+
}
222+
206223
// Called each time the search query changes while being typed. Jumps to the first matching
207224
// result, starting from the original cursor position
208225
function findFirst(query) {
@@ -215,13 +232,17 @@ define(function (require, exports, module) {
215232
if (!state.query) {
216233
// Search field is empty - no results
217234
$("#find-counter").text("");
235+
enableFindNavigator(false);
218236
cm.setCursor(searchStartPos);
219237
if (modalBar) {
220238
getDialogTextField().removeClass("no-results");
221239
}
222240
return;
223241
}
224242

243+
//Flag that controls the navigation controls.
244+
var enableNavigator = false;
245+
225246
// Highlight all matches
226247
// (Except on huge documents, where this is too expensive)
227248
if (cm.getValue().length < 500000) {
@@ -243,19 +264,24 @@ define(function (require, exports, module) {
243264
cursor = getSearchCursor(cm, state.query, {line: cursor.to().line + 1, ch: 0});
244265
}
245266
}
246-
267+
247268
if (resultCount === 0) {
248269
$("#find-counter").text(Strings.FIND_NO_RESULTS);
249270
} else if (resultCount === 1) {
250-
$("#find-counter").text(Strings.FIND_RESULT_COUNT_SINGLE);
271+
$("#find-counter").text(Strings.FIND_RESULT_COUNT_SINGLE);
251272
} else {
252273
$("#find-counter").text(StringUtils.format(Strings.FIND_RESULT_COUNT, resultCount));
274+
enableNavigator = true;
253275
}
254276

255277
} else {
256278
$("#find-counter").text("");
279+
enableNavigator = true;
257280
}
258281

282+
//Enable Next/Prev navigator buttons if necessary
283+
enableFindNavigator(enableNavigator);
284+
259285
state.posFrom = state.posTo = searchStartPos;
260286
var foundAny = findNext(editor, rev);
261287

@@ -291,6 +317,14 @@ define(function (require, exports, module) {
291317
$(cm.getWrapperElement()).removeClass("find-highlighting");
292318
});
293319

320+
modalBar.getRoot().on("click", function (e) {
321+
if (e.target.id === "find-next") {
322+
_findNext();
323+
} else if (e.target.id === "find-prev") {
324+
_findPrevious();
325+
}
326+
});
327+
294328
var $input = getDialogTextField();
295329
$input.on("input", function () {
296330
findFirst($input.val());

src/styles/brackets.less

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -910,6 +910,13 @@ a, img {
910910
}
911911
}
912912

913+
.modal-bar .navigator {
914+
display: none;
915+
button {
916+
margin: 2px 1px 3px;
917+
}
918+
}
919+
913920
// Search result highlighting - CodeMirror highlighting is pretty constrained. Highlights are
914921
// blended on TOP of the selection color. The "current" search result is indicated by selection,
915922
// so we want the selection visible underneath the highlight. To do this, the highlight must be
@@ -928,6 +935,7 @@ a, img {
928935
}
929936
#find-counter {
930937
font-weight: @font-weight-semibold;
938+
padding: 0 5px;
931939
}
932940

933941

0 commit comments

Comments
 (0)