Skip to content

Commit

Permalink
Add an, as of yet undocumented, fourth argument to addWidget
Browse files Browse the repository at this point in the history
Can be one of 'below' (default), 'over', or 'fit', and controls the way
the widget is positioned in relation to the given character position.
'fit' means CodeMirror does its best to keep the widget inside the current
dimensions of the editor.
  • Loading branch information
marijnh committed Jul 4, 2011
1 parent 7db788e commit 3f8f0dd
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions lib/codemirror.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,16 +154,22 @@ var CodeMirror = (function() {
clearMarker: removeGutterMarker,
setLineClass: operation(setLineClass),
lineInfo: lineInfo,
addWidget: function(pos, node, scroll) {
pos = clipPos(pos);
var wcoords = localCoords(pos, true);
node.style.top = (showingFrom * lineHeight() + wcoords.yBot + paddingTop()) + "px";
node.style.left = (wcoords.x + paddingLeft()) + "px";
addWidget: function(pos, node, scroll, where) {
pos = localCoords(clipPos(pos));
var top = pos.yBot, left = pos.x;
node.style.position = "absolute";
code.appendChild(node);
if (scroll) {
var vcoords = localCoords(pos);
scrollIntoView(vcoords.x, vcoords.yBot, vcoords.x + node.offsetWidth, vcoords.yBot + node.offsetHeight);
node.style.left = left + "px";
if (where == "over") top = pos.y;
else if (where == "fit") {
var vspace = lines.length * lineHeight(), hspace = code.clientWidth - paddingLeft();
top = pos.y + node.offsetHeight > vspace ? vspace - node.offsetHeight : pos.y;
if (left + node.offsetWidth > hspace) left = hspace - node.offsetWidth;
}
node.style.top = (top + paddingTop()) + "px";
node.style.left = (left + paddingLeft()) + "px";
if (scroll)
scrollIntoView(left, top, left + node.offsetWidth, top + node.offsetHeight);
},

lineCount: function() {return lines.length;},
Expand Down Expand Up @@ -757,6 +763,8 @@ var CodeMirror = (function() {

var textWidth = stringWidth(maxLine);
lineSpace.style.width = textWidth > scroller.clientWidth ? textWidth + "px" : "";
// Needed to prevent odd wrapping/hiding of widgets placed in here.
code.style.width = (lineSpace.offsetWidth + lineSpace.offsetLeft) + "px";

// Since this is all rather error prone, it is honoured with the
// only assertion in the whole file.
Expand Down

0 comments on commit 3f8f0dd

Please sign in to comment.