Skip to content

Commit

Permalink
Add a className option to addLineWidget
Browse files Browse the repository at this point in the history
Issue #5952
  • Loading branch information
marijnh committed Dec 16, 2019
1 parent 1c4b922 commit ddafba7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
3 changes: 3 additions & 0 deletions doc/manual.html
Original file line number Diff line number Diff line change
Expand Up @@ -1881,6 +1881,9 @@ <h3 id="api_decoration">Widget, gutter, and decoration methods</h3>
position (zero for the top, N to put it after the Nth other
widget). Note that this only has effect once, when the
widget is created.
<dt><code><strong>className</strong>: string</code></dt>
<dd>Add an extra CSS class name to the wrapper element
created for the widget.</dd>
</dl>
Note that the widget node will become a descendant of nodes with
CodeMirror-specific CSS classes, and those classes might in some
Expand Down
8 changes: 4 additions & 4 deletions src/display/update_line.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { buildLineContent } from "../line/line_data.js"
import { lineNumberFor } from "../line/utils_line.js"
import { ie, ie_version } from "../util/browser.js"
import { elt } from "../util/dom.js"
import { elt, classTest } from "../util/dom.js"
import { signalLater } from "../util/operation_group.js"

// When an aspect of a line changes, a string is added to
Expand Down Expand Up @@ -124,10 +124,10 @@ function updateLineGutter(cm, lineView, lineN, dims) {

function updateLineWidgets(cm, lineView, dims) {
if (lineView.alignable) lineView.alignable = null
let isWidget = classTest("CodeMirror-linewidget")
for (let node = lineView.node.firstChild, next; node; node = next) {
next = node.nextSibling
if (node.className == "CodeMirror-linewidget")
lineView.node.removeChild(node)
if (isWidget.test(node)) lineView.node.removeChild(node)
}
insertLineWidgets(cm, lineView, dims)
}
Expand Down Expand Up @@ -157,7 +157,7 @@ function insertLineWidgetsFor(cm, line, lineView, dims, allowAbove) {
if (!line.widgets) return
let wrap = ensureLineWrapped(lineView)
for (let i = 0, ws = line.widgets; i < ws.length; ++i) {
let widget = ws[i], node = elt("div", [widget.node], "CodeMirror-linewidget")
let widget = ws[i], node = elt("div", [widget.node], "CodeMirror-linewidget" + (widget.className ? " " + widget.className : ""))
if (!widget.handleMouseEvents) node.setAttribute("cm-ignore-events", "true")
positionLineWidget(widget, node, lineView, dims)
cm.display.input.setUneditable(node)
Expand Down

0 comments on commit ddafba7

Please sign in to comment.