Skip to content

Commit 9ad40ee

Browse files
adrianheinemarijnh
authored andcommitted
Convert anonymous to arrow functions
1 parent 6992c53 commit 9ad40ee

35 files changed

+305
-355
lines changed

src/display/focus.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,10 @@ export function ensureFocus(cm) {
99

1010
export function delayBlurEvent(cm) {
1111
cm.state.delayingBlurEvent = true
12-
setTimeout(function() {
13-
if (cm.state.delayingBlurEvent) {
14-
cm.state.delayingBlurEvent = false
15-
onBlur(cm)
16-
}
17-
}, 100)
12+
setTimeout(() => { if (cm.state.delayingBlurEvent) {
13+
cm.state.delayingBlurEvent = false
14+
onBlur(cm)
15+
} }, 100)
1816
}
1917

2018
export function onFocus(cm, e) {
@@ -30,7 +28,7 @@ export function onFocus(cm, e) {
3028
// select-all detection hack)
3129
if (!cm.curOp && cm.display.selForContextMenu != cm.doc.sel) {
3230
cm.display.input.reset()
33-
if (webkit) setTimeout(function() { cm.display.input.reset(true) }, 20) // Issue #1730
31+
if (webkit) setTimeout(() => cm.display.input.reset(true), 20) // Issue #1730
3432
}
3533
cm.display.input.receivedFocus()
3634
}
@@ -45,5 +43,5 @@ export function onBlur(cm, e) {
4543
rmClass(cm.display.wrapper, "CodeMirror-focused")
4644
}
4745
clearInterval(cm.display.blinker)
48-
setTimeout(function() {if (!cm.state.focused) cm.display.shift = false}, 150)
46+
setTimeout(() => { if (!cm.state.focused) cm.display.shift = false }, 150)
4947
}

src/display/highlight_worker.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ function highlightWorker(cm) {
2020
let state = copyState(doc.mode, getStateBefore(cm, doc.frontier))
2121
let changedLines = []
2222

23-
doc.iter(doc.frontier, Math.min(doc.first + doc.size, cm.display.viewTo + 500), function(line) {
23+
doc.iter(doc.frontier, Math.min(doc.first + doc.size, cm.display.viewTo + 500), line => {
2424
if (doc.frontier >= cm.display.viewFrom) { // Visible
2525
let oldStyles = line.styles, tooLong = line.text.length > cm.options.maxHighlightLength
2626
let highlighted = highlightLine(cm, line, tooLong ? copyState(doc.mode, state) : state, true)
@@ -44,7 +44,7 @@ function highlightWorker(cm) {
4444
return true
4545
}
4646
})
47-
if (changedLines.length) runInOp(cm, function() {
47+
if (changedLines.length) runInOp(cm, () => {
4848
for (let i = 0; i < changedLines.length; i++)
4949
regLineChange(cm, changedLines[i], "text")
5050
})

src/display/mode_state.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export function loadMode(cm) {
1111
}
1212

1313
export function resetModeState(cm) {
14-
cm.doc.iter(function(line) {
14+
cm.doc.iter(line => {
1515
if (line.stateAfter) line.stateAfter = null
1616
if (line.styles) line.styles = null
1717
})

src/display/operations.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export function startOperation(cm) {
4646
// Finish an operation, updating the display and signalling delayed events
4747
export function endOperation(cm) {
4848
let op = cm.curOp
49-
finishOperation(op, function(group) {
49+
finishOperation(op, group => {
5050
for (let i = 0; i < group.ops.length; i++)
5151
group.ops[i].cm.curOp = null
5252
endOperations(group)

src/display/scroll_events.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ else if (gecko) wheelPixelsPerUnit = 15
4848
else if (chrome) wheelPixelsPerUnit = -.7
4949
else if (safari) wheelPixelsPerUnit = -1/3
5050

51-
let wheelEventDelta = function(e) {
51+
function wheelEventDelta(e) {
5252
let dx = e.wheelDeltaX, dy = e.wheelDeltaY
5353
if (dx == null && e.detail && e.axis == e.HORIZONTAL_AXIS) dx = e.detail
5454
if (dy == null && e.detail && e.axis == e.VERTICAL_AXIS) dy = e.detail
@@ -120,7 +120,7 @@ export function onScrollWheel(cm, e) {
120120
if (display.wheelStartX == null) {
121121
display.wheelStartX = scroll.scrollLeft; display.wheelStartY = scroll.scrollTop
122122
display.wheelDX = dx; display.wheelDY = dy
123-
setTimeout(function() {
123+
setTimeout(() => {
124124
if (display.wheelStartX == null) return
125125
let movedX = scroll.scrollLeft - display.wheelStartX
126126
let movedY = scroll.scrollTop - display.wheelStartY

src/display/scrollbars.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ function NativeScrollbars(place, scroll, cm) {
3333
let horiz = this.horiz = elt("div", [elt("div", null, null, "height: 100%; min-height: 1px")], "CodeMirror-hscrollbar")
3434
place(vert); place(horiz)
3535

36-
on(vert, "scroll", function() {
36+
on(vert, "scroll", () => {
3737
if (vert.clientHeight) scroll(vert.scrollTop, "vertical")
3838
})
39-
on(horiz, "scroll", function() {
39+
on(horiz, "scroll", () => {
4040
if (horiz.clientWidth) scroll(horiz.scrollLeft, "horizontal")
4141
})
4242

@@ -172,14 +172,14 @@ export function initScrollbars(cm) {
172172
rmClass(cm.display.wrapper, cm.display.scrollbars.addClass)
173173
}
174174

175-
cm.display.scrollbars = new scrollbarModel[cm.options.scrollbarStyle](function(node) {
175+
cm.display.scrollbars = new scrollbarModel[cm.options.scrollbarStyle](node => {
176176
cm.display.wrapper.insertBefore(node, cm.display.scrollbarFiller)
177177
// Prevent clicks in the scrollbars from killing focus
178-
on(node, "mousedown", function() {
179-
if (cm.state.focused) setTimeout(function() { cm.display.input.focus() }, 0)
178+
on(node, "mousedown", () => {
179+
if (cm.state.focused) setTimeout(() => cm.display.input.focus(), 0)
180180
})
181181
node.setAttribute("cm-not-content", "true")
182-
}, function(pos, axis) {
182+
}, (pos, axis) => {
183183
if (axis == "horizontal") setScrollLeft(cm, pos)
184184
else setScrollTop(cm, pos)
185185
}, cm)

src/display/selection.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ function drawSelectionRange(cm, range, output) {
7070
return charCoords(cm, Pos(line, ch), "div", lineObj, bias)
7171
}
7272

73-
iterateBidiSections(getOrder(lineObj), fromArg || 0, toArg == null ? lineLen : toArg, function(from, to, dir) {
73+
iterateBidiSections(getOrder(lineObj), fromArg || 0, toArg == null ? lineLen : toArg, (from, to, dir) => {
7474
let leftPos = coords(from, "left"), rightPos, left, right
7575
if (from == to) {
7676
rightPos = leftPos
@@ -129,9 +129,8 @@ export function restartBlink(cm) {
129129
let on = true
130130
display.cursorDiv.style.visibility = ""
131131
if (cm.options.cursorBlinkRate > 0)
132-
display.blinker = setInterval(function() {
133-
display.cursorDiv.style.visibility = (on = !on) ? "" : "hidden"
134-
}, cm.options.cursorBlinkRate)
132+
display.blinker = setInterval(() => display.cursorDiv.style.visibility = (on = !on) ? "" : "hidden",
133+
cm.options.cursorBlinkRate)
135134
else if (cm.options.cursorBlinkRate < 0)
136135
display.cursorDiv.style.visibility = "hidden"
137136
}

src/edit/CodeMirror.js

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ export function CodeMirror(place, options) {
6868

6969
// Override magic textarea content restore that IE sometimes does
7070
// on our hidden textarea on reload
71-
if (ie && ie_version < 11) setTimeout(function() { cm.display.input.reset(true) }, 20)
71+
if (ie && ie_version < 11) setTimeout(() => cm.display.input.reset(true), 20)
7272

7373
registerEventHandlers(this)
7474
ensureGlobalHandlers()
@@ -108,7 +108,7 @@ function registerEventHandlers(cm) {
108108
on(d.scroller, "mousedown", operation(cm, onMouseDown))
109109
// Older IE's will not fire a second mousedown for a double click
110110
if (ie && ie_version < 11)
111-
on(d.scroller, "dblclick", operation(cm, function(e) {
111+
on(d.scroller, "dblclick", operation(cm, e => {
112112
if (signalDOMEvent(cm, e)) return
113113
let pos = posFromMouse(cm, e)
114114
if (!pos || clickInGutter(cm, e) || eventInWidget(cm.display, e)) return
@@ -117,17 +117,17 @@ function registerEventHandlers(cm) {
117117
extendSelection(cm.doc, word.anchor, word.head)
118118
}))
119119
else
120-
on(d.scroller, "dblclick", function(e) { signalDOMEvent(cm, e) || e_preventDefault(e) })
120+
on(d.scroller, "dblclick", e => signalDOMEvent(cm, e) || e_preventDefault(e))
121121
// Some browsers fire contextmenu *after* opening the menu, at
122122
// which point we can't mess with it anymore. Context menu is
123123
// handled in onMouseDown for these browsers.
124-
if (!captureRightClick) on(d.scroller, "contextmenu", function(e) {onContextMenu(cm, e)})
124+
if (!captureRightClick) on(d.scroller, "contextmenu", e => onContextMenu(cm, e))
125125

126126
// Used to suppress mouse event handling when a touch happens
127127
let touchFinished, prevTouch = {end: 0}
128128
function finishTouch() {
129129
if (d.activeTouch) {
130-
touchFinished = setTimeout(function() {d.activeTouch = null}, 1000)
130+
touchFinished = setTimeout(() => d.activeTouch = null, 1000)
131131
prevTouch = d.activeTouch
132132
prevTouch.end = +new Date
133133
}
@@ -142,7 +142,7 @@ function registerEventHandlers(cm) {
142142
let dx = other.left - touch.left, dy = other.top - touch.top
143143
return dx * dx + dy * dy > 20 * 20
144144
}
145-
on(d.scroller, "touchstart", function(e) {
145+
on(d.scroller, "touchstart", e => {
146146
if (!signalDOMEvent(cm, e) && !isMouseLikeTouchEvent(e)) {
147147
clearTimeout(touchFinished)
148148
let now = +new Date
@@ -154,10 +154,10 @@ function registerEventHandlers(cm) {
154154
}
155155
}
156156
})
157-
on(d.scroller, "touchmove", function() {
157+
on(d.scroller, "touchmove", () => {
158158
if (d.activeTouch) d.activeTouch.moved = true
159159
})
160-
on(d.scroller, "touchend", function(e) {
160+
on(d.scroller, "touchend", e => {
161161
let touch = d.activeTouch
162162
if (touch && !eventInWidget(d, e) && touch.left != null &&
163163
!touch.moved && new Date - touch.start < 300) {
@@ -178,7 +178,7 @@ function registerEventHandlers(cm) {
178178

179179
// Sync scrolling between fake scrollbars and real scrollable
180180
// area, ensure viewport is updated when scrolling.
181-
on(d.scroller, "scroll", function() {
181+
on(d.scroller, "scroll", () => {
182182
if (d.scroller.clientHeight) {
183183
setScrollTop(cm, d.scroller.scrollTop)
184184
setScrollLeft(cm, d.scroller.scrollLeft, true)
@@ -187,27 +187,27 @@ function registerEventHandlers(cm) {
187187
})
188188

189189
// Listen to wheel events in order to try and update the viewport on time.
190-
on(d.scroller, "mousewheel", function(e){onScrollWheel(cm, e)})
191-
on(d.scroller, "DOMMouseScroll", function(e){onScrollWheel(cm, e)})
190+
on(d.scroller, "mousewheel", e => onScrollWheel(cm, e))
191+
on(d.scroller, "DOMMouseScroll", e => onScrollWheel(cm, e))
192192

193193
// Prevent wrapper from ever scrolling
194-
on(d.wrapper, "scroll", function() { d.wrapper.scrollTop = d.wrapper.scrollLeft = 0 })
194+
on(d.wrapper, "scroll", () => d.wrapper.scrollTop = d.wrapper.scrollLeft = 0)
195195

196196
d.dragFunctions = {
197-
enter: function(e) {if (!signalDOMEvent(cm, e)) e_stop(e)},
198-
over: function(e) {if (!signalDOMEvent(cm, e)) { onDragOver(cm, e); e_stop(e) }},
199-
start: function(e){onDragStart(cm, e)},
197+
enter: e => {if (!signalDOMEvent(cm, e)) e_stop(e)},
198+
over: e => {if (!signalDOMEvent(cm, e)) { onDragOver(cm, e); e_stop(e) }},
199+
start: e => onDragStart(cm, e),
200200
drop: operation(cm, onDrop),
201-
leave: function(e) {if (!signalDOMEvent(cm, e)) { clearDragCursor(cm) }}
201+
leave: e => {if (!signalDOMEvent(cm, e)) { clearDragCursor(cm) }}
202202
}
203203

204204
let inp = d.input.getField()
205-
on(inp, "keyup", function(e) { onKeyUp.call(cm, e) })
205+
on(inp, "keyup", e => onKeyUp.call(cm, e))
206206
on(inp, "keydown", operation(cm, onKeyDown))
207207
on(inp, "keypress", operation(cm, onKeyPress))
208-
on(inp, "focus", function(e) { onFocus(cm, e) })
209-
on(inp, "blur", function (e) { onBlur(cm, e) })
208+
on(inp, "focus", e => onFocus(cm, e))
209+
on(inp, "blur", e => onBlur(cm, e))
210210
}
211211

212212
let initHooks = []
213-
CodeMirror.defineInitHook = function(f) {initHooks.push(f)}
213+
CodeMirror.defineInitHook = f => initHooks.push(f)

0 commit comments

Comments
 (0)