Skip to content
Snippets Groups Projects
Commit 9ad40ee7 authored by Adrian Heine's avatar Adrian Heine Committed by Marijn Haverbeke
Browse files

Convert anonymous to arrow functions

parent 6992c534
No related branches found
No related tags found
No related merge requests found
Showing
with 245 additions and 292 deletions
......@@ -9,12 +9,10 @@ export function ensureFocus(cm) {
export function delayBlurEvent(cm) {
cm.state.delayingBlurEvent = true
setTimeout(function() {
if (cm.state.delayingBlurEvent) {
cm.state.delayingBlurEvent = false
onBlur(cm)
}
}, 100)
setTimeout(() => { if (cm.state.delayingBlurEvent) {
cm.state.delayingBlurEvent = false
onBlur(cm)
} }, 100)
}
export function onFocus(cm, e) {
......@@ -30,7 +28,7 @@ export function onFocus(cm, e) {
// select-all detection hack)
if (!cm.curOp && cm.display.selForContextMenu != cm.doc.sel) {
cm.display.input.reset()
if (webkit) setTimeout(function() { cm.display.input.reset(true) }, 20) // Issue #1730
if (webkit) setTimeout(() => cm.display.input.reset(true), 20) // Issue #1730
}
cm.display.input.receivedFocus()
}
......@@ -45,5 +43,5 @@ export function onBlur(cm, e) {
rmClass(cm.display.wrapper, "CodeMirror-focused")
}
clearInterval(cm.display.blinker)
setTimeout(function() {if (!cm.state.focused) cm.display.shift = false}, 150)
setTimeout(() => { if (!cm.state.focused) cm.display.shift = false }, 150)
}
......@@ -20,7 +20,7 @@ function highlightWorker(cm) {
let state = copyState(doc.mode, getStateBefore(cm, doc.frontier))
let changedLines = []
doc.iter(doc.frontier, Math.min(doc.first + doc.size, cm.display.viewTo + 500), function(line) {
doc.iter(doc.frontier, Math.min(doc.first + doc.size, cm.display.viewTo + 500), line => {
if (doc.frontier >= cm.display.viewFrom) { // Visible
let oldStyles = line.styles, tooLong = line.text.length > cm.options.maxHighlightLength
let highlighted = highlightLine(cm, line, tooLong ? copyState(doc.mode, state) : state, true)
......@@ -44,7 +44,7 @@ function highlightWorker(cm) {
return true
}
})
if (changedLines.length) runInOp(cm, function() {
if (changedLines.length) runInOp(cm, () => {
for (let i = 0; i < changedLines.length; i++)
regLineChange(cm, changedLines[i], "text")
})
......
......@@ -11,7 +11,7 @@ export function loadMode(cm) {
}
export function resetModeState(cm) {
cm.doc.iter(function(line) {
cm.doc.iter(line => {
if (line.stateAfter) line.stateAfter = null
if (line.styles) line.styles = null
})
......
......@@ -46,7 +46,7 @@ export function startOperation(cm) {
// Finish an operation, updating the display and signalling delayed events
export function endOperation(cm) {
let op = cm.curOp
finishOperation(op, function(group) {
finishOperation(op, group => {
for (let i = 0; i < group.ops.length; i++)
group.ops[i].cm.curOp = null
endOperations(group)
......
......@@ -48,7 +48,7 @@ else if (gecko) wheelPixelsPerUnit = 15
else if (chrome) wheelPixelsPerUnit = -.7
else if (safari) wheelPixelsPerUnit = -1/3
let wheelEventDelta = function(e) {
function wheelEventDelta(e) {
let dx = e.wheelDeltaX, dy = e.wheelDeltaY
if (dx == null && e.detail && e.axis == e.HORIZONTAL_AXIS) dx = e.detail
if (dy == null && e.detail && e.axis == e.VERTICAL_AXIS) dy = e.detail
......@@ -120,7 +120,7 @@ export function onScrollWheel(cm, e) {
if (display.wheelStartX == null) {
display.wheelStartX = scroll.scrollLeft; display.wheelStartY = scroll.scrollTop
display.wheelDX = dx; display.wheelDY = dy
setTimeout(function() {
setTimeout(() => {
if (display.wheelStartX == null) return
let movedX = scroll.scrollLeft - display.wheelStartX
let movedY = scroll.scrollTop - display.wheelStartY
......
......@@ -33,10 +33,10 @@ function NativeScrollbars(place, scroll, cm) {
let horiz = this.horiz = elt("div", [elt("div", null, null, "height: 100%; min-height: 1px")], "CodeMirror-hscrollbar")
place(vert); place(horiz)
on(vert, "scroll", function() {
on(vert, "scroll", () => {
if (vert.clientHeight) scroll(vert.scrollTop, "vertical")
})
on(horiz, "scroll", function() {
on(horiz, "scroll", () => {
if (horiz.clientWidth) scroll(horiz.scrollLeft, "horizontal")
})
......@@ -172,14 +172,14 @@ export function initScrollbars(cm) {
rmClass(cm.display.wrapper, cm.display.scrollbars.addClass)
}
cm.display.scrollbars = new scrollbarModel[cm.options.scrollbarStyle](function(node) {
cm.display.scrollbars = new scrollbarModel[cm.options.scrollbarStyle](node => {
cm.display.wrapper.insertBefore(node, cm.display.scrollbarFiller)
// Prevent clicks in the scrollbars from killing focus
on(node, "mousedown", function() {
if (cm.state.focused) setTimeout(function() { cm.display.input.focus() }, 0)
on(node, "mousedown", () => {
if (cm.state.focused) setTimeout(() => cm.display.input.focus(), 0)
})
node.setAttribute("cm-not-content", "true")
}, function(pos, axis) {
}, (pos, axis) => {
if (axis == "horizontal") setScrollLeft(cm, pos)
else setScrollTop(cm, pos)
}, cm)
......
......@@ -70,7 +70,7 @@ function drawSelectionRange(cm, range, output) {
return charCoords(cm, Pos(line, ch), "div", lineObj, bias)
}
iterateBidiSections(getOrder(lineObj), fromArg || 0, toArg == null ? lineLen : toArg, function(from, to, dir) {
iterateBidiSections(getOrder(lineObj), fromArg || 0, toArg == null ? lineLen : toArg, (from, to, dir) => {
let leftPos = coords(from, "left"), rightPos, left, right
if (from == to) {
rightPos = leftPos
......@@ -129,9 +129,8 @@ export function restartBlink(cm) {
let on = true
display.cursorDiv.style.visibility = ""
if (cm.options.cursorBlinkRate > 0)
display.blinker = setInterval(function() {
display.cursorDiv.style.visibility = (on = !on) ? "" : "hidden"
}, cm.options.cursorBlinkRate)
display.blinker = setInterval(() => display.cursorDiv.style.visibility = (on = !on) ? "" : "hidden",
cm.options.cursorBlinkRate)
else if (cm.options.cursorBlinkRate < 0)
display.cursorDiv.style.visibility = "hidden"
}
......@@ -68,7 +68,7 @@ export function CodeMirror(place, options) {
// Override magic textarea content restore that IE sometimes does
// on our hidden textarea on reload
if (ie && ie_version < 11) setTimeout(function() { cm.display.input.reset(true) }, 20)
if (ie && ie_version < 11) setTimeout(() => cm.display.input.reset(true), 20)
registerEventHandlers(this)
ensureGlobalHandlers()
......@@ -108,7 +108,7 @@ function registerEventHandlers(cm) {
on(d.scroller, "mousedown", operation(cm, onMouseDown))
// Older IE's will not fire a second mousedown for a double click
if (ie && ie_version < 11)
on(d.scroller, "dblclick", operation(cm, function(e) {
on(d.scroller, "dblclick", operation(cm, e => {
if (signalDOMEvent(cm, e)) return
let pos = posFromMouse(cm, e)
if (!pos || clickInGutter(cm, e) || eventInWidget(cm.display, e)) return
......@@ -117,17 +117,17 @@ function registerEventHandlers(cm) {
extendSelection(cm.doc, word.anchor, word.head)
}))
else
on(d.scroller, "dblclick", function(e) { signalDOMEvent(cm, e) || e_preventDefault(e) })
on(d.scroller, "dblclick", e => signalDOMEvent(cm, e) || e_preventDefault(e))
// Some browsers fire contextmenu *after* opening the menu, at
// which point we can't mess with it anymore. Context menu is
// handled in onMouseDown for these browsers.
if (!captureRightClick) on(d.scroller, "contextmenu", function(e) {onContextMenu(cm, e)})
if (!captureRightClick) on(d.scroller, "contextmenu", e => onContextMenu(cm, e))
// Used to suppress mouse event handling when a touch happens
let touchFinished, prevTouch = {end: 0}
function finishTouch() {
if (d.activeTouch) {
touchFinished = setTimeout(function() {d.activeTouch = null}, 1000)
touchFinished = setTimeout(() => d.activeTouch = null, 1000)
prevTouch = d.activeTouch
prevTouch.end = +new Date
}
......@@ -142,7 +142,7 @@ function registerEventHandlers(cm) {
let dx = other.left - touch.left, dy = other.top - touch.top
return dx * dx + dy * dy > 20 * 20
}
on(d.scroller, "touchstart", function(e) {
on(d.scroller, "touchstart", e => {
if (!signalDOMEvent(cm, e) && !isMouseLikeTouchEvent(e)) {
clearTimeout(touchFinished)
let now = +new Date
......@@ -154,10 +154,10 @@ function registerEventHandlers(cm) {
}
}
})
on(d.scroller, "touchmove", function() {
on(d.scroller, "touchmove", () => {
if (d.activeTouch) d.activeTouch.moved = true
})
on(d.scroller, "touchend", function(e) {
on(d.scroller, "touchend", e => {
let touch = d.activeTouch
if (touch && !eventInWidget(d, e) && touch.left != null &&
!touch.moved && new Date - touch.start < 300) {
......@@ -178,7 +178,7 @@ function registerEventHandlers(cm) {
// Sync scrolling between fake scrollbars and real scrollable
// area, ensure viewport is updated when scrolling.
on(d.scroller, "scroll", function() {
on(d.scroller, "scroll", () => {
if (d.scroller.clientHeight) {
setScrollTop(cm, d.scroller.scrollTop)
setScrollLeft(cm, d.scroller.scrollLeft, true)
......@@ -187,27 +187,27 @@ function registerEventHandlers(cm) {
})
// Listen to wheel events in order to try and update the viewport on time.
on(d.scroller, "mousewheel", function(e){onScrollWheel(cm, e)})
on(d.scroller, "DOMMouseScroll", function(e){onScrollWheel(cm, e)})
on(d.scroller, "mousewheel", e => onScrollWheel(cm, e))
on(d.scroller, "DOMMouseScroll", e => onScrollWheel(cm, e))
// Prevent wrapper from ever scrolling
on(d.wrapper, "scroll", function() { d.wrapper.scrollTop = d.wrapper.scrollLeft = 0 })
on(d.wrapper, "scroll", () => d.wrapper.scrollTop = d.wrapper.scrollLeft = 0)
d.dragFunctions = {
enter: function(e) {if (!signalDOMEvent(cm, e)) e_stop(e)},
over: function(e) {if (!signalDOMEvent(cm, e)) { onDragOver(cm, e); e_stop(e) }},
start: function(e){onDragStart(cm, e)},
enter: e => {if (!signalDOMEvent(cm, e)) e_stop(e)},
over: e => {if (!signalDOMEvent(cm, e)) { onDragOver(cm, e); e_stop(e) }},
start: e => onDragStart(cm, e),
drop: operation(cm, onDrop),
leave: function(e) {if (!signalDOMEvent(cm, e)) { clearDragCursor(cm) }}
leave: e => {if (!signalDOMEvent(cm, e)) { clearDragCursor(cm) }}
}
let inp = d.input.getField()
on(inp, "keyup", function(e) { onKeyUp.call(cm, e) })
on(inp, "keyup", e => onKeyUp.call(cm, e))
on(inp, "keydown", operation(cm, onKeyDown))
on(inp, "keypress", operation(cm, onKeyPress))
on(inp, "focus", function(e) { onFocus(cm, e) })
on(inp, "blur", function (e) { onBlur(cm, e) })
on(inp, "focus", e => onFocus(cm, e))
on(inp, "blur", e => onBlur(cm, e))
}
let initHooks = []
CodeMirror.defineInitHook = function(f) {initHooks.push(f)}
CodeMirror.defineInitHook = f => initHooks.push(f)
......@@ -13,109 +13,87 @@ import { getOrder, lineLeft, lineRight } from "../util/bidi"
// editor, mostly used for keybindings.
export let commands = {
selectAll: selectAll,
singleSelection: function(cm) {
cm.setSelection(cm.getCursor("anchor"), cm.getCursor("head"), sel_dontScroll)
},
killLine: function(cm) {
deleteNearSelection(cm, function(range) {
if (range.empty()) {
let len = getLine(cm.doc, range.head.line).text.length
if (range.head.ch == len && range.head.line < cm.lastLine())
return {from: range.head, to: Pos(range.head.line + 1, 0)}
else
return {from: range.head, to: Pos(range.head.line, len)}
} else {
return {from: range.from(), to: range.to()}
}
})
},
deleteLine: function(cm) {
deleteNearSelection(cm, function(range) {
return {from: Pos(range.from().line, 0),
to: clipPos(cm.doc, Pos(range.to().line + 1, 0))}
})
},
delLineLeft: function(cm) {
deleteNearSelection(cm, function(range) {
return {from: Pos(range.from().line, 0), to: range.from()}
})
},
delWrappedLineLeft: function(cm) {
deleteNearSelection(cm, function(range) {
let top = cm.charCoords(range.head, "div").top + 5
let leftPos = cm.coordsChar({left: 0, top: top}, "div")
return {from: leftPos, to: range.from()}
})
},
delWrappedLineRight: function(cm) {
deleteNearSelection(cm, function(range) {
let top = cm.charCoords(range.head, "div").top + 5
let rightPos = cm.coordsChar({left: cm.display.lineDiv.offsetWidth + 100, top: top}, "div")
return {from: range.from(), to: rightPos }
})
},
undo: function(cm) {cm.undo()},
redo: function(cm) {cm.redo()},
undoSelection: function(cm) {cm.undoSelection()},
redoSelection: function(cm) {cm.redoSelection()},
goDocStart: function(cm) {cm.extendSelection(Pos(cm.firstLine(), 0))},
goDocEnd: function(cm) {cm.extendSelection(Pos(cm.lastLine()))},
goLineStart: function(cm) {
cm.extendSelectionsBy(function(range) { return lineStart(cm, range.head.line) },
{origin: "+move", bias: 1})
},
goLineStartSmart: function(cm) {
cm.extendSelectionsBy(function(range) {
return lineStartSmart(cm, range.head)
}, {origin: "+move", bias: 1})
},
goLineEnd: function(cm) {
cm.extendSelectionsBy(function(range) { return lineEnd(cm, range.head.line) },
{origin: "+move", bias: -1})
},
goLineRight: function(cm) {
cm.extendSelectionsBy(function(range) {
let top = cm.charCoords(range.head, "div").top + 5
return cm.coordsChar({left: cm.display.lineDiv.offsetWidth + 100, top: top}, "div")
}, sel_move)
},
goLineLeft: function(cm) {
cm.extendSelectionsBy(function(range) {
let top = cm.charCoords(range.head, "div").top + 5
return cm.coordsChar({left: 0, top: top}, "div")
}, sel_move)
},
goLineLeftSmart: function(cm) {
cm.extendSelectionsBy(function(range) {
let top = cm.charCoords(range.head, "div").top + 5
let pos = cm.coordsChar({left: 0, top: top}, "div")
if (pos.ch < cm.getLine(pos.line).search(/\S/)) return lineStartSmart(cm, range.head)
return pos
}, sel_move)
},
goLineUp: function(cm) {cm.moveV(-1, "line")},
goLineDown: function(cm) {cm.moveV(1, "line")},
goPageUp: function(cm) {cm.moveV(-1, "page")},
goPageDown: function(cm) {cm.moveV(1, "page")},
goCharLeft: function(cm) {cm.moveH(-1, "char")},
goCharRight: function(cm) {cm.moveH(1, "char")},
goColumnLeft: function(cm) {cm.moveH(-1, "column")},
goColumnRight: function(cm) {cm.moveH(1, "column")},
goWordLeft: function(cm) {cm.moveH(-1, "word")},
goGroupRight: function(cm) {cm.moveH(1, "group")},
goGroupLeft: function(cm) {cm.moveH(-1, "group")},
goWordRight: function(cm) {cm.moveH(1, "word")},
delCharBefore: function(cm) {cm.deleteH(-1, "char")},
delCharAfter: function(cm) {cm.deleteH(1, "char")},
delWordBefore: function(cm) {cm.deleteH(-1, "word")},
delWordAfter: function(cm) {cm.deleteH(1, "word")},
delGroupBefore: function(cm) {cm.deleteH(-1, "group")},
delGroupAfter: function(cm) {cm.deleteH(1, "group")},
indentAuto: function(cm) {cm.indentSelection("smart")},
indentMore: function(cm) {cm.indentSelection("add")},
indentLess: function(cm) {cm.indentSelection("subtract")},
insertTab: function(cm) {cm.replaceSelection("\t")},
insertSoftTab: function(cm) {
singleSelection: cm => cm.setSelection(cm.getCursor("anchor"), cm.getCursor("head"), sel_dontScroll),
killLine: cm => deleteNearSelection(cm, range => {
if (range.empty()) {
let len = getLine(cm.doc, range.head.line).text.length
if (range.head.ch == len && range.head.line < cm.lastLine())
return {from: range.head, to: Pos(range.head.line + 1, 0)}
else
return {from: range.head, to: Pos(range.head.line, len)}
} else {
return {from: range.from(), to: range.to()}
}
}),
deleteLine: cm => deleteNearSelection(cm, range => ({
from: Pos(range.from().line, 0),
to: clipPos(cm.doc, Pos(range.to().line + 1, 0))
})),
delLineLeft: cm => deleteNearSelection(cm, range => ({
from: Pos(range.from().line, 0), to: range.from()
})),
delWrappedLineLeft: cm => deleteNearSelection(cm, range => {
let top = cm.charCoords(range.head, "div").top + 5
let leftPos = cm.coordsChar({left: 0, top: top}, "div")
return {from: leftPos, to: range.from()}
}),
delWrappedLineRight: cm => deleteNearSelection(cm, range => {
let top = cm.charCoords(range.head, "div").top + 5
let rightPos = cm.coordsChar({left: cm.display.lineDiv.offsetWidth + 100, top: top}, "div")
return {from: range.from(), to: rightPos }
}),
undo: cm => cm.undo(),
redo: cm => cm.redo(),
undoSelection: cm => cm.undoSelection(),
redoSelection: cm => cm.redoSelection(),
goDocStart: cm => cm.extendSelection(Pos(cm.firstLine(), 0)),
goDocEnd: cm => cm.extendSelection(Pos(cm.lastLine())),
goLineStart: cm => cm.extendSelectionsBy(range => lineStart(cm, range.head.line),
{origin: "+move", bias: 1}
),
goLineStartSmart: cm => cm.extendSelectionsBy(range => lineStartSmart(cm, range.head),
{origin: "+move", bias: 1}
),
goLineEnd: cm => cm.extendSelectionsBy(range => lineEnd(cm, range.head.line),
{origin: "+move", bias: -1}
),
goLineRight: cm => cm.extendSelectionsBy(range => {
let top = cm.charCoords(range.head, "div").top + 5
return cm.coordsChar({left: cm.display.lineDiv.offsetWidth + 100, top: top}, "div")
}, sel_move),
goLineLeft: cm => cm.extendSelectionsBy(range => {
let top = cm.charCoords(range.head, "div").top + 5
return cm.coordsChar({left: 0, top: top}, "div")
}, sel_move),
goLineLeftSmart: cm => cm.extendSelectionsBy(range => {
let top = cm.charCoords(range.head, "div").top + 5
let pos = cm.coordsChar({left: 0, top: top}, "div")
if (pos.ch < cm.getLine(pos.line).search(/\S/)) return lineStartSmart(cm, range.head)
return pos
}, sel_move),
goLineUp: cm => cm.moveV(-1, "line"),
goLineDown: cm => cm.moveV(1, "line"),
goPageUp: cm => cm.moveV(-1, "page"),
goPageDown: cm => cm.moveV(1, "page"),
goCharLeft: cm => cm.moveH(-1, "char"),
goCharRight: cm => cm.moveH(1, "char"),
goColumnLeft: cm => cm.moveH(-1, "column"),
goColumnRight: cm => cm.moveH(1, "column"),
goWordLeft: cm => cm.moveH(-1, "word"),
goGroupRight: cm => cm.moveH(1, "group"),
goGroupLeft: cm => cm.moveH(-1, "group"),
goWordRight: cm => cm.moveH(1, "word"),
delCharBefore: cm => cm.deleteH(-1, "char"),
delCharAfter: cm => cm.deleteH(1, "char"),
delWordBefore: cm => cm.deleteH(-1, "word"),
delWordAfter: cm => cm.deleteH(1, "word"),
delGroupBefore: cm => cm.deleteH(-1, "group"),
delGroupAfter: cm => cm.deleteH(1, "group"),
indentAuto: cm => cm.indentSelection("smart"),
indentMore: cm => cm.indentSelection("add"),
indentLess: cm => cm.indentSelection("subtract"),
insertTab: cm => cm.replaceSelection("\t"),
insertSoftTab: cm => {
let spaces = [], ranges = cm.listSelections(), tabSize = cm.options.tabSize
for (let i = 0; i < ranges.length; i++) {
let pos = ranges[i].from()
......@@ -124,47 +102,43 @@ export let commands = {
}
cm.replaceSelections(spaces)
},
defaultTab: function(cm) {
defaultTab: cm => {
if (cm.somethingSelected()) cm.indentSelection("add")
else cm.execCommand("insertTab")
},
transposeChars: function(cm) {
runInOp(cm, function() {
let ranges = cm.listSelections(), newSel = []
for (let i = 0; i < ranges.length; i++) {
let cur = ranges[i].head, line = getLine(cm.doc, cur.line).text
if (line) {
if (cur.ch == line.length) cur = new Pos(cur.line, cur.ch - 1)
if (cur.ch > 0) {
cur = new Pos(cur.line, cur.ch + 1)
cm.replaceRange(line.charAt(cur.ch - 1) + line.charAt(cur.ch - 2),
Pos(cur.line, cur.ch - 2), cur, "+transpose")
} else if (cur.line > cm.doc.first) {
let prev = getLine(cm.doc, cur.line - 1).text
if (prev)
cm.replaceRange(line.charAt(0) + cm.doc.lineSeparator() +
prev.charAt(prev.length - 1),
Pos(cur.line - 1, prev.length - 1), Pos(cur.line, 1), "+transpose")
}
transposeChars: cm => runInOp(cm, () => {
let ranges = cm.listSelections(), newSel = []
for (let i = 0; i < ranges.length; i++) {
let cur = ranges[i].head, line = getLine(cm.doc, cur.line).text
if (line) {
if (cur.ch == line.length) cur = new Pos(cur.line, cur.ch - 1)
if (cur.ch > 0) {
cur = new Pos(cur.line, cur.ch + 1)
cm.replaceRange(line.charAt(cur.ch - 1) + line.charAt(cur.ch - 2),
Pos(cur.line, cur.ch - 2), cur, "+transpose")
} else if (cur.line > cm.doc.first) {
let prev = getLine(cm.doc, cur.line - 1).text
if (prev)
cm.replaceRange(line.charAt(0) + cm.doc.lineSeparator() +
prev.charAt(prev.length - 1),
Pos(cur.line - 1, prev.length - 1), Pos(cur.line, 1), "+transpose")
}
newSel.push(new Range(cur, cur))
}
cm.setSelections(newSel)
})
},
newlineAndIndent: function(cm) {
runInOp(cm, function() {
let sels = cm.listSelections()
for (let i = sels.length - 1; i >= 0; i--)
cm.replaceRange(cm.doc.lineSeparator(), sels[i].anchor, sels[i].head, "+input")
sels = cm.listSelections()
for (let i = 0; i < sels.length; i++)
cm.indentLine(sels[i].from().line, null, true)
ensureCursorVisible(cm)
})
},
openLine: function(cm) {cm.replaceSelection("\n", "start")},
toggleOverwrite: function(cm) {cm.toggleOverwrite()}
newSel.push(new Range(cur, cur))
}
cm.setSelections(newSel)
}),
newlineAndIndent: cm => runInOp(cm, () => {
let sels = cm.listSelections()
for (let i = sels.length - 1; i >= 0; i--)
cm.replaceRange(cm.doc.lineSeparator(), sels[i].anchor, sels[i].head, "+input")
sels = cm.listSelections()
for (let i = 0; i < sels.length; i++)
cm.indentLine(sels[i].from().line, null, true)
ensureCursorVisible(cm)
}),
openLine: cm => cm.replaceSelection("\n", "start"),
toggleOverwrite: cm => cm.toggleOverwrite()
}
......
......@@ -22,7 +22,7 @@ export function deleteNearSelection(cm, compute) {
kill.push(toKill)
}
// Next, remove those actual ranges.
runInOp(cm, function() {
runInOp(cm, () => {
for (let i = kill.length - 1; i >= 0; i--)
replaceRange(cm.doc, "", kill[i].from, kill[i].to, "+delete")
ensureCursorVisible(cm)
......
......@@ -29,13 +29,13 @@ export function onDrop(e) {
// and insert it.
if (files && files.length && window.FileReader && window.File) {
let n = files.length, text = Array(n), read = 0
let loadFile = function(file, i) {
let loadFile = (file, i) => {
if (cm.options.allowDropFileTypes &&
indexOf(cm.options.allowDropFileTypes, file.type) == -1)
return
let reader = new FileReader
reader.onload = operation(cm, function() {
reader.onload = operation(cm, () => {
let content = reader.result
if (/[\x00-\x08\x0e-\x1f]{2}/.test(content)) content = ""
text[i] = content
......@@ -56,7 +56,7 @@ export function onDrop(e) {
if (cm.state.draggingText && cm.doc.sel.contains(pos) > -1) {
cm.state.draggingText(e)
// Ensure the editor is re-focused
setTimeout(function() {cm.display.input.focus()}, 20)
setTimeout(() => cm.display.input.focus(), 20)
return
}
try {
......
......@@ -28,7 +28,7 @@ export function fromTextArea(textarea, options) {
let form = textarea.form
realSubmit = form.submit
try {
let wrappedSubmit = form.submit = function() {
let wrappedSubmit = form.submit = () => {
save()
form.submit = realSubmit
form.submit()
......@@ -38,10 +38,10 @@ export function fromTextArea(textarea, options) {
}
}
options.finishInit = function(cm) {
options.finishInit = cm => {
cm.save = save
cm.getTextArea = function() { return textarea }
cm.toTextArea = function() {
cm.getTextArea = () => textarea
cm.toTextArea = () => {
cm.toTextArea = isNaN // Prevent this from being ran twice
save()
textarea.parentNode.removeChild(cm.getWrapperElement())
......@@ -55,8 +55,7 @@ export function fromTextArea(textarea, options) {
}
textarea.style.display = "none"
let cm = CodeMirror(function(node) {
textarea.parentNode.insertBefore(node, textarea.nextSibling)
}, options)
let cm = CodeMirror(node => textarea.parentNode.insertBefore(node, textarea.nextSibling),
options)
return cm
}
......@@ -23,16 +23,14 @@ export function ensureGlobalHandlers() {
function registerGlobalHandlers() {
// When the window resizes, we need to refresh active editors.
let resizeTimer
on(window, "resize", function() {
if (resizeTimer == null) resizeTimer = setTimeout(function() {
on(window, "resize", () => {
if (resizeTimer == null) resizeTimer = setTimeout(() => {
resizeTimer = null
forEachCodeMirror(onResize)
}, 100)
})
// When the window loses focus, we want to show the editor as blurred
on(window, "blur", function() {
forEachCodeMirror(onBlur)
})
on(window, "blur", () => forEachCodeMirror(onBlur))
}
// Called when the window resizes
function onResize(cm) {
......
......@@ -45,7 +45,7 @@ function dispatchKey(cm, name, e, handle) {
let seq = cm.state.keySeq
if (seq) {
if (isModifierKey(name)) return "handled"
stopSeq.set(50, function() {
stopSeq.set(50, () => {
if (cm.state.keySeq == seq) {
cm.state.keySeq = null
cm.display.input.reset()
......@@ -81,20 +81,19 @@ function handleKeyBinding(cm, e) {
// First try to resolve full name (including 'Shift-'). Failing
// that, see if there is a cursor-motion command (starting with
// 'go') bound to the keyname without 'Shift-'.
return dispatchKey(cm, "Shift-" + name, e, function(b) {return doHandleBinding(cm, b, true)})
|| dispatchKey(cm, name, e, function(b) {
return dispatchKey(cm, "Shift-" + name, e, b => doHandleBinding(cm, b, true))
|| dispatchKey(cm, name, e, b => {
if (typeof b == "string" ? /^go[A-Z]/.test(b) : b.motion)
return doHandleBinding(cm, b)
})
} else {
return dispatchKey(cm, name, e, function(b) { return doHandleBinding(cm, b) })
return dispatchKey(cm, name, e, b => doHandleBinding(cm, b))
}
}
// Handle a key from the keypress event
function handleCharBinding(cm, e, ch) {
return dispatchKey(cm, "'" + ch + "'", e,
function(b) { return doHandleBinding(cm, b, true) })
return dispatchKey(cm, "'" + ch + "'", e, b => doHandleBinding(cm, b, true))
}
let lastStoppedKey = null
......
......@@ -46,17 +46,15 @@ CodeMirror.defineMode = function(name/*, mode, …*/) {
CodeMirror.defineMIME = defineMIME
// Minimal default mode.
CodeMirror.defineMode("null", function() {
return {token: function(stream) {stream.skipToEnd()}}
})
CodeMirror.defineMode("null", () => ({token: stream => stream.skipToEnd()}))
CodeMirror.defineMIME("text/plain", "null")
// EXTENSIONS
CodeMirror.defineExtension = function(name, func) {
CodeMirror.defineExtension = (name, func) => {
CodeMirror.prototype[name] = func
}
CodeMirror.defineDocExtension = function(name, func) {
CodeMirror.defineDocExtension = (name, func) => {
Doc.prototype[name] = func
}
......
......@@ -69,7 +69,7 @@ export default function(CodeMirror) {
insertSorted(this.state.overlays,
{mode: mode, modeSpec: spec, opaque: options && options.opaque,
priority: (options && options.priority) || 0},
function(overlay) { return overlay.priority })
overlay => overlay.priority)
this.state.modeGen++
regChange(this)
}),
......@@ -219,7 +219,7 @@ export default function(CodeMirror) {
defaultCharWidth: function() { return charWidth(this.display) },
setGutterMarker: methodOp(function(line, gutterID, value) {
return changeLine(this.doc, line, "gutter", function(line) {
return changeLine(this.doc, line, "gutter", line => {
let markers = line.gutterMarkers || (line.gutterMarkers = {})
markers[gutterID] = value
if (!value && isEmpty(markers)) line.gutterMarkers = null
......@@ -229,7 +229,7 @@ export default function(CodeMirror) {
clearGutter: methodOp(function(gutterID) {
let cm = this, doc = cm.doc, i = doc.first
doc.iter(function(line) {
doc.iter(line => {
if (line.gutterMarkers && line.gutterMarkers[gutterID]) {
line.gutterMarkers[gutterID] = null
regLineChange(cm, i, "gutter")
......@@ -316,7 +316,7 @@ export default function(CodeMirror) {
moveH: methodOp(function(dir, unit) {
let cm = this
cm.extendSelectionsBy(function(range) {
cm.extendSelectionsBy(range => {
if (cm.display.shift || cm.doc.extend || range.empty())
return findPosH(cm.doc, range.head, dir, unit, cm.options.rtlMoveVisually)
else
......@@ -329,7 +329,7 @@ export default function(CodeMirror) {
if (sel.somethingSelected())
doc.replaceSelection("", null, "+delete")
else
deleteNearSelection(this, function(range) {
deleteNearSelection(this, range => {
let other = findPosH(doc, range.head, dir, unit, false)
return dir < 0 ? {from: other, to: range.head} : {from: range.head, to: other}
})
......@@ -352,7 +352,7 @@ 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()
doc.extendSelectionsBy(function(range) {
doc.extendSelectionsBy(range => {
if (collapse)
return dir < 0 ? range.from() : range.to()
let headPos = cursorCoords(cm, range.head, "div")
......@@ -376,9 +376,9 @@ export default function(CodeMirror) {
if ((pos.xRel < 0 || end == line.length) && start) --start; else ++end
let startChar = line.charAt(start)
let check = isWordChar(startChar, helper)
? function(ch) { return isWordChar(ch, helper) }
: /\s/.test(startChar) ? function(ch) {return /\s/.test(ch)}
: function(ch) {return !/\s/.test(ch) && !isWordChar(ch)}
? ch => isWordChar(ch, helper)
: /\s/.test(startChar) ? ch => /\s/.test(ch)
: ch => (!/\s/.test(ch) && !isWordChar(ch))
while (start > 0 && check(line.charAt(start - 1))) --start
while (end < line.length && check(line.charAt(end))) ++end
}
......@@ -436,14 +436,12 @@ export default function(CodeMirror) {
setSize: methodOp(function(width, height) {
let cm = this
function interpret(val) {
return typeof val == "number" || /^\d+$/.test(String(val)) ? val + "px" : val
}
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, function(line) {
cm.doc.iter(lineNo, cm.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 }
++lineNo
......
......@@ -28,7 +28,7 @@ export function onMouseDown(e) {
// Briefly turn off draggability, to allow widgets to do
// normal dragging things.
display.scroller.draggable = false
setTimeout(function(){display.scroller.draggable = true}, 100)
setTimeout(() => display.scroller.draggable = true, 100)
}
return
}
......@@ -49,7 +49,7 @@ export function onMouseDown(e) {
case 2:
if (webkit) cm.state.lastMiddleDown = +new Date
if (start) extendSelection(cm.doc, start)
setTimeout(function() {display.input.focus()}, 20)
setTimeout(() => display.input.focus(), 20)
e_preventDefault(e)
break
case 3:
......@@ -89,7 +89,7 @@ function leftButtonDown(cm, e, start) {
// happen, and treat as a click if it didn't.
function leftButtonStartDrag(cm, e, start, modifier) {
let display = cm.display, startTime = +new Date
let dragEnd = operation(cm, function(e2) {
let dragEnd = operation(cm, e2 => {
if (webkit) display.scroller.draggable = false
cm.state.draggingText = false
off(document, "mouseup", dragEnd)
......@@ -100,7 +100,7 @@ function leftButtonStartDrag(cm, e, start, modifier) {
extendSelection(cm.doc, start)
// Work around unexplainable focus problem in IE9 (#2127) and Chrome (#3081)
if (webkit || ie && ie_version == 9)
setTimeout(function() {document.body.focus(); display.input.focus()}, 20)
setTimeout(() => {document.body.focus(); display.input.focus()}, 20)
else
display.input.focus()
}
......@@ -230,10 +230,10 @@ function leftButtonSelect(cm, e, start, type, addNew) {
extendTo(cur)
let visible = visibleLines(display, doc)
if (cur.line >= visible.to || cur.line < visible.from)
setTimeout(operation(cm, function(){if (counter == curCount) extend(e)}), 150)
setTimeout(operation(cm, () => {if (counter == curCount) extend(e)}), 150)
} else {
let outside = e.clientY < editorSize.top ? -20 : e.clientY > editorSize.bottom ? 20 : 0
if (outside) setTimeout(operation(cm, function() {
if (outside) setTimeout(operation(cm, () => {
if (counter != curCount) return
display.scroller.scrollTop += outside
extend(e)
......@@ -251,7 +251,7 @@ function leftButtonSelect(cm, e, start, type, addNew) {
doc.history.lastSelOrigin = null
}
let move = operation(cm, function(e) {
let move = operation(cm, e => {
if (!e_button(e)) done(e)
else extend(e)
})
......
......@@ -28,7 +28,7 @@ export function defineOptions(CodeMirror) {
function option(name, deflt, handle, notOnInit) {
CodeMirror.defaults[name] = deflt
if (handle) optionHandlers[name] =
notOnInit ? function(cm, val, old) {if (old != Init) handle(cm, val, old)} : handle
notOnInit ? (cm, val, old) => {if (old != Init) handle(cm, val, old)} : handle
}
CodeMirror.defineOption = option
......@@ -38,10 +38,8 @@ export function defineOptions(CodeMirror) {
// These two are, on init, called from the constructor because they
// have to be initialized before the editor can start at all.
option("value", "", function(cm, val) {
cm.setValue(val)
}, true)
option("mode", null, function(cm, val) {
option("value", "", (cm, val) => cm.setValue(val), true)
option("mode", null, (cm, val) => {
cm.doc.modeOption = val
loadMode(cm)
}, true)
......@@ -49,16 +47,16 @@ export function defineOptions(CodeMirror) {
option("indentUnit", 2, loadMode, true)
option("indentWithTabs", false)
option("smartIndent", true)
option("tabSize", 4, function(cm) {
option("tabSize", 4, cm => {
resetModeState(cm)
clearCaches(cm)
regChange(cm)
}, true)
option("lineSeparator", null, function(cm, val) {
option("lineSeparator", null, (cm, val) => {
cm.doc.lineSep = val
if (!val) return
let newBreaks = [], lineNo = cm.doc.first
cm.doc.iter(function(line) {
cm.doc.iter(line => {
for (let pos = 0;;) {
let found = line.text.indexOf(val, pos)
if (found == -1) break
......@@ -70,26 +68,24 @@ export function defineOptions(CodeMirror) {
for (let i = newBreaks.length - 1; i >= 0; i--)
replaceRange(cm.doc, val, newBreaks[i], Pos(newBreaks[i].line, newBreaks[i].ch + val.length))
})
option("specialChars", /[\u0000-\u001f\u007f\u00ad\u200b-\u200f\u2028\u2029\ufeff]/g, function(cm, val, old) {
option("specialChars", /[\u0000-\u001f\u007f\u00ad\u200b-\u200f\u2028\u2029\ufeff]/g, (cm, val, old) => {
cm.state.specialChars = new RegExp(val.source + (val.test("\t") ? "" : "|\t"), "g")
if (old != Init) cm.refresh()
})
option("specialCharPlaceholder", defaultSpecialCharPlaceholder, function(cm) {cm.refresh()}, true)
option("specialCharPlaceholder", defaultSpecialCharPlaceholder, cm => cm.refresh(), true)
option("electricChars", true)
option("inputStyle", mobile ? "contenteditable" : "textarea", function() {
option("inputStyle", mobile ? "contenteditable" : "textarea", () => {
throw new Error("inputStyle can not (yet) be changed in a running editor") // FIXME
}, true)
option("spellcheck", false, function(cm, val) {
cm.getInputField().spellcheck = val
}, true)
option("spellcheck", false, (cm, val) => cm.getInputField().spellcheck = val, true)
option("rtlMoveVisually", !windows)
option("wholeLineUpdateBefore", true)
option("theme", "default", function(cm) {
option("theme", "default", cm => {
themeChanged(cm)
guttersChanged(cm)
}, true)
option("keyMap", "default", function(cm, val, old) {
option("keyMap", "default", (cm, val, old) => {
let next = getKeyMap(val)
let prev = old != Init && getKeyMap(old)
if (prev && prev.detach) prev.detach(cm, next)
......@@ -98,33 +94,33 @@ export function defineOptions(CodeMirror) {
option("extraKeys", null)
option("lineWrapping", false, wrappingChanged, true)
option("gutters", [], function(cm) {
option("gutters", [], cm => {
setGuttersForLineNumbers(cm.options)
guttersChanged(cm)
}, true)
option("fixedGutter", true, function(cm, val) {
option("fixedGutter", true, (cm, val) => {
cm.display.gutters.style.left = val ? compensateForHScroll(cm.display) + "px" : "0"
cm.refresh()
}, true)
option("coverGutterNextToScrollbar", false, function(cm) {updateScrollbars(cm)}, true)
option("scrollbarStyle", "native", function(cm) {
option("coverGutterNextToScrollbar", false, cm => updateScrollbars(cm), true)
option("scrollbarStyle", "native", cm => {
initScrollbars(cm)
updateScrollbars(cm)
cm.display.scrollbars.setScrollTop(cm.doc.scrollTop)
cm.display.scrollbars.setScrollLeft(cm.doc.scrollLeft)
}, true)
option("lineNumbers", false, function(cm) {
option("lineNumbers", false, cm => {
setGuttersForLineNumbers(cm.options)
guttersChanged(cm)
}, true)
option("firstLineNumber", 1, guttersChanged, true)
option("lineNumberFormatter", function(integer) {return integer}, guttersChanged, true)
option("lineNumberFormatter", integer => integer, guttersChanged, true)
option("showCursorWhenSelecting", false, updateSelection, true)
option("resetSelectionOnContextMenu", true)
option("lineWiseCopyCut", true)
option("readOnly", false, function(cm, val) {
option("readOnly", false, (cm, val) => {
if (val == "nocursor") {
onBlur(cm)
cm.display.input.blur()
......@@ -134,7 +130,7 @@ export function defineOptions(CodeMirror) {
}
cm.display.input.readOnlyChanged(val)
})
option("disableInput", false, function(cm, val) {if (!val) cm.display.input.reset()}, true)
option("disableInput", false, (cm, val) => {if (!val) cm.display.input.reset()}, true)
option("dragDrop", true, dragDropChanged)
option("allowDropFileTypes", null)
......@@ -147,24 +143,22 @@ export function defineOptions(CodeMirror) {
option("flattenSpans", true, resetModeState, true)
option("addModeClass", false, resetModeState, true)
option("pollInterval", 100)
option("undoDepth", 200, function(cm, val){cm.doc.history.undoDepth = val})
option("undoDepth", 200, (cm, val) => cm.doc.history.undoDepth = val)
option("historyEventDelay", 1250)
option("viewportMargin", 10, function(cm){cm.refresh()}, true)
option("viewportMargin", 10, cm => cm.refresh(), true)
option("maxHighlightLength", 10000, resetModeState, true)
option("moveInputWithCursor", true, function(cm, val) {
option("moveInputWithCursor", true, (cm, val) => {
if (!val) cm.display.input.resetPosition()
})
option("tabindex", null, function(cm, val) {
cm.display.input.getField().tabIndex = val || ""
})
option("tabindex", null, (cm, val) => cm.display.input.getField().tabIndex = val || "")
option("autofocus", null)
}
function guttersChanged(cm) {
updateGutters(cm)
regChange(cm)
setTimeout(function(){alignHorizontally(cm)}, 20)
setTimeout(() => alignHorizontally(cm), 20)
}
function dragDropChanged(cm, value, old) {
......@@ -192,5 +186,5 @@ function wrappingChanged(cm) {
estimateLineHeights(cm)
regChange(cm)
clearCaches(cm)
setTimeout(function(){updateScrollbars(cm)}, 100)
setTimeout(() => updateScrollbars(cm), 100)
}
......@@ -29,15 +29,15 @@ ContentEditableInput.prototype = copyObj({
let div = input.div = display.lineDiv
disableBrowserMagic(div, cm.options.spellcheck)
on(div, "paste", function(e) {
on(div, "paste", e => {
if (signalDOMEvent(cm, e) || handlePaste(e, cm)) return
// IE doesn't fire input events, so we schedule a read for the pasted content in this way
if (ie_version <= 11) setTimeout(operation(cm, function() {
if (ie_version <= 11) setTimeout(operation(cm, () => {
if (!input.pollContent()) regChange(cm)
}), 20)
})
on(div, "compositionstart", function(e) {
on(div, "compositionstart", e => {
let data = e.data
input.composing = {sel: cm.doc.sel, data: data, startData: data}
if (!data) return
......@@ -48,10 +48,8 @@ ContentEditableInput.prototype = copyObj({
input.composing.sel = simpleSelection(Pos(prim.head.line, found),
Pos(prim.head.line, found + data.length))
})
on(div, "compositionupdate", function(e) {
input.composing.data = e.data
})
on(div, "compositionend", function(e) {
on(div, "compositionupdate", e => input.composing.data = e.data)
on(div, "compositionend", e => {
let ours = input.composing
if (!ours) return
if (e.data != ours.startData && !/\u200b/.test(e.data))
......@@ -59,7 +57,7 @@ ContentEditableInput.prototype = copyObj({
// Need a small delay to prevent other code (input event,
// selection polling) from doing damage when fired right after
// compositionend.
setTimeout(function() {
setTimeout(() => {
if (!ours.handled)
input.applyComposition(ours)
if (input.composing == ours)
......@@ -67,14 +65,12 @@ ContentEditableInput.prototype = copyObj({
}, 50)
})
on(div, "touchstart", function() {
input.forceCompositionEnd()
})
on(div, "touchstart", () => input.forceCompositionEnd())
on(div, "input", function() {
on(div, "input", () => {
if (input.composing) return
if (cm.isReadOnly() || !input.pollContent())
runInOp(input.cm, function() {regChange(cm)})
runInOp(input.cm, () => regChange(cm))
})
function onCopyCut(e) {
......@@ -88,7 +84,7 @@ ContentEditableInput.prototype = copyObj({
let ranges = copyableRanges(cm)
setLastCopied({lineWise: true, text: ranges.text})
if (e.type == "cut") {
cm.operation(function() {
cm.operation(() => {
cm.setSelections(ranges.ranges, 0, sel_dontScroll)
cm.replaceSelection("", null, "cut")
})
......@@ -110,7 +106,7 @@ ContentEditableInput.prototype = copyObj({
te.value = lastCopied.text.join("\n")
let hadFocus = document.activeElement
selectInput(te)
setTimeout(function() {
setTimeout(() => {
cm.display.lineSpace.removeChild(kludge)
hadFocus.focus()
if (hadFocus == div) input.showPrimarySelection()
......@@ -175,10 +171,10 @@ ContentEditableInput.prototype = copyObj({
startGracePeriod: function() {
let input = this
clearTimeout(this.gracePeriod)
this.gracePeriod = setTimeout(function() {
this.gracePeriod = setTimeout(() => {
input.gracePeriod = false
if (input.selectionChanged())
input.cm.operation(function() { input.cm.curOp.selectionChanged = true })
input.cm.operation(() => input.cm.curOp.selectionChanged = true)
}, 20)
},
......@@ -213,7 +209,7 @@ ContentEditableInput.prototype = copyObj({
if (this.selectionInEditor())
this.pollSelection()
else
runInOp(this.cm, function() { input.cm.curOp.selectionChanged = true })
runInOp(this.cm, () => input.cm.curOp.selectionChanged = true)
function poll() {
if (input.cm.state.focused) {
......@@ -236,7 +232,7 @@ ContentEditableInput.prototype = copyObj({
this.rememberSelection()
let anchor = domToPos(cm, sel.anchorNode, sel.anchorOffset)
let head = domToPos(cm, sel.focusNode, sel.focusOffset)
if (anchor && head) runInOp(cm, function() {
if (anchor && head) runInOp(cm, () => {
setSelection(cm.doc, simpleSelection(anchor, head), sel_dontScroll)
if (anchor.bad || head.bad) cm.curOp.selectionChanged = true
})
......@@ -356,7 +352,7 @@ function badPos(pos, bad) { if (bad) pos.bad = true; return pos }
function domTextBetween(cm, from, to, fromLine, toLine) {
let text = "", closing = false, lineSep = cm.doc.lineSeparator()
function recognizeMarker(id) { return function(marker) { return marker.id == id } }
function recognizeMarker(id) { return marker => marker.id == id }
function walk(node) {
if (node.nodeType == 1) {
let cmText = node.getAttribute("cm-text")
......
......@@ -46,12 +46,12 @@ TextareaInput.prototype = copyObj({
// Needed to hide big blue blinking cursor on Mobile Safari (doesn't seem to work in iOS 8 anymore)
if (ios) te.style.width = "0px"
on(te, "input", function() {
on(te, "input", () => {
if (ie && ie_version >= 9 && input.hasSelection) input.hasSelection = null
input.poll()
})
on(te, "paste", function(e) {
on(te, "paste", e => {
if (signalDOMEvent(cm, e) || handlePaste(e, cm)) return
cm.state.pasteIncoming = true
......@@ -86,18 +86,18 @@ TextareaInput.prototype = copyObj({
on(te, "cut", prepareCopyCut)
on(te, "copy", prepareCopyCut)
on(display.scroller, "paste", function(e) {
on(display.scroller, "paste", e => {
if (eventInWidget(display, e) || signalDOMEvent(cm, e)) return
cm.state.pasteIncoming = true
input.focus()
})
// Prevent normal selection in the editor (we handle our own)
on(display.lineSpace, "selectstart", function(e) {
on(display.lineSpace, "selectstart", e => {
if (!eventInWidget(display, e)) e_preventDefault(e)
})
on(te, "compositionstart", function() {
on(te, "compositionstart", () => {
let start = cm.getCursor("from")
if (input.composing) input.composing.range.clear()
input.composing = {
......@@ -105,7 +105,7 @@ TextareaInput.prototype = copyObj({
range: cm.markText(start, cm.getCursor("to"), {className: "CodeMirror-composing"})
}
})
on(te, "compositionend", function() {
on(te, "compositionend", () => {
if (input.composing) {
input.poll()
input.composing.range.clear()
......@@ -187,7 +187,7 @@ TextareaInput.prototype = copyObj({
slowPoll: function() {
let input = this
if (input.pollingFast) return
input.polling.set(this.cm.options.pollInterval, function() {
input.polling.set(this.cm.options.pollInterval, () => {
input.poll()
if (input.cm.state.focused) input.slowPoll()
})
......@@ -246,7 +246,7 @@ TextareaInput.prototype = copyObj({
while (same < l && prevInput.charCodeAt(same) == text.charCodeAt(same)) ++same
let self = this
runInOp(cm, function() {
runInOp(cm, () => {
applyTextInput(cm, text.slice(same), prevInput.length - same,
null, self.composing ? "*compose" : null)
......@@ -326,7 +326,7 @@ TextareaInput.prototype = copyObj({
// Try to detect the user choosing select-all
if (te.selectionStart != null) {
if (!ie || (ie && ie_version < 9)) prepareSelectAllHack()
let i = 0, poll = function() {
let i = 0, poll = () => {
if (display.selForContextMenu == cm.doc.sel && te.selectionStart == 0 &&
te.selectionEnd > 0 && input.prevInput == "\u200b")
operation(cm, selectAll)(cm)
......@@ -340,7 +340,7 @@ TextareaInput.prototype = copyObj({
if (ie && ie_version >= 9) prepareSelectAllHack()
if (captureRightClick) {
e_stop(e)
let mouseup = function() {
let mouseup = () => {
off(window, "mouseup", mouseup)
setTimeout(rehide, 20)
}
......
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