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

Commit

Permalink
Ensure inline widgets are scrolled to be fully visible when opened, a…
Browse files Browse the repository at this point in the history
…nd ensure cursor within inline widget remains visible on selection change
  • Loading branch information
Narciso Jaramillo committed Dec 18, 2012
1 parent f028229 commit 32afc6f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
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
});
}
};

Expand Down

0 comments on commit 32afc6f

Please sign in to comment.