Skip to content

Commit cef4089

Browse files
committed
Remove a few vars that worked around this-binding issue
1 parent 9ad40ee commit cef4089

File tree

4 files changed

+34
-41
lines changed

4 files changed

+34
-41
lines changed

src/edit/CodeMirror.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,9 @@ export function CodeMirror(place, options) {
6464
specialChars: null
6565
}
6666

67-
let cm = this
68-
6967
// Override magic textarea content restore that IE sometimes does
7068
// on our hidden textarea on reload
71-
if (ie && ie_version < 11) setTimeout(() => cm.display.input.reset(true), 20)
69+
if (ie && ie_version < 11) setTimeout(() => this.display.input.reset(true), 20)
7270

7371
registerEventHandlers(this)
7472
ensureGlobalHandlers()
@@ -77,7 +75,7 @@ export function CodeMirror(place, options) {
7775
this.curOp.forceUpdate = true
7876
attachDoc(this, doc)
7977

80-
if ((options.autofocus && !mobile) || cm.hasFocus())
78+
if ((options.autofocus && !mobile) || this.hasFocus())
8179
setTimeout(bind(onFocus, this), 20)
8280
else
8381
onBlur(this)

src/edit/methods.js

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -228,11 +228,11 @@ export default function(CodeMirror) {
228228
}),
229229

230230
clearGutter: methodOp(function(gutterID) {
231-
let cm = this, doc = cm.doc, i = doc.first
231+
let doc = this.doc, i = doc.first
232232
doc.iter(line => {
233233
if (line.gutterMarkers && line.gutterMarkers[gutterID]) {
234234
line.gutterMarkers[gutterID] = null
235-
regLineChange(cm, i, "gutter")
235+
regLineChange(this, i, "gutter")
236236
if (isEmpty(line.gutterMarkers)) line.gutterMarkers = null
237237
}
238238
++i
@@ -315,10 +315,9 @@ export default function(CodeMirror) {
315315
},
316316

317317
moveH: methodOp(function(dir, unit) {
318-
let cm = this
319-
cm.extendSelectionsBy(range => {
320-
if (cm.display.shift || cm.doc.extend || range.empty())
321-
return findPosH(cm.doc, range.head, dir, unit, cm.options.rtlMoveVisually)
318+
this.extendSelectionsBy(range => {
319+
if (this.display.shift || this.doc.extend || range.empty())
320+
return findPosH(this.doc, range.head, dir, unit, this.options.rtlMoveVisually)
322321
else
323322
return dir < 0 ? range.from() : range.to()
324323
}, sel_move)
@@ -350,17 +349,17 @@ export default function(CodeMirror) {
350349
},
351350

352351
moveV: methodOp(function(dir, unit) {
353-
let cm = this, doc = this.doc, goals = []
354-
let collapse = !cm.display.shift && !doc.extend && doc.sel.somethingSelected()
352+
let doc = this.doc, goals = []
353+
let collapse = !this.display.shift && !doc.extend && doc.sel.somethingSelected()
355354
doc.extendSelectionsBy(range => {
356355
if (collapse)
357356
return dir < 0 ? range.from() : range.to()
358-
let headPos = cursorCoords(cm, range.head, "div")
357+
let headPos = cursorCoords(this, range.head, "div")
359358
if (range.goalColumn != null) headPos.left = range.goalColumn
360359
goals.push(headPos.left)
361-
let pos = findPosV(cm, headPos, dir, unit)
360+
let pos = findPosV(this, headPos, dir, unit)
362361
if (unit == "page" && range == doc.sel.primary())
363-
addToScrollPos(cm, null, charCoords(cm, pos, "div").top - headPos.top)
362+
addToScrollPos(this, null, charCoords(this, pos, "div").top - headPos.top)
364363
return pos
365364
}, sel_move)
366365
if (goals.length) for (let i = 0; i < doc.sel.ranges.length; i++)
@@ -435,19 +434,18 @@ export default function(CodeMirror) {
435434
}),
436435

437436
setSize: methodOp(function(width, height) {
438-
let cm = this
439437
let interpret = val => typeof val == "number" || /^\d+$/.test(String(val)) ? val + "px" : val
440-
if (width != null) cm.display.wrapper.style.width = interpret(width)
441-
if (height != null) cm.display.wrapper.style.height = interpret(height)
442-
if (cm.options.lineWrapping) clearLineMeasurementCache(this)
443-
let lineNo = cm.display.viewFrom
444-
cm.doc.iter(lineNo, cm.display.viewTo, line => {
438+
if (width != null) this.display.wrapper.style.width = interpret(width)
439+
if (height != null) this.display.wrapper.style.height = interpret(height)
440+
if (this.options.lineWrapping) clearLineMeasurementCache(this)
441+
let lineNo = this.display.viewFrom
442+
this.doc.iter(lineNo, this.display.viewTo, line => {
445443
if (line.widgets) for (let i = 0; i < line.widgets.length; i++)
446-
if (line.widgets[i].noHScroll) { regLineChange(cm, lineNo, "widget"); break }
444+
if (line.widgets[i].noHScroll) { regLineChange(this, lineNo, "widget"); break }
447445
++lineNo
448446
})
449-
cm.curOp.forceUpdate = true
450-
signal(cm, "refresh", this)
447+
this.curOp.forceUpdate = true
448+
signal(this, "refresh", this)
451449
}),
452450

453451
operation: function(f){return runInOp(this, f)},

src/input/ContentEditableInput.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -169,12 +169,11 @@ ContentEditableInput.prototype = copyObj({
169169
},
170170

171171
startGracePeriod: function() {
172-
let input = this
173172
clearTimeout(this.gracePeriod)
174173
this.gracePeriod = setTimeout(() => {
175-
input.gracePeriod = false
176-
if (input.selectionChanged())
177-
input.cm.operation(() => input.cm.curOp.selectionChanged = true)
174+
this.gracePeriod = false
175+
if (this.selectionChanged())
176+
this.cm.operation(() => this.cm.curOp.selectionChanged = true)
178177
}, 20)
179178
},
180179

src/input/TextareaInput.js

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ TextareaInput.prototype = copyObj({
4747
if (ios) te.style.width = "0px"
4848

4949
on(te, "input", () => {
50-
if (ie && ie_version >= 9 && input.hasSelection) input.hasSelection = null
50+
if (ie && ie_version >= 9 && this.hasSelection) this.hasSelection = null
5151
input.poll()
5252
})
5353

@@ -185,11 +185,10 @@ TextareaInput.prototype = copyObj({
185185
// Poll for input changes, using the normal rate of polling. This
186186
// runs as long as the editor is focused.
187187
slowPoll: function() {
188-
let input = this
189-
if (input.pollingFast) return
190-
input.polling.set(this.cm.options.pollInterval, () => {
191-
input.poll()
192-
if (input.cm.state.focused) input.slowPoll()
188+
if (this.pollingFast) return
189+
this.polling.set(this.cm.options.pollInterval, () => {
190+
this.poll()
191+
if (this.cm.state.focused) this.slowPoll()
193192
})
194193
},
195194

@@ -245,18 +244,17 @@ TextareaInput.prototype = copyObj({
245244
let same = 0, l = Math.min(prevInput.length, text.length)
246245
while (same < l && prevInput.charCodeAt(same) == text.charCodeAt(same)) ++same
247246

248-
let self = this
249247
runInOp(cm, () => {
250248
applyTextInput(cm, text.slice(same), prevInput.length - same,
251-
null, self.composing ? "*compose" : null)
249+
null, this.composing ? "*compose" : null)
252250

253251
// Don't leave long text in the textarea, since it makes further polling slow
254-
if (text.length > 1000 || text.indexOf("\n") > -1) input.value = self.prevInput = ""
255-
else self.prevInput = text
252+
if (text.length > 1000 || text.indexOf("\n") > -1) input.value = this.prevInput = ""
253+
else this.prevInput = text
256254

257-
if (self.composing) {
258-
self.composing.range.clear()
259-
self.composing.range = cm.markText(self.composing.start, cm.getCursor("to"),
255+
if (this.composing) {
256+
this.composing.range.clear()
257+
this.composing.range = cm.markText(this.composing.start, cm.getCursor("to"),
260258
{className: "CodeMirror-composing"})
261259
}
262260
})

0 commit comments

Comments
 (0)