Skip to content

Commit ddafba7

Browse files
committed
Add a className option to addLineWidget
Issue #5952
1 parent 1c4b922 commit ddafba7

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

doc/manual.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1881,6 +1881,9 @@ <h3 id="api_decoration">Widget, gutter, and decoration methods</h3>
18811881
position (zero for the top, N to put it after the Nth other
18821882
widget). Note that this only has effect once, when the
18831883
widget is created.
1884+
<dt><code><strong>className</strong>: string</code></dt>
1885+
<dd>Add an extra CSS class name to the wrapper element
1886+
created for the widget.</dd>
18841887
</dl>
18851888
Note that the widget node will become a descendant of nodes with
18861889
CodeMirror-specific CSS classes, and those classes might in some

src/display/update_line.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { buildLineContent } from "../line/line_data.js"
22
import { lineNumberFor } from "../line/utils_line.js"
33
import { ie, ie_version } from "../util/browser.js"
4-
import { elt } from "../util/dom.js"
4+
import { elt, classTest } from "../util/dom.js"
55
import { signalLater } from "../util/operation_group.js"
66

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

125125
function updateLineWidgets(cm, lineView, dims) {
126126
if (lineView.alignable) lineView.alignable = null
127+
let isWidget = classTest("CodeMirror-linewidget")
127128
for (let node = lineView.node.firstChild, next; node; node = next) {
128129
next = node.nextSibling
129-
if (node.className == "CodeMirror-linewidget")
130-
lineView.node.removeChild(node)
130+
if (isWidget.test(node)) lineView.node.removeChild(node)
131131
}
132132
insertLineWidgets(cm, lineView, dims)
133133
}
@@ -157,7 +157,7 @@ function insertLineWidgetsFor(cm, line, lineView, dims, allowAbove) {
157157
if (!line.widgets) return
158158
let wrap = ensureLineWrapped(lineView)
159159
for (let i = 0, ws = line.widgets; i < ws.length; ++i) {
160-
let widget = ws[i], node = elt("div", [widget.node], "CodeMirror-linewidget")
160+
let widget = ws[i], node = elt("div", [widget.node], "CodeMirror-linewidget" + (widget.className ? " " + widget.className : ""))
161161
if (!widget.handleMouseEvents) node.setAttribute("cm-ignore-events", "true")
162162
positionLineWidget(widget, node, lineView, dims)
163163
cm.display.input.setUneditable(node)

0 commit comments

Comments
 (0)