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

Commit 3243e74

Browse files
committed
Merge pull request #10413 from adobe/pflynn/find-highlight-tickmark
Highlight scrollbar tickmark for the current Find match
2 parents 8d1b81d + 0a65893 commit 3243e74

3 files changed

Lines changed: 47 additions & 4 deletions

File tree

src/search/FindReplace.js

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ define(function (require, exports, module) {
163163
}
164164
}
165165

166+
console.assert(state.matchIndex !== -1);
166167
if (state.matchIndex !== -1) {
167168
// Convert to 1-based by adding one before showing the index.
168169
findBar.showFindCount(StringUtils.format(Strings.FIND_MATCH_INDEX,
@@ -404,6 +405,7 @@ define(function (require, exports, module) {
404405
function clearCurrentMatchHighlight(cm, state) {
405406
if (state.markedCurrent) {
406407
state.markedCurrent.clear();
408+
ScrollTrackMarkers.markCurrent(-1);
407409
}
408410
}
409411

@@ -426,13 +428,28 @@ define(function (require, exports, module) {
426428

427429
var nextMatch = _getNextMatch(editor, searchBackwards, pos);
428430
if (nextMatch) {
429-
_updateFindBarWithMatchInfo(getSearchState(editor._codeMirror),
430-
{from: nextMatch.start, to: nextMatch.end}, searchBackwards);
431+
// Update match index indicators - only possible if we have resultSet saved (missing if FIND_MAX_FILE_SIZE threshold hit)
432+
if (state.resultSet.length) {
433+
_updateFindBarWithMatchInfo(state,
434+
{from: nextMatch.start, to: nextMatch.end}, searchBackwards);
435+
// Update current-tickmark indicator - only if highlighting enabled (disabled if FIND_HIGHLIGHT_MAX threshold hit)
436+
if (state.marked.length) {
437+
ScrollTrackMarkers.markCurrent(state.matchIndex); // _updateFindBarWithMatchInfo() has updated this index
438+
}
439+
}
440+
431441
_selectAndScrollTo(editor, [nextMatch], true, preferNoScroll);
432-
state.markedCurrent = cm.markText(nextMatch.start, nextMatch.end,
433-
{ className: "searching-current-match", startStyle: "searching-first", endStyle: "searching-last" });
442+
443+
// Only mark text with "current match" highlight if search bar still open
444+
if (findBar && !findBar.isClosed()) {
445+
// If highlighting disabled, apply both match AND current-match styles for correct appearance
446+
var curentMatchClassName = state.marked.length ? "searching-current-match" : "CodeMirror-searching searching-current-match";
447+
state.markedCurrent = cm.markText(nextMatch.start, nextMatch.end,
448+
{ className: curentMatchClassName, startStyle: "searching-first", endStyle: "searching-last" });
449+
}
434450
} else {
435451
cm.setCursor(editor.getCursorPos()); // collapses selection, keeping cursor in place to avoid scrolling
452+
// (nothing more to do: previous highlights already cleared above)
436453
}
437454
});
438455
}

src/search/ScrollTrackMarkers.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,12 @@ define(function (require, exports, module) {
6262
*/
6363
var marks = [];
6464

65+
/**
66+
* Tickmark markCurrent() last called on, or null if never called / called with -1.
67+
* @type {?jQueryObject}
68+
*/
69+
var $markedTickmark;
70+
6571

6672
function _getScrollbar(editor) {
6773
// Be sure to select only the direct descendant, not also elements within nested inline editors
@@ -114,6 +120,7 @@ define(function (require, exports, module) {
114120
if (editor) {
115121
$(".tickmark-track", editor.getRootElement()).empty();
116122
marks = [];
123+
$markedTickmark = null;
117124
}
118125
}
119126

@@ -168,6 +175,18 @@ define(function (require, exports, module) {
168175
marks = marks.concat(posArray);
169176
_renderMarks(posArray);
170177
}
178+
179+
/** @param {number} index Either -1, or an index into the array passed to addTickmarks() */
180+
function markCurrent(index) {
181+
// Remove previous highlight first
182+
if ($markedTickmark) {
183+
$markedTickmark.removeClass("tickmark-current");
184+
$markedTickmark = null;
185+
}
186+
if (index !== -1) {
187+
$markedTickmark = $(".tickmark-track > .tickmark", editor.getRootElement()).eq(index).addClass("tickmark-current");
188+
}
189+
}
171190

172191
// Private helper for unit tests
173192
function _getTickmarks() {
@@ -181,4 +200,5 @@ define(function (require, exports, module) {
181200
exports.clear = clear;
182201
exports.setVisible = setVisible;
183202
exports.addTickmarks = addTickmarks;
203+
exports.markCurrent = markCurrent;
184204
});

src/styles/brackets.less

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1715,6 +1715,12 @@ textarea.exclusions-editor {
17151715
border-top: 1px solid #e0d123;
17161716
border-bottom: 1px solid #d4c620;
17171717
opacity: 0.85; // allow thumb to show through
1718+
&.tickmark-current {
1719+
background-color: #ed9823;
1720+
border-top: 1px solid #dd9128;
1721+
border-bottom: 1px solid #cb8320;
1722+
z-index: 1; // ensure this one appears above overlapping sibling highlights
1723+
}
17181724
}
17191725
}
17201726

0 commit comments

Comments
 (0)