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

Commit

Permalink
Merge pull request #7120 from adobe/tom/remove-viewport-hack
Browse files Browse the repository at this point in the history
Simplify the calculation when there are inline editors
  • Loading branch information
RaymondLim committed Mar 7, 2014
2 parents 34ff3d8 + e1119b0 commit 3b72e93
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/view/ViewCommandHandlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ define(function (require, exports, module) {
var scrolledTop = scrollTop / textHeight,
scrolledBottom = (scrollTop + editorHeight) / textHeight;

// Adjust last line to round inward to show a whole lines.
// Adjust the last line to round inward to show a whole lines.
var firstLine = Math.ceil(scrolledTop),
lastLine = Math.floor(scrolledBottom) - 1;

Expand All @@ -267,26 +267,26 @@ define(function (require, exports, module) {
paddingTop = editor._getLineSpaceElement().offsetTop,
editorHeight = scrollInfo.clientHeight,
scrollTop = scrollInfo.top - paddingTop,
linesInView = _getLinesInView(textHeight, scrollTop, editorHeight),
inlinesHeight = 0;
removedScroll = paddingTop;

// Go through all the editors and reduce the scroll top and editor height to recalculate the lines in view
// Go through all the editors and reduce the scroll top and editor height to properly calculate the lines in view
var line, coords;
inlineEditors.forEach(function (inlineEditor) {
line = editor._getInlineWidgetLineNumber(inlineEditor);
coords = editor._codeMirror.charCoords({line: line, ch: 0}, "local");

if (coords.top < scrollInfo.top) {
scrollTop -= inlineEditor.info.height;
linesInView = _getLinesInView(textHeight, scrollTop, editorHeight);
inlinesHeight += inlineEditor.info.height;
removedScroll += inlineEditor.info.height;

} else if (coords.top + inlineEditor.info.height < scrollInfo.top + editorHeight) {
editorHeight -= inlineEditor.info.height;
linesInView = _getLinesInView(textHeight, scrollTop, editorHeight);
}
});

// Calculate the lines in view
var linesInView = _getLinesInView(textHeight, scrollTop, editorHeight);

// If there is no selection move the cursor so that is always visible.
if (!hasSelecction) {
// Move the cursor to the first visible line.
Expand All @@ -306,7 +306,7 @@ define(function (require, exports, module) {

// Scroll and make it snap to lines
var lines = linesInView.first + direction;
editor.setScrollPos(scrollInfo.left, (textHeight * lines) + paddingTop + inlinesHeight);
editor.setScrollPos(scrollInfo.left, (textHeight * lines) + removedScroll);
}

/** Scrolls one line up */
Expand Down

0 comments on commit 3b72e93

Please sign in to comment.