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

[cmv3] Ensure inline widgets are scrolled to be fully visible when opened, and ... #2397

Merged
merged 1 commit into from
Dec 19, 2012
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
11 changes: 10 additions & 1 deletion src/editor/Editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -959,8 +959,17 @@ define(function (require, exports, module) {
var node = inlineWidget.htmlContent,
oldHeight = (node && $(node).height()) || 0;

// TODO: handle ensureVisible
$(node).height(height);
if (ensureVisible) {
var offset = $(node).offset(),
lineSpaceOffset = $(this._getLineSpaceElement()).offset();
this._codeMirror.scrollIntoView({
left: offset.left - lineSpaceOffset.left,
top: offset.top - lineSpaceOffset.top,
right: offset.left - lineSpaceOffset.left, // don't try to make the right edge visible
bottom: offset.top + height - lineSpaceOffset.top
});
}

// update position for all following inline editors
if (oldHeight !== height) {
Expand Down
20 changes: 9 additions & 11 deletions src/editor/MultiRangeInlineEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ define(function (require, exports, module) {
MultiRangeInlineEditor.prototype._ensureCursorVisible = function () {
if ($.contains(this.editors[0].getRootElement(), window.document.activeElement)) {
var cursorCoords = this.editors[0]._codeMirror.cursorCoords(),
lineSpaceOffset = $(this.editors[0]._getLineSpaceElement()).offset(),
inlineLineSpaceOffset = $(this.editors[0]._getLineSpaceElement()).offset(),
rangeListOffset = this.$relatedContainer.offset();
// If we're off the left-hand side, we just want to scroll it into view normally. But
// if we're underneath the range list on the right, we want to ask the host editor to
Expand All @@ -436,16 +436,14 @@ define(function (require, exports, module) {
}

// Vertically, we want to set the scroll position relative to the overall host editor, not
// the lineSpace of the widget itself. Also, we can't use the lineSpace here, because its top
// position just corresponds to whatever CodeMirror happens to have rendered at the top. So
// we need to figure out our position relative to the top of the virtual scroll area, which is
// the top of the actual scroller minus the scroll position.
var scrollerTop = $(this.hostEditor.getScrollerElement()).offset().top - this.hostEditor.getScrollPos().y;
// TODO: [cmv3] scrollIntoView isn't implemented yet
// this.hostEditor._codeMirror.scrollIntoView(cursorCoords.left - lineSpaceOffset.left,
// cursorCoords.top - scrollerTop,
// cursorCoords.left - lineSpaceOffset.left,
// cursorCoords.bottom - scrollerTop);
// the lineSpace of the widget itself.
var hostLineSpaceTop = $(this.hostEditor._getLineSpaceElement()).offset().top;
this.hostEditor._codeMirror.scrollIntoView({
left: cursorCoords.left - inlineLineSpaceOffset.left,
top: cursorCoords.top - hostLineSpaceTop,
right: cursorCoords.left - inlineLineSpaceOffset.left,
bottom: cursorCoords.bottom - hostLineSpaceTop
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that we can use the hostEditor's lineSpace here now because the new scrolling mechanism in v3 still has the lineSpace always be the full height of the virtual document (instead of just a small window around the viewport as in our original version).

});
}
};

Expand Down