Skip to content
This repository was archived by the owner on Sep 6, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/editor/Editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -892,6 +892,21 @@ define(function (require, exports, module) {
return this._codeMirror.lineCount();
};

/**
* Deterines if line is fully visible.
* @param {number} zero-based index of the line to test
* @return {boolean} true if the line is fully visible, false otherwise
*/
Editor.prototype.isLineVisible = function (line) {
var coords = this._codeMirror.charCoords({line: line, ch: 0}, "local"),
scrollInfo = this._codeMirror.getScrollInfo(),
top = scrollInfo.top,
bottom = scrollInfo.top + scrollInfo.clientHeight;

// Check top and bottom and return false for partially visible lines.
return (coords.top >= top && coords.bottom <= bottom);
};

/**
* Gets the number of the first visible line in the editor.
* @returns {number} The 0-based index of the first visible line.
Expand Down
8 changes: 7 additions & 1 deletion src/search/FindReplace.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,13 @@ define(function (require, exports, module) {
}
}

var centerOptions = (isFindFirst) ? Editor.BOUNDARY_IGNORE_TOP : Editor.BOUNDARY_CHECK_NORMAL;
var resultVisible = editor.isLineVisible(cursor.from().line),
centerOptions = Editor.BOUNDARY_CHECK_NORMAL;

if (isFindFirst && resultVisible) {
// no need to scroll if the line with the match is in view
centerOptions = Editor.BOUNDARY_IGNORE_TOP;
}
editor.setSelection(cursor.from(), cursor.to(), true, centerOptions);
state.posFrom = cursor.from();
state.posTo = cursor.to();
Expand Down