Closed sebhaase closed 9 years ago
This seems to work: http://roysharon.com/blog/37
function scrollIntoView(t) {
if (typeof(t) != 'object') return;
if (t.getRangeAt) {
// we have a Selection object
if (t.rangeCount == 0) return;
t = t.getRangeAt(0);
}
if (t.cloneRange) {
// we have a Range object
var r = t.cloneRange(); // do not modify the source range
r.collapse(true); // collapse to start
var t = r.startContainer;
// if start is an element, then startOffset is the child number
// in which the range starts
if (t.nodeType == 1) t = t.childNodes[r.startOffset];
}
// if t is not an element node, then we need to skip back until we find the
// previous element with which we can call scrollIntoView()
o = t;
while (o && o.nodeType != 1) o = o.previousSibling;
t = o || t.parentNode;
if (t) t.scrollIntoView();
}
// call scrollIntoView(window.getSelection());
ref. http://roysharon.com/blog/wp-content/uploads/2010/12/scrollIntoView.js
It should be easy to force a scroll into view on the caret / selection position. Where would I have to add that function ?
The plugin already has that function to scroll to the selected postion.
For me it scrolls only when going from source-mode to wysiwyg mode - but not when switching into the source-code editor mode.
Yes this is a known issue, which wont be changed. You could use the better CodeMirror Plugin which replaces the default mode
It should be easy to force a scroll into view on the caret / selection position. Where would I have to add that function ?