Skip to content
Snippets Groups Projects
Commit cef40890 authored by Marijn Haverbeke's avatar Marijn Haverbeke
Browse files

Remove a few vars that worked around this-binding issue

parent 9ad40ee7
No related branches found
No related tags found
No related merge requests found
......@@ -64,11 +64,9 @@ export function CodeMirror(place, options) {
specialChars: null
}
let cm = this
// Override magic textarea content restore that IE sometimes does
// on our hidden textarea on reload
if (ie && ie_version < 11) setTimeout(() => cm.display.input.reset(true), 20)
if (ie && ie_version < 11) setTimeout(() => this.display.input.reset(true), 20)
registerEventHandlers(this)
ensureGlobalHandlers()
......@@ -77,7 +75,7 @@ export function CodeMirror(place, options) {
this.curOp.forceUpdate = true
attachDoc(this, doc)
if ((options.autofocus && !mobile) || cm.hasFocus())
if ((options.autofocus && !mobile) || this.hasFocus())
setTimeout(bind(onFocus, this), 20)
else
onBlur(this)
......
......@@ -228,11 +228,11 @@ export default function(CodeMirror) {
}),
clearGutter: methodOp(function(gutterID) {
let cm = this, doc = cm.doc, i = doc.first
let doc = this.doc, i = doc.first
doc.iter(line => {
if (line.gutterMarkers && line.gutterMarkers[gutterID]) {
line.gutterMarkers[gutterID] = null
regLineChange(cm, i, "gutter")
regLineChange(this, i, "gutter")
if (isEmpty(line.gutterMarkers)) line.gutterMarkers = null
}
++i
......@@ -315,10 +315,9 @@ export default function(CodeMirror) {
},
moveH: methodOp(function(dir, unit) {
let cm = this
cm.extendSelectionsBy(range => {
if (cm.display.shift || cm.doc.extend || range.empty())
return findPosH(cm.doc, range.head, dir, unit, cm.options.rtlMoveVisually)
this.extendSelectionsBy(range => {
if (this.display.shift || this.doc.extend || range.empty())
return findPosH(this.doc, range.head, dir, unit, this.options.rtlMoveVisually)
else
return dir < 0 ? range.from() : range.to()
}, sel_move)
......@@ -350,17 +349,17 @@ export default function(CodeMirror) {
},
moveV: methodOp(function(dir, unit) {
let cm = this, doc = this.doc, goals = []
let collapse = !cm.display.shift && !doc.extend && doc.sel.somethingSelected()
let doc = this.doc, goals = []
let collapse = !this.display.shift && !doc.extend && doc.sel.somethingSelected()
doc.extendSelectionsBy(range => {
if (collapse)
return dir < 0 ? range.from() : range.to()
let headPos = cursorCoords(cm, range.head, "div")
let headPos = cursorCoords(this, range.head, "div")
if (range.goalColumn != null) headPos.left = range.goalColumn
goals.push(headPos.left)
let pos = findPosV(cm, headPos, dir, unit)
let pos = findPosV(this, headPos, dir, unit)
if (unit == "page" && range == doc.sel.primary())
addToScrollPos(cm, null, charCoords(cm, pos, "div").top - headPos.top)
addToScrollPos(this, null, charCoords(this, pos, "div").top - headPos.top)
return pos
}, sel_move)
if (goals.length) for (let i = 0; i < doc.sel.ranges.length; i++)
......@@ -435,19 +434,18 @@ export default function(CodeMirror) {
}),
setSize: methodOp(function(width, height) {
let cm = this
let interpret = val => typeof val == "number" || /^\d+$/.test(String(val)) ? val + "px" : val
if (width != null) cm.display.wrapper.style.width = interpret(width)
if (height != null) cm.display.wrapper.style.height = interpret(height)
if (cm.options.lineWrapping) clearLineMeasurementCache(this)
let lineNo = cm.display.viewFrom
cm.doc.iter(lineNo, cm.display.viewTo, line => {
if (width != null) this.display.wrapper.style.width = interpret(width)
if (height != null) this.display.wrapper.style.height = interpret(height)
if (this.options.lineWrapping) clearLineMeasurementCache(this)
let lineNo = this.display.viewFrom
this.doc.iter(lineNo, this.display.viewTo, line => {
if (line.widgets) for (let i = 0; i < line.widgets.length; i++)
if (line.widgets[i].noHScroll) { regLineChange(cm, lineNo, "widget"); break }
if (line.widgets[i].noHScroll) { regLineChange(this, lineNo, "widget"); break }
++lineNo
})
cm.curOp.forceUpdate = true
signal(cm, "refresh", this)
this.curOp.forceUpdate = true
signal(this, "refresh", this)
}),
operation: function(f){return runInOp(this, f)},
......
......@@ -169,12 +169,11 @@ ContentEditableInput.prototype = copyObj({
},
startGracePeriod: function() {
let input = this
clearTimeout(this.gracePeriod)
this.gracePeriod = setTimeout(() => {
input.gracePeriod = false
if (input.selectionChanged())
input.cm.operation(() => input.cm.curOp.selectionChanged = true)
this.gracePeriod = false
if (this.selectionChanged())
this.cm.operation(() => this.cm.curOp.selectionChanged = true)
}, 20)
},
......
......@@ -47,7 +47,7 @@ TextareaInput.prototype = copyObj({
if (ios) te.style.width = "0px"
on(te, "input", () => {
if (ie && ie_version >= 9 && input.hasSelection) input.hasSelection = null
if (ie && ie_version >= 9 && this.hasSelection) this.hasSelection = null
input.poll()
})
......@@ -185,11 +185,10 @@ TextareaInput.prototype = copyObj({
// Poll for input changes, using the normal rate of polling. This
// runs as long as the editor is focused.
slowPoll: function() {
let input = this
if (input.pollingFast) return
input.polling.set(this.cm.options.pollInterval, () => {
input.poll()
if (input.cm.state.focused) input.slowPoll()
if (this.pollingFast) return
this.polling.set(this.cm.options.pollInterval, () => {
this.poll()
if (this.cm.state.focused) this.slowPoll()
})
},
......@@ -245,18 +244,17 @@ TextareaInput.prototype = copyObj({
let same = 0, l = Math.min(prevInput.length, text.length)
while (same < l && prevInput.charCodeAt(same) == text.charCodeAt(same)) ++same
let self = this
runInOp(cm, () => {
applyTextInput(cm, text.slice(same), prevInput.length - same,
null, self.composing ? "*compose" : null)
null, this.composing ? "*compose" : null)
// Don't leave long text in the textarea, since it makes further polling slow
if (text.length > 1000 || text.indexOf("\n") > -1) input.value = self.prevInput = ""
else self.prevInput = text
if (text.length > 1000 || text.indexOf("\n") > -1) input.value = this.prevInput = ""
else this.prevInput = text
if (self.composing) {
self.composing.range.clear()
self.composing.range = cm.markText(self.composing.start, cm.getCursor("to"),
if (this.composing) {
this.composing.range.clear()
this.composing.range = cm.markText(this.composing.start, cm.getCursor("to"),
{className: "CodeMirror-composing"})
}
})
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment