Skip to content

Commit 0e54532

Browse files
Todd Bermanmarijnh
authored andcommitted
Move setGutterMarker, clearGutter and lineInfo to Doc
1 parent da8a35d commit 0e54532

File tree

3 files changed

+45
-44
lines changed

3 files changed

+45
-44
lines changed

doc/manual.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1699,7 +1699,7 @@ <h3 id="api_marker">Text-marking methods</h3>
16991699
<h3 id="api_decoration">Widget, gutter, and decoration methods</h3>
17001700

17011701
<dl>
1702-
<dt id="setGutterMarker"><code><strong>cm.setGutterMarker</strong>(line: integer|LineHandle, gutterID: string, value: Element) → LineHandle</code></dt>
1702+
<dt id="setGutterMarker"><code><strong>doc.setGutterMarker</strong>(line: integer|LineHandle, gutterID: string, value: Element) → LineHandle</code></dt>
17031703
<dd>Sets the gutter marker for the given gutter (identified by
17041704
its CSS class, see
17051705
the <a href="#option_gutters"><code>gutters</code></a> option)
@@ -1708,7 +1708,7 @@ <h3 id="api_decoration">Widget, gutter, and decoration methods</h3>
17081708
will be shown in the specified gutter next to the specified
17091709
line.</dd>
17101710

1711-
<dt id="clearGutter"><code><strong>cm.clearGutter</strong>(gutterID: string)</code></dt>
1711+
<dt id="clearGutter"><code><strong>doc.clearGutter</strong>(gutterID: string)</code></dt>
17121712
<dd>Remove all gutter markers in
17131713
the <a href="#option_gutters">gutter</a> with the given ID.</dd>
17141714

@@ -1733,7 +1733,7 @@ <h3 id="api_decoration">Widget, gutter, and decoration methods</h3>
17331733
can be left off to remove all classes for the specified node, or
17341734
be a string to remove only a specific class.</dd>
17351735

1736-
<dt id="lineInfo"><code><strong>cm.lineInfo</strong>(line: integer|LineHandle) → object</code></dt>
1736+
<dt id="lineInfo"><code><strong>doc.lineInfo</strong>(line: integer|LineHandle) → object</code></dt>
17371737
<dd>Returns the line number, text content, and marker status of
17381738
the given line, which can be either a number or a line handle.
17391739
The returned object has the structure <code>{line, handle, text,

src/edit/methods.js

Lines changed: 2 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { deleteNearSelection } from "./deleteNearSelection"
2-
import { changeLine } from "../model/changes"
32
import { commands } from "./commands"
43
import { attachDoc } from "../model/document_data"
54
import { activeElt, addClass, rmClass } from "../util/dom"
@@ -18,9 +17,9 @@ import { addToScrollPos, calculateScrollPos, ensureCursorVisible, resolveScrollT
1817
import { heightAtLine } from "../line/spans"
1918
import { updateGutterSpace } from "../display/update_display"
2019
import { lineLeft, lineRight, moveLogically, moveVisually } from "../util/bidi"
21-
import { indexOf, insertSorted, isEmpty, isWordChar, sel_dontScroll, sel_move } from "../util/misc"
20+
import { indexOf, insertSorted, isWordChar, sel_dontScroll, sel_move } from "../util/misc"
2221
import { signalLater } from "../util/operation_group"
23-
import { getLine, isLine, lineAtHeight, lineNo } from "../line/utils_line"
22+
import { getLine, isLine, lineAtHeight } from "../line/utils_line"
2423
import { regChange, regLineChange } from "../display/view_tracking"
2524

2625
// The publicly visible API. Note that methodOp(f) means
@@ -218,43 +217,6 @@ export default function(CodeMirror) {
218217
defaultTextHeight: function() { return textHeight(this.display) },
219218
defaultCharWidth: function() { return charWidth(this.display) },
220219

221-
setGutterMarker: methodOp(function(line, gutterID, value) {
222-
return changeLine(this.doc, line, "gutter", line => {
223-
let markers = line.gutterMarkers || (line.gutterMarkers = {})
224-
markers[gutterID] = value
225-
if (!value && isEmpty(markers)) line.gutterMarkers = null
226-
return true
227-
})
228-
}),
229-
230-
clearGutter: methodOp(function(gutterID) {
231-
let doc = this.doc, i = doc.first
232-
doc.iter(line => {
233-
if (line.gutterMarkers && line.gutterMarkers[gutterID]) {
234-
line.gutterMarkers[gutterID] = null
235-
regLineChange(this, i, "gutter")
236-
if (isEmpty(line.gutterMarkers)) line.gutterMarkers = null
237-
}
238-
++i
239-
})
240-
}),
241-
242-
lineInfo: function(line) {
243-
let n
244-
if (typeof line == "number") {
245-
if (!isLine(this.doc, line)) return null
246-
n = line
247-
line = getLine(this.doc, line)
248-
if (!line) return null
249-
} else {
250-
n = lineNo(line)
251-
if (n == null) return null
252-
}
253-
return {line: n, handle: line, text: line.text, gutterMarkers: line.gutterMarkers,
254-
textClass: line.textClass, bgClass: line.bgClass, wrapClass: line.wrapClass,
255-
widgets: line.widgets}
256-
},
257-
258220
getViewport: function() { return {from: this.display.viewFrom, to: this.display.viewTo}},
259221

260222
addWidget: function(pos, node, scroll, vert, horiz) {

src/model/Doc.js

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { visualLine } from "../line/spans"
66
import { getBetween, getLine, getLines, isLine, lineNo } from "../line/utils_line"
77
import { classTest } from "../util/dom"
88
import { splitLinesAuto } from "../util/feature_detection"
9-
import { createObj, map, sel_dontScroll } from "../util/misc"
9+
import { createObj, map, isEmpty, sel_dontScroll } from "../util/misc"
1010
import { ensureCursorVisible } from "../display/scrolling"
1111

1212
import { changeLine, makeChange, makeChangeFromHistory, replaceRange } from "./changes"
@@ -219,6 +219,45 @@ Doc.prototype = createObj(BranchChunk.prototype, {
219219
hist.undone = copyHistoryArray(histData.undone.slice(0), null, true)
220220
},
221221

222+
setGutterMarker: docMethodOp(function(line, gutterID, value) {
223+
return changeLine(this, line, "gutter", line => {
224+
let markers = line.gutterMarkers || (line.gutterMarkers = {})
225+
markers[gutterID] = value
226+
if (!value && isEmpty(markers)) line.gutterMarkers = null
227+
return true
228+
})
229+
}),
230+
231+
clearGutter: docMethodOp(function(gutterID) {
232+
let i = this.first
233+
this.iter(line => {
234+
if (line.gutterMarkers && line.gutterMarkers[gutterID]) {
235+
changeLine(this, line, "gutter", () => {
236+
line.gutterMarkers[gutterID] = null
237+
if (isEmpty(line.gutterMarkers)) line.gutterMarkers = null
238+
return true
239+
})
240+
}
241+
++i
242+
})
243+
}),
244+
245+
lineInfo: function(line) {
246+
let n
247+
if (typeof line == "number") {
248+
if (!isLine(this, line)) return null
249+
n = line
250+
line = getLine(this, line)
251+
if (!line) return null
252+
} else {
253+
n = lineNo(line)
254+
if (n == null) return null
255+
}
256+
return {line: n, handle: line, text: line.text, gutterMarkers: line.gutterMarkers,
257+
textClass: line.textClass, bgClass: line.bgClass, wrapClass: line.wrapClass,
258+
widgets: line.widgets}
259+
},
260+
222261
addLineClass: docMethodOp(function(handle, where, cls) {
223262
return changeLine(this, handle, where == "gutter" ? "gutter" : "class", line => {
224263
let prop = where == "text" ? "textClass"

0 commit comments

Comments
 (0)