Skip to content

Commit

Permalink
Replace var with let
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianheine authored and marijnh committed Sep 29, 2016
1 parent 519b3ad commit c17d023
Show file tree
Hide file tree
Showing 57 changed files with 1,327 additions and 1,281 deletions.
2 changes: 1 addition & 1 deletion src/display/Display.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { scrollerGap } from "../util/misc"
// display-related state.

export function Display(place, doc, input) {
var d = this
let d = this
this.input = input

// Covers bottom-right square when both scrollbars are present.
Expand Down
11 changes: 6 additions & 5 deletions src/display/gutters.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ import { updateGutterSpace } from "./update_display"
// Rebuild the gutter elements, ensure the margin to the left of the
// code matches their width.
export function updateGutters(cm) {
var gutters = cm.display.gutters, specs = cm.options.gutters
let gutters = cm.display.gutters, specs = cm.options.gutters
removeChildren(gutters)
for (var i = 0; i < specs.length; ++i) {
var gutterClass = specs[i]
var gElt = gutters.appendChild(elt("div", null, "CodeMirror-gutter " + gutterClass))
let i = 0
for (; i < specs.length; ++i) {
let gutterClass = specs[i]
let gElt = gutters.appendChild(elt("div", null, "CodeMirror-gutter " + gutterClass))
if (gutterClass == "CodeMirror-linenumbers") {
cm.display.lineGutter = gElt
gElt.style.width = (cm.display.lineNumWidth || 1) + "px"
Expand All @@ -23,7 +24,7 @@ export function updateGutters(cm) {
// Make sure the gutters options contains the element
// "CodeMirror-linenumbers" when the lineNumbers option is true.
export function setGuttersForLineNumbers(options) {
var found = indexOf(options.gutters, "CodeMirror-linenumbers")
let found = indexOf(options.gutters, "CodeMirror-linenumbers")
if (found == -1 && options.lineNumbers) {
options.gutters = options.gutters.concat(["CodeMirror-linenumbers"])
} else if (found > -1 && !options.lineNumbers) {
Expand Down
20 changes: 10 additions & 10 deletions src/display/highlight_worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,24 @@ export function startWorker(cm, time) {
}

function highlightWorker(cm) {
var doc = cm.doc
let doc = cm.doc
if (doc.frontier < doc.first) doc.frontier = doc.first
if (doc.frontier >= cm.display.viewTo) return
var end = +new Date + cm.options.workTime
var state = copyState(doc.mode, getStateBefore(cm, doc.frontier))
var changedLines = []
let end = +new Date + cm.options.workTime
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) {
if (doc.frontier >= cm.display.viewFrom) { // Visible
var oldStyles = line.styles, tooLong = line.text.length > cm.options.maxHighlightLength
var highlighted = highlightLine(cm, line, tooLong ? copyState(doc.mode, state) : state, true)
let oldStyles = line.styles, tooLong = line.text.length > cm.options.maxHighlightLength
let highlighted = highlightLine(cm, line, tooLong ? copyState(doc.mode, state) : state, true)
line.styles = highlighted.styles
var oldCls = line.styleClasses, newCls = highlighted.classes
let oldCls = line.styleClasses, newCls = highlighted.classes
if (newCls) line.styleClasses = newCls
else if (oldCls) line.styleClasses = null
var ischange = !oldStyles || oldStyles.length != line.styles.length ||
let ischange = !oldStyles || oldStyles.length != line.styles.length ||
oldCls != newCls && (!oldCls || !newCls || oldCls.bgClass != newCls.bgClass || oldCls.textClass != newCls.textClass)
for (var i = 0; !ischange && i < oldStyles.length; ++i) ischange = oldStyles[i] != line.styles[i]
for (let i = 0; !ischange && i < oldStyles.length; ++i) ischange = oldStyles[i] != line.styles[i]
if (ischange) changedLines.push(doc.frontier)
line.stateAfter = tooLong ? state : copyState(doc.mode, state)
} else {
Expand All @@ -45,7 +45,7 @@ function highlightWorker(cm) {
}
})
if (changedLines.length) runInOp(cm, function() {
for (var i = 0; i < changedLines.length; i++)
for (let i = 0; i < changedLines.length; i++)
regLineChange(cm, changedLines[i], "text")
})
}
18 changes: 9 additions & 9 deletions src/display/line_numbers.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@ import { updateGutterSpace } from "./update_display"
// Re-align line numbers and gutter marks to compensate for
// horizontal scrolling.
export function alignHorizontally(cm) {
var display = cm.display, view = display.view
let display = cm.display, view = display.view
if (!display.alignWidgets && (!display.gutters.firstChild || !cm.options.fixedGutter)) return
var comp = compensateForHScroll(display) - display.scroller.scrollLeft + cm.doc.scrollLeft
var gutterW = display.gutters.offsetWidth, left = comp + "px"
for (var i = 0; i < view.length; i++) if (!view[i].hidden) {
let comp = compensateForHScroll(display) - display.scroller.scrollLeft + cm.doc.scrollLeft
let gutterW = display.gutters.offsetWidth, left = comp + "px"
for (let i = 0; i < view.length; i++) if (!view[i].hidden) {
if (cm.options.fixedGutter) {
if (view[i].gutter)
view[i].gutter.style.left = left
if (view[i].gutterBackground)
view[i].gutterBackground.style.left = left
}
var align = view[i].alignable
if (align) for (var j = 0; j < align.length; j++)
let align = view[i].alignable
if (align) for (let j = 0; j < align.length; j++)
align[j].style.left = left
}
if (cm.options.fixedGutter)
Expand All @@ -31,11 +31,11 @@ export function alignHorizontally(cm) {
// is needed.
export function maybeUpdateLineNumberWidth(cm) {
if (!cm.options.lineNumbers) return false
var doc = cm.doc, last = lineNumberFor(cm.options, doc.first + doc.size - 1), display = cm.display
let doc = cm.doc, last = lineNumberFor(cm.options, doc.first + doc.size - 1), display = cm.display
if (last.length != display.lineNumChars) {
var test = display.measure.appendChild(elt("div", [elt("div", last)],
let test = display.measure.appendChild(elt("div", [elt("div", last)],
"CodeMirror-linenumber CodeMirror-gutter-elt"))
var innerW = test.firstChild.offsetWidth, padding = test.offsetWidth - innerW
let innerW = test.firstChild.offsetWidth, padding = test.offsetWidth - innerW
display.lineGutter.style.width = ""
display.lineNumInnerWidth = Math.max(innerW, display.lineGutter.offsetWidth - padding) + 1
display.lineNumWidth = display.lineNumInnerWidth + padding
Expand Down
38 changes: 19 additions & 19 deletions src/display/operations.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { updateHeightsInViewport } from "./update_lines"
// error-prone). Instead, display updates are batched and then all
// combined and executed at once.

var nextOpId = 0
let nextOpId = 0
// Start a new operation.
export function startOperation(cm) {
cm.curOp = {
Expand All @@ -45,9 +45,9 @@ export function startOperation(cm) {

// Finish an operation, updating the display and signalling delayed events
export function endOperation(cm) {
var op = cm.curOp
let op = cm.curOp
finishOperation(op, function(group) {
for (var i = 0; i < group.ops.length; i++)
for (let i = 0; i < group.ops.length; i++)
group.ops[i].cm.curOp = null
endOperations(group)
})
Expand All @@ -56,21 +56,21 @@ export function endOperation(cm) {
// The DOM updates done when an operation finishes are batched so
// that the minimum number of relayouts are required.
function endOperations(group) {
var ops = group.ops
for (var i = 0; i < ops.length; i++) // Read DOM
let ops = group.ops
for (let i = 0; i < ops.length; i++) // Read DOM
endOperation_R1(ops[i])
for (var i = 0; i < ops.length; i++) // Write DOM (maybe)
for (let i = 0; i < ops.length; i++) // Write DOM (maybe)
endOperation_W1(ops[i])
for (var i = 0; i < ops.length; i++) // Read DOM
for (let i = 0; i < ops.length; i++) // Read DOM
endOperation_R2(ops[i])
for (var i = 0; i < ops.length; i++) // Write DOM (maybe)
for (let i = 0; i < ops.length; i++) // Write DOM (maybe)
endOperation_W2(ops[i])
for (var i = 0; i < ops.length; i++) // Read DOM
for (let i = 0; i < ops.length; i++) // Read DOM
endOperation_finish(ops[i])
}

function endOperation_R1(op) {
var cm = op.cm, display = cm.display
let cm = op.cm, display = cm.display
maybeClipScrollbars(cm)
if (op.updateMaxLine) findMaxLine(cm)

Expand All @@ -87,7 +87,7 @@ function endOperation_W1(op) {
}

function endOperation_R2(op) {
var cm = op.cm, display = cm.display
let cm = op.cm, display = cm.display
if (op.updatedDisplay) updateHeightsInViewport(cm)

op.barMeasure = measureForScrollbars(cm)
Expand All @@ -108,7 +108,7 @@ function endOperation_R2(op) {
}

function endOperation_W2(op) {
var cm = op.cm
let cm = op.cm

if (op.adjustWidthTo != null) {
cm.display.sizer.style.minWidth = op.adjustWidthTo + "px"
Expand All @@ -117,7 +117,7 @@ function endOperation_W2(op) {
cm.display.maxLineChanged = false
}

var takeFocus = op.focus && op.focus == activeElt() && (!document.hasFocus || document.hasFocus())
let takeFocus = op.focus && op.focus == activeElt() && (!document.hasFocus || document.hasFocus())
if (op.preparedSelection)
cm.display.input.showSelection(op.preparedSelection, takeFocus)
if (op.updatedDisplay || op.startHeight != cm.doc.height)
Expand All @@ -133,7 +133,7 @@ function endOperation_W2(op) {
}

function endOperation_finish(op) {
var cm = op.cm, display = cm.display, doc = cm.doc
let cm = op.cm, display = cm.display, doc = cm.doc

if (op.updatedDisplay) postUpdateDisplay(cm, op.update)

Expand All @@ -155,17 +155,17 @@ function endOperation_finish(op) {
}
// If we need to scroll a specific position into view, do so.
if (op.scrollToPos) {
var coords = scrollPosIntoView(cm, clipPos(doc, op.scrollToPos.from),
let coords = scrollPosIntoView(cm, clipPos(doc, op.scrollToPos.from),
clipPos(doc, op.scrollToPos.to), op.scrollToPos.margin)
if (op.scrollToPos.isCursor && cm.state.focused) maybeScrollWindow(cm, coords)
}

// Fire events for markers that are hidden/unidden by editing or
// undoing
var hidden = op.maybeHiddenMarkers, unhidden = op.maybeUnhiddenMarkers
if (hidden) for (var i = 0; i < hidden.length; ++i)
let hidden = op.maybeHiddenMarkers, unhidden = op.maybeUnhiddenMarkers
if (hidden) for (let i = 0; i < hidden.length; ++i)
if (!hidden[i].lines.length) signal(hidden[i], "hide")
if (unhidden) for (var i = 0; i < unhidden.length; ++i)
if (unhidden) for (let i = 0; i < unhidden.length; ++i)
if (unhidden[i].lines.length) signal(unhidden[i], "unhide")

if (display.wrapper.offsetHeight)
Expand Down Expand Up @@ -206,7 +206,7 @@ export function methodOp(f) {
}
export function docMethodOp(f) {
return function() {
var cm = this.cm
let cm = this.cm
if (!cm || cm.curOp) return f.apply(this, arguments)
startOperation(cm)
try { return f.apply(this, arguments) }
Expand Down
30 changes: 15 additions & 15 deletions src/display/scroll_events.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export function setScrollLeft(cm, val, isScroller) {
// is that it gives us a chance to update the display before the
// actual scrolling happens, reducing flickering.

var wheelSamples = 0, wheelPixelsPerUnit = null
let wheelSamples = 0, wheelPixelsPerUnit = null
// Fill in a browser-detected starting value on browsers where we
// know one. These don't have to be accurate -- the result of them
// being wrong would just be a slight flicker on the first wheel
Expand All @@ -48,36 +48,36 @@ else if (gecko) wheelPixelsPerUnit = 15
else if (chrome) wheelPixelsPerUnit = -.7
else if (safari) wheelPixelsPerUnit = -1/3

var wheelEventDelta = function(e) {
var dx = e.wheelDeltaX, dy = e.wheelDeltaY
let wheelEventDelta = function(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
else if (dy == null) dy = e.wheelDelta
return {x: dx, y: dy}
}
export function wheelEventPixels(e) {
var delta = wheelEventDelta(e)
let delta = wheelEventDelta(e)
delta.x *= wheelPixelsPerUnit
delta.y *= wheelPixelsPerUnit
return delta
}

export function onScrollWheel(cm, e) {
var delta = wheelEventDelta(e), dx = delta.x, dy = delta.y
let delta = wheelEventDelta(e), dx = delta.x, dy = delta.y

var display = cm.display, scroll = display.scroller
let display = cm.display, scroll = display.scroller
// Quit if there's nothing to scroll here
var canScrollX = scroll.scrollWidth > scroll.clientWidth
var canScrollY = scroll.scrollHeight > scroll.clientHeight
let canScrollX = scroll.scrollWidth > scroll.clientWidth
let canScrollY = scroll.scrollHeight > scroll.clientHeight
if (!(dx && canScrollX || dy && canScrollY)) return

// Webkit browsers on OS X abort momentum scrolls when the target
// of the scroll event is removed from the scrollable element.
// This hack (see related code in patchDisplay) makes sure the
// element is kept around.
if (dy && mac && webkit) {
outer: for (var cur = e.target, view = display.view; cur != scroll; cur = cur.parentNode) {
for (var i = 0; i < view.length; i++) {
outer: for (let cur = e.target, view = display.view; cur != scroll; cur = cur.parentNode) {
for (let i = 0; i < view.length; i++) {
if (view[i].node == cur) {
cm.display.currentWheelTarget = cur
break outer
Expand Down Expand Up @@ -109,8 +109,8 @@ export function onScrollWheel(cm, e) {
// 'Project' the visible viewport to cover the area that is being
// scrolled into view (if we know enough to estimate it).
if (dy && wheelPixelsPerUnit != null) {
var pixels = dy * wheelPixelsPerUnit
var top = cm.doc.scrollTop, bot = top + display.wrapper.clientHeight
let pixels = dy * wheelPixelsPerUnit
let top = cm.doc.scrollTop, bot = top + display.wrapper.clientHeight
if (pixels < 0) top = Math.max(0, top + pixels - 50)
else bot = Math.min(cm.doc.height, bot + pixels + 50)
updateDisplaySimple(cm, {top: top, bottom: bot})
Expand All @@ -122,9 +122,9 @@ export function onScrollWheel(cm, e) {
display.wheelDX = dx; display.wheelDY = dy
setTimeout(function() {
if (display.wheelStartX == null) return
var movedX = scroll.scrollLeft - display.wheelStartX
var movedY = scroll.scrollTop - display.wheelStartY
var sample = (movedY && display.wheelDY && movedY / display.wheelDY) ||
let movedX = scroll.scrollLeft - display.wheelStartX
let movedY = scroll.scrollTop - display.wheelStartY
let sample = (movedY && display.wheelDY && movedY / display.wheelDY) ||
(movedX && display.wheelDX && movedX / display.wheelDX)
display.wheelStartX = display.wheelStartY = null
if (!sample) return
Expand Down
Loading

0 comments on commit c17d023

Please sign in to comment.