Commit fac62400 authored by Romain Courteaud's avatar Romain Courteaud

[erp5_code_mirror] Drop the not needed src folder

parent a3a26621
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Folder" module="OFS.Folder"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_objects</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>src</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="File" module="OFS.Image"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_Cacheable__manager_id</string> </key>
<value> <string>http_cache</string> </value>
</item>
<item>
<key> <string>__name__</string> </key>
<value> <string>codemirror.js</string> </value>
</item>
<item>
<key> <string>content_type</string> </key>
<value> <string>application/javascript</string> </value>
</item>
<item>
<key> <string>precondition</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Folder" module="OFS.Folder"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_objects</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>display</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
import { gecko, ie, ie_version, mobile, webkit } from "../util/browser"
import { elt } from "../util/dom"
import { scrollerGap } from "../util/misc"
// The display handles the DOM integration, both for input reading
// and content drawing. It holds references to DOM nodes and
// display-related state.
export function Display(place, doc, input) {
let d = this
this.input = input
// Covers bottom-right square when both scrollbars are present.
d.scrollbarFiller = elt("div", null, "CodeMirror-scrollbar-filler")
d.scrollbarFiller.setAttribute("cm-not-content", "true")
// Covers bottom of gutter when coverGutterNextToScrollbar is on
// and h scrollbar is present.
d.gutterFiller = elt("div", null, "CodeMirror-gutter-filler")
d.gutterFiller.setAttribute("cm-not-content", "true")
// Will contain the actual code, positioned to cover the viewport.
d.lineDiv = elt("div", null, "CodeMirror-code")
// Elements are added to these to represent selection and cursors.
d.selectionDiv = elt("div", null, null, "position: relative; z-index: 1")
d.cursorDiv = elt("div", null, "CodeMirror-cursors")
// A visibility: hidden element used to find the size of things.
d.measure = elt("div", null, "CodeMirror-measure")
// When lines outside of the viewport are measured, they are drawn in this.
d.lineMeasure = elt("div", null, "CodeMirror-measure")
// Wraps everything that needs to exist inside the vertically-padded coordinate system
d.lineSpace = elt("div", [d.measure, d.lineMeasure, d.selectionDiv, d.cursorDiv, d.lineDiv],
null, "position: relative; outline: none")
// Moved around its parent to cover visible view.
d.mover = elt("div", [elt("div", [d.lineSpace], "CodeMirror-lines")], null, "position: relative")
// Set to the height of the document, allowing scrolling.
d.sizer = elt("div", [d.mover], "CodeMirror-sizer")
d.sizerWidth = null
// Behavior of elts with overflow: auto and padding is
// inconsistent across browsers. This is used to ensure the
// scrollable area is big enough.
d.heightForcer = elt("div", null, null, "position: absolute; height: " + scrollerGap + "px; width: 1px;")
// Will contain the gutters, if any.
d.gutters = elt("div", null, "CodeMirror-gutters")
d.lineGutter = null
// Actual scrollable element.
d.scroller = elt("div", [d.sizer, d.heightForcer, d.gutters], "CodeMirror-scroll")
d.scroller.setAttribute("tabIndex", "-1")
// The element in which the editor lives.
d.wrapper = elt("div", [d.scrollbarFiller, d.gutterFiller, d.scroller], "CodeMirror")
// Work around IE7 z-index bug (not perfect, hence IE7 not really being supported)
if (ie && ie_version < 8) { d.gutters.style.zIndex = -1; d.scroller.style.paddingRight = 0 }
if (!webkit && !(gecko && mobile)) d.scroller.draggable = true
if (place) {
if (place.appendChild) place.appendChild(d.wrapper)
else place(d.wrapper)
}
// Current rendered range (may be bigger than the view window).
d.viewFrom = d.viewTo = doc.first
d.reportedViewFrom = d.reportedViewTo = doc.first
// Information about the rendered lines.
d.view = []
d.renderedView = null
// Holds info about a single rendered line when it was rendered
// for measurement, while not in view.
d.externalMeasured = null
// Empty space (in pixels) above the view
d.viewOffset = 0
d.lastWrapHeight = d.lastWrapWidth = 0
d.updateLineNumbers = null
d.nativeBarWidth = d.barHeight = d.barWidth = 0
d.scrollbarsClipped = false
// Used to only resize the line number gutter when necessary (when
// the amount of lines crosses a boundary that makes its width change)
d.lineNumWidth = d.lineNumInnerWidth = d.lineNumChars = null
// Set to true when a non-horizontal-scrolling line widget is
// added. As an optimization, line widget aligning is skipped when
// this is false.
d.alignWidgets = false
d.cachedCharWidth = d.cachedTextHeight = d.cachedPaddingH = null
// Tracks the maximum line length so that the horizontal scrollbar
// can be kept static when scrolling.
d.maxLine = null
d.maxLineLength = 0
d.maxLineChanged = false
// Used for measuring wheel scrolling granularity
d.wheelDX = d.wheelDY = d.wheelStartX = d.wheelStartY = null
// True when shift is held down.
d.shift = false
// Used to track whether anything happened since the context menu
// was opened.
d.selForContextMenu = null
d.activeTouch = null
input.init(d)
}
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="File" module="OFS.Image"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_Cacheable__manager_id</string> </key>
<value> <string>http_cache</string> </value>
</item>
<item>
<key> <string>__name__</string> </key>
<value> <string>Display.js</string> </value>
</item>
<item>
<key> <string>content_type</string> </key>
<value> <string>application/javascript</string> </value>
</item>
<item>
<key> <string>precondition</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
import { restartBlink } from "./selection"
import { webkit } from "../util/browser"
import { addClass, rmClass } from "../util/dom"
import { signal } from "../util/event"
export function ensureFocus(cm) {
if (!cm.state.focused) { cm.display.input.focus(); onFocus(cm) }
}
export function delayBlurEvent(cm) {
cm.state.delayingBlurEvent = true
setTimeout(() => { if (cm.state.delayingBlurEvent) {
cm.state.delayingBlurEvent = false
onBlur(cm)
} }, 100)
}
export function onFocus(cm, e) {
if (cm.state.delayingBlurEvent) cm.state.delayingBlurEvent = false
if (cm.options.readOnly == "nocursor") return
if (!cm.state.focused) {
signal(cm, "focus", cm, e)
cm.state.focused = true
addClass(cm.display.wrapper, "CodeMirror-focused")
// This test prevents this from firing when a context
// menu is closed (since the input reset would kill the
// select-all detection hack)
if (!cm.curOp && cm.display.selForContextMenu != cm.doc.sel) {
cm.display.input.reset()
if (webkit) setTimeout(() => cm.display.input.reset(true), 20) // Issue #1730
}
cm.display.input.receivedFocus()
}
restartBlink(cm)
}
export function onBlur(cm, e) {
if (cm.state.delayingBlurEvent) return
if (cm.state.focused) {
signal(cm, "blur", cm, e)
cm.state.focused = false
rmClass(cm.display.wrapper, "CodeMirror-focused")
}
clearInterval(cm.display.blinker)
setTimeout(() => { if (!cm.state.focused) cm.display.shift = false }, 150)
}
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="File" module="OFS.Image"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_Cacheable__manager_id</string> </key>
<value> <string>http_cache</string> </value>
</item>
<item>
<key> <string>__name__</string> </key>
<value> <string>focus.js</string> </value>
</item>
<item>
<key> <string>content_type</string> </key>
<value> <string>application/javascript</string> </value>
</item>
<item>
<key> <string>precondition</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
import { elt, removeChildren } from "../util/dom"
import { indexOf } from "../util/misc"
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) {
let gutters = cm.display.gutters, specs = cm.options.gutters
removeChildren(gutters)
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"
}
}
gutters.style.display = i ? "" : "none"
updateGutterSpace(cm)
}
// Make sure the gutters options contains the element
// "CodeMirror-linenumbers" when the lineNumbers option is true.
export function setGuttersForLineNumbers(options) {
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) {
options.gutters = options.gutters.slice(0)
options.gutters.splice(found, 1)
}
}
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="File" module="OFS.Image"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_Cacheable__manager_id</string> </key>
<value> <string>http_cache</string> </value>
</item>
<item>
<key> <string>__name__</string> </key>
<value> <string>gutters.js</string> </value>
</item>
<item>
<key> <string>content_type</string> </key>
<value> <string>application/javascript</string> </value>
</item>
<item>
<key> <string>precondition</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
import { getStateBefore, highlightLine, processLine } from "../line/highlight"
import { copyState } from "../modes"
import { bind } from "../util/misc"
import { runInOp } from "./operations"
import { regLineChange } from "./view_tracking"
// HIGHLIGHT WORKER
export function startWorker(cm, time) {
if (cm.doc.mode.startState && cm.doc.frontier < cm.display.viewTo)
cm.state.highlight.set(time, bind(highlightWorker, cm))
}
function highlightWorker(cm) {
let doc = cm.doc
if (doc.frontier < doc.first) doc.frontier = doc.first
if (doc.frontier >= cm.display.viewTo) return
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), 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)
line.styles = highlighted.styles
let oldCls = line.styleClasses, newCls = highlighted.classes
if (newCls) line.styleClasses = newCls
else if (oldCls) line.styleClasses = null
let ischange = !oldStyles || oldStyles.length != line.styles.length ||
oldCls != newCls && (!oldCls || !newCls || oldCls.bgClass != newCls.bgClass || oldCls.textClass != newCls.textClass)
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 {
if (line.text.length <= cm.options.maxHighlightLength)
processLine(cm, line.text, state)
line.stateAfter = doc.frontier % 5 == 0 ? copyState(doc.mode, state) : null
}
++doc.frontier
if (+new Date > end) {
startWorker(cm, cm.options.workDelay)
return true
}
})
if (changedLines.length) runInOp(cm, () => {
for (let i = 0; i < changedLines.length; i++)
regLineChange(cm, changedLines[i], "text")
})
}
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="File" module="OFS.Image"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_Cacheable__manager_id</string> </key>
<value> <string>http_cache</string> </value>
</item>
<item>
<key> <string>__name__</string> </key>
<value> <string>highlight_worker.js</string> </value>
</item>
<item>
<key> <string>content_type</string> </key>
<value> <string>application/javascript</string> </value>
</item>
<item>
<key> <string>precondition</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
import { lineNumberFor } from "../line/utils_line"
import { compensateForHScroll } from "../measurement/position_measurement"
import { elt } from "../util/dom"
import { updateGutterSpace } from "./update_display"
// Re-align line numbers and gutter marks to compensate for
// horizontal scrolling.
export function alignHorizontally(cm) {
let display = cm.display, view = display.view
if (!display.alignWidgets && (!display.gutters.firstChild || !cm.options.fixedGutter)) return
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
}
let align = view[i].alignable
if (align) for (let j = 0; j < align.length; j++)
align[j].style.left = left
}
if (cm.options.fixedGutter)
display.gutters.style.left = (comp + gutterW) + "px"
}
// Used to ensure that the line number gutter is still the right
// size for the current document size. Returns true when an update
// is needed.
export function maybeUpdateLineNumberWidth(cm) {
if (!cm.options.lineNumbers) return false
let doc = cm.doc, last = lineNumberFor(cm.options, doc.first + doc.size - 1), display = cm.display
if (last.length != display.lineNumChars) {
let test = display.measure.appendChild(elt("div", [elt("div", last)],
"CodeMirror-linenumber CodeMirror-gutter-elt"))
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
display.lineNumChars = display.lineNumInnerWidth ? last.length : -1
display.lineGutter.style.width = display.lineNumWidth + "px"
updateGutterSpace(cm)
return true
}
return false
}
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="File" module="OFS.Image"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_Cacheable__manager_id</string> </key>
<value> <string>http_cache</string> </value>
</item>
<item>
<key> <string>__name__</string> </key>
<value> <string>line_numbers.js</string> </value>
</item>
<item>
<key> <string>content_type</string> </key>
<value> <string>application/javascript</string> </value>
</item>
<item>
<key> <string>precondition</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
import { getMode } from "../modes"
import { startWorker } from "./highlight_worker"
import { regChange } from "./view_tracking"
// Used to get the editor into a consistent state again when options change.
export function loadMode(cm) {
cm.doc.mode = getMode(cm.options, cm.doc.modeOption)
resetModeState(cm)
}
export function resetModeState(cm) {
cm.doc.iter(line => {
if (line.stateAfter) line.stateAfter = null
if (line.styles) line.styles = null
})
cm.doc.frontier = cm.doc.first
startWorker(cm, 100)
cm.state.modeGen++
if (cm.curOp) regChange(cm)
}
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="File" module="OFS.Image"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_Cacheable__manager_id</string> </key>
<value> <string>http_cache</string> </value>
</item>
<item>
<key> <string>__name__</string> </key>
<value> <string>mode_state.js</string> </value>
</item>
<item>
<key> <string>content_type</string> </key>
<value> <string>application/javascript</string> </value>
</item>
<item>
<key> <string>precondition</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
import { clipPos } from "../line/pos"
import { findMaxLine } from "../line/spans"
import { displayWidth, measureChar, scrollGap } from "../measurement/position_measurement"
import { signal } from "../util/event"
import { activeElt } from "../util/dom"
import { finishOperation, pushOperation } from "../util/operation_group"
import { ensureFocus } from "./focus"
import { alignHorizontally } from "./line_numbers"
import { measureForScrollbars, updateScrollbars } from "./scrollbars"
import { setScrollLeft } from "./scroll_events"
import { restartBlink } from "./selection"
import { maybeScrollWindow, scrollPosIntoView } from "./scrolling"
import { DisplayUpdate, maybeClipScrollbars, postUpdateDisplay, setDocumentHeight, updateDisplayIfNeeded } from "./update_display"
import { updateHeightsInViewport } from "./update_lines"
// Operations are used to wrap a series of changes to the editor
// state in such a way that each change won't have to update the
// cursor and display (which would be awkward, slow, and
// error-prone). Instead, display updates are batched and then all
// combined and executed at once.
let nextOpId = 0
// Start a new operation.
export function startOperation(cm) {
cm.curOp = {
cm: cm,
viewChanged: false, // Flag that indicates that lines might need to be redrawn
startHeight: cm.doc.height, // Used to detect need to update scrollbar
forceUpdate: false, // Used to force a redraw
updateInput: null, // Whether to reset the input textarea
typing: false, // Whether this reset should be careful to leave existing text (for compositing)
changeObjs: null, // Accumulated changes, for firing change events
cursorActivityHandlers: null, // Set of handlers to fire cursorActivity on
cursorActivityCalled: 0, // Tracks which cursorActivity handlers have been called already
selectionChanged: false, // Whether the selection needs to be redrawn
updateMaxLine: false, // Set when the widest line needs to be determined anew
scrollLeft: null, scrollTop: null, // Intermediate scroll position, not pushed to DOM yet
scrollToPos: null, // Used to scroll to a specific position
focus: false,
id: ++nextOpId // Unique ID
}
pushOperation(cm.curOp)
}
// Finish an operation, updating the display and signalling delayed events
export function endOperation(cm) {
let op = cm.curOp
finishOperation(op, group => {
for (let i = 0; i < group.ops.length; i++)
group.ops[i].cm.curOp = null
endOperations(group)
})
}
// The DOM updates done when an operation finishes are batched so
// that the minimum number of relayouts are required.
function endOperations(group) {
let ops = group.ops
for (let i = 0; i < ops.length; i++) // Read DOM
endOperation_R1(ops[i])
for (let i = 0; i < ops.length; i++) // Write DOM (maybe)
endOperation_W1(ops[i])
for (let i = 0; i < ops.length; i++) // Read DOM
endOperation_R2(ops[i])
for (let i = 0; i < ops.length; i++) // Write DOM (maybe)
endOperation_W2(ops[i])
for (let i = 0; i < ops.length; i++) // Read DOM
endOperation_finish(ops[i])
}
function endOperation_R1(op) {
let cm = op.cm, display = cm.display
maybeClipScrollbars(cm)
if (op.updateMaxLine) findMaxLine(cm)
op.mustUpdate = op.viewChanged || op.forceUpdate || op.scrollTop != null ||
op.scrollToPos && (op.scrollToPos.from.line < display.viewFrom ||
op.scrollToPos.to.line >= display.viewTo) ||
display.maxLineChanged && cm.options.lineWrapping
op.update = op.mustUpdate &&
new DisplayUpdate(cm, op.mustUpdate && {top: op.scrollTop, ensure: op.scrollToPos}, op.forceUpdate)
}
function endOperation_W1(op) {
op.updatedDisplay = op.mustUpdate && updateDisplayIfNeeded(op.cm, op.update)
}
function endOperation_R2(op) {
let cm = op.cm, display = cm.display
if (op.updatedDisplay) updateHeightsInViewport(cm)
op.barMeasure = measureForScrollbars(cm)
// If the max line changed since it was last measured, measure it,
// and ensure the document's width matches it.
// updateDisplay_W2 will use these properties to do the actual resizing
if (display.maxLineChanged && !cm.options.lineWrapping) {
op.adjustWidthTo = measureChar(cm, display.maxLine, display.maxLine.text.length).left + 3
cm.display.sizerWidth = op.adjustWidthTo
op.barMeasure.scrollWidth =
Math.max(display.scroller.clientWidth, display.sizer.offsetLeft + op.adjustWidthTo + scrollGap(cm) + cm.display.barWidth)
op.maxScrollLeft = Math.max(0, display.sizer.offsetLeft + op.adjustWidthTo - displayWidth(cm))
}
if (op.updatedDisplay || op.selectionChanged)
op.preparedSelection = display.input.prepareSelection(op.focus)
}
function endOperation_W2(op) {
let cm = op.cm
if (op.adjustWidthTo != null) {
cm.display.sizer.style.minWidth = op.adjustWidthTo + "px"
if (op.maxScrollLeft < cm.doc.scrollLeft)
setScrollLeft(cm, Math.min(cm.display.scroller.scrollLeft, op.maxScrollLeft), true)
cm.display.maxLineChanged = false
}
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)
updateScrollbars(cm, op.barMeasure)
if (op.updatedDisplay)
setDocumentHeight(cm, op.barMeasure)
if (op.selectionChanged) restartBlink(cm)
if (cm.state.focused && op.updateInput)
cm.display.input.reset(op.typing)
if (takeFocus) ensureFocus(op.cm)
}
function endOperation_finish(op) {
let cm = op.cm, display = cm.display, doc = cm.doc
if (op.updatedDisplay) postUpdateDisplay(cm, op.update)
// Abort mouse wheel delta measurement, when scrolling explicitly
if (display.wheelStartX != null && (op.scrollTop != null || op.scrollLeft != null || op.scrollToPos))
display.wheelStartX = display.wheelStartY = null
// Propagate the scroll position to the actual DOM scroller
if (op.scrollTop != null && (display.scroller.scrollTop != op.scrollTop || op.forceScroll)) {
doc.scrollTop = Math.max(0, Math.min(display.scroller.scrollHeight - display.scroller.clientHeight, op.scrollTop))
display.scrollbars.setScrollTop(doc.scrollTop)
display.scroller.scrollTop = doc.scrollTop
}
if (op.scrollLeft != null && (display.scroller.scrollLeft != op.scrollLeft || op.forceScroll)) {
doc.scrollLeft = Math.max(0, Math.min(display.scroller.scrollWidth - display.scroller.clientWidth, op.scrollLeft))
display.scrollbars.setScrollLeft(doc.scrollLeft)
display.scroller.scrollLeft = doc.scrollLeft
alignHorizontally(cm)
}
// If we need to scroll a specific position into view, do so.
if (op.scrollToPos) {
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
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 (let i = 0; i < unhidden.length; ++i)
if (unhidden[i].lines.length) signal(unhidden[i], "unhide")
if (display.wrapper.offsetHeight)
doc.scrollTop = cm.display.scroller.scrollTop
// Fire change events, and delayed event handlers
if (op.changeObjs)
signal(cm, "changes", cm, op.changeObjs)
if (op.update)
op.update.finish()
}
// Run the given function in an operation
export function runInOp(cm, f) {
if (cm.curOp) return f()
startOperation(cm)
try { return f() }
finally { endOperation(cm) }
}
// Wraps a function in an operation. Returns the wrapped function.
export function operation(cm, f) {
return function() {
if (cm.curOp) return f.apply(cm, arguments)
startOperation(cm)
try { return f.apply(cm, arguments) }
finally { endOperation(cm) }
}
}
// Used to add methods to editor and doc instances, wrapping them in
// operations.
export function methodOp(f) {
return function() {
if (this.curOp) return f.apply(this, arguments)
startOperation(this)
try { return f.apply(this, arguments) }
finally { endOperation(this) }
}
}
export function docMethodOp(f) {
return function() {
let cm = this.cm
if (!cm || cm.curOp) return f.apply(this, arguments)
startOperation(cm)
try { return f.apply(this, arguments) }
finally { endOperation(cm) }
}
}
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="File" module="OFS.Image"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_Cacheable__manager_id</string> </key>
<value> <string>http_cache</string> </value>
</item>
<item>
<key> <string>__name__</string> </key>
<value> <string>operations.js</string> </value>
</item>
<item>
<key> <string>content_type</string> </key>
<value> <string>application/javascript</string> </value>
</item>
<item>
<key> <string>precondition</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
import { chrome, gecko, ie, mac, presto, safari, webkit } from "../util/browser"
import { e_preventDefault } from "../util/event"
import { startWorker } from "./highlight_worker"
import { alignHorizontally } from "./line_numbers"
import { updateDisplaySimple} from "./update_display"
// Sync the scrollable area and scrollbars, ensure the viewport
// covers the visible area.
export function setScrollTop(cm, val) {
if (Math.abs(cm.doc.scrollTop - val) < 2) return
cm.doc.scrollTop = val
if (!gecko) updateDisplaySimple(cm, {top: val})
if (cm.display.scroller.scrollTop != val) cm.display.scroller.scrollTop = val
cm.display.scrollbars.setScrollTop(val)
if (gecko) updateDisplaySimple(cm)
startWorker(cm, 100)
}
// Sync scroller and scrollbar, ensure the gutter elements are
// aligned.
export function setScrollLeft(cm, val, isScroller) {
if (isScroller ? val == cm.doc.scrollLeft : Math.abs(cm.doc.scrollLeft - val) < 2) return
val = Math.min(val, cm.display.scroller.scrollWidth - cm.display.scroller.clientWidth)
cm.doc.scrollLeft = val
alignHorizontally(cm)
if (cm.display.scroller.scrollLeft != val) cm.display.scroller.scrollLeft = val
cm.display.scrollbars.setScrollLeft(val)
}
// Since the delta values reported on mouse wheel events are
// unstandardized between browsers and even browser versions, and
// generally horribly unpredictable, this code starts by measuring
// the scroll effect that the first few mouse wheel events have,
// and, from that, detects the way it can convert deltas to pixel
// offsets afterwards.
//
// The reason we want to know the amount a wheel event will scroll
// is that it gives us a chance to update the display before the
// actual scrolling happens, reducing flickering.
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
// scroll (if it is large enough).
if (ie) wheelPixelsPerUnit = -.53
else if (gecko) wheelPixelsPerUnit = 15
else if (chrome) wheelPixelsPerUnit = -.7
else if (safari) wheelPixelsPerUnit = -1/3
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
else if (dy == null) dy = e.wheelDelta
return {x: dx, y: dy}
}
export function wheelEventPixels(e) {
let delta = wheelEventDelta(e)
delta.x *= wheelPixelsPerUnit
delta.y *= wheelPixelsPerUnit
return delta
}
export function onScrollWheel(cm, e) {
let delta = wheelEventDelta(e), dx = delta.x, dy = delta.y
let display = cm.display, scroll = display.scroller
// Quit if there's nothing to scroll here
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 (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
}
}
}
}
// On some browsers, horizontal scrolling will cause redraws to
// happen before the gutter has been realigned, causing it to
// wriggle around in a most unseemly way. When we have an
// estimated pixels/delta value, we just handle horizontal
// scrolling entirely here. It'll be slightly off from native, but
// better than glitching out.
if (dx && !gecko && !presto && wheelPixelsPerUnit != null) {
if (dy && canScrollY)
setScrollTop(cm, Math.max(0, Math.min(scroll.scrollTop + dy * wheelPixelsPerUnit, scroll.scrollHeight - scroll.clientHeight)))
setScrollLeft(cm, Math.max(0, Math.min(scroll.scrollLeft + dx * wheelPixelsPerUnit, scroll.scrollWidth - scroll.clientWidth)))
// Only prevent default scrolling if vertical scrolling is
// actually possible. Otherwise, it causes vertical scroll
// jitter on OSX trackpads when deltaX is small and deltaY
// is large (issue #3579)
if (!dy || (dy && canScrollY))
e_preventDefault(e)
display.wheelStartX = null // Abort measurement, if in progress
return
}
// '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) {
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})
}
if (wheelSamples < 20) {
if (display.wheelStartX == null) {
display.wheelStartX = scroll.scrollLeft; display.wheelStartY = scroll.scrollTop
display.wheelDX = dx; display.wheelDY = dy
setTimeout(() => {
if (display.wheelStartX == null) return
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
wheelPixelsPerUnit = (wheelPixelsPerUnit * wheelSamples + sample) / (wheelSamples + 1)
++wheelSamples
}, 200)
} else {
display.wheelDX += dx; display.wheelDY += dy
}
}
}
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="File" module="OFS.Image"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_Cacheable__manager_id</string> </key>
<value> <string>http_cache</string> </value>
</item>
<item>
<key> <string>__name__</string> </key>
<value> <string>scroll_events.js</string> </value>
</item>
<item>
<key> <string>content_type</string> </key>
<value> <string>application/javascript</string> </value>
</item>
<item>
<key> <string>precondition</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
import { addClass, elt, rmClass } from "../util/dom"
import { on } from "../util/event"
import { scrollGap, paddingVert } from "../measurement/position_measurement"
import { ie, ie_version, mac, mac_geMountainLion } from "../util/browser"
import { updateHeightsInViewport } from "./update_lines"
import { Delayed } from "../util/misc"
import { setScrollLeft, setScrollTop } from "./scroll_events"
// SCROLLBARS
// Prepare DOM reads needed to update the scrollbars. Done in one
// shot to minimize update/measure roundtrips.
export function measureForScrollbars(cm) {
let d = cm.display, gutterW = d.gutters.offsetWidth
let docH = Math.round(cm.doc.height + paddingVert(cm.display))
return {
clientHeight: d.scroller.clientHeight,
viewHeight: d.wrapper.clientHeight,
scrollWidth: d.scroller.scrollWidth, clientWidth: d.scroller.clientWidth,
viewWidth: d.wrapper.clientWidth,
barLeft: cm.options.fixedGutter ? gutterW : 0,
docHeight: docH,
scrollHeight: docH + scrollGap(cm) + d.barHeight,
nativeBarWidth: d.nativeBarWidth,
gutterWidth: gutterW
}
}
class NativeScrollbars {
constructor(place, scroll, cm) {
this.cm = cm
let vert = this.vert = elt("div", [elt("div", null, null, "min-width: 1px")], "CodeMirror-vscrollbar")
let horiz = this.horiz = elt("div", [elt("div", null, null, "height: 100%; min-height: 1px")], "CodeMirror-hscrollbar")
place(vert); place(horiz)
on(vert, "scroll", () => {
if (vert.clientHeight) scroll(vert.scrollTop, "vertical")
})
on(horiz, "scroll", () => {
if (horiz.clientWidth) scroll(horiz.scrollLeft, "horizontal")
})
this.checkedZeroWidth = false
// Need to set a minimum width to see the scrollbar on IE7 (but must not set it on IE8).
if (ie && ie_version < 8) this.horiz.style.minHeight = this.vert.style.minWidth = "18px"
}
update(measure) {
let needsH = measure.scrollWidth > measure.clientWidth + 1
let needsV = measure.scrollHeight > measure.clientHeight + 1
let sWidth = measure.nativeBarWidth
if (needsV) {
this.vert.style.display = "block"
this.vert.style.bottom = needsH ? sWidth + "px" : "0"
let totalHeight = measure.viewHeight - (needsH ? sWidth : 0)
// A bug in IE8 can cause this value to be negative, so guard it.
this.vert.firstChild.style.height =
Math.max(0, measure.scrollHeight - measure.clientHeight + totalHeight) + "px"
} else {
this.vert.style.display = ""
this.vert.firstChild.style.height = "0"
}
if (needsH) {
this.horiz.style.display = "block"
this.horiz.style.right = needsV ? sWidth + "px" : "0"
this.horiz.style.left = measure.barLeft + "px"
let totalWidth = measure.viewWidth - measure.barLeft - (needsV ? sWidth : 0)
this.horiz.firstChild.style.width =
Math.max(0, measure.scrollWidth - measure.clientWidth + totalWidth) + "px"
} else {
this.horiz.style.display = ""
this.horiz.firstChild.style.width = "0"
}
if (!this.checkedZeroWidth && measure.clientHeight > 0) {
if (sWidth == 0) this.zeroWidthHack()
this.checkedZeroWidth = true
}
return {right: needsV ? sWidth : 0, bottom: needsH ? sWidth : 0}
}
setScrollLeft(pos) {
if (this.horiz.scrollLeft != pos) this.horiz.scrollLeft = pos
if (this.disableHoriz) this.enableZeroWidthBar(this.horiz, this.disableHoriz)
}
setScrollTop(pos) {
if (this.vert.scrollTop != pos) this.vert.scrollTop = pos
if (this.disableVert) this.enableZeroWidthBar(this.vert, this.disableVert)
}
zeroWidthHack() {
let w = mac && !mac_geMountainLion ? "12px" : "18px"
this.horiz.style.height = this.vert.style.width = w
this.horiz.style.pointerEvents = this.vert.style.pointerEvents = "none"
this.disableHoriz = new Delayed
this.disableVert = new Delayed
}
enableZeroWidthBar(bar, delay) {
bar.style.pointerEvents = "auto"
function maybeDisable() {
// To find out whether the scrollbar is still visible, we
// check whether the element under the pixel in the bottom
// left corner of the scrollbar box is the scrollbar box
// itself (when the bar is still visible) or its filler child
// (when the bar is hidden). If it is still visible, we keep
// it enabled, if it's hidden, we disable pointer events.
let box = bar.getBoundingClientRect()
let elt = document.elementFromPoint(box.left + 1, box.bottom - 1)
if (elt != bar) bar.style.pointerEvents = "none"
else delay.set(1000, maybeDisable)
}
delay.set(1000, maybeDisable)
}
clear() {
let parent = this.horiz.parentNode
parent.removeChild(this.horiz)
parent.removeChild(this.vert)
}
}
class NullScrollbars {
update() { return {bottom: 0, right: 0} }
setScrollLeft() {}
setScrollTop() {}
clear() {}
}
export function updateScrollbars(cm, measure) {
if (!measure) measure = measureForScrollbars(cm)
let startWidth = cm.display.barWidth, startHeight = cm.display.barHeight
updateScrollbarsInner(cm, measure)
for (let i = 0; i < 4 && startWidth != cm.display.barWidth || startHeight != cm.display.barHeight; i++) {
if (startWidth != cm.display.barWidth && cm.options.lineWrapping)
updateHeightsInViewport(cm)
updateScrollbarsInner(cm, measureForScrollbars(cm))
startWidth = cm.display.barWidth; startHeight = cm.display.barHeight
}
}
// Re-synchronize the fake scrollbars with the actual size of the
// content.
function updateScrollbarsInner(cm, measure) {
let d = cm.display
let sizes = d.scrollbars.update(measure)
d.sizer.style.paddingRight = (d.barWidth = sizes.right) + "px"
d.sizer.style.paddingBottom = (d.barHeight = sizes.bottom) + "px"
d.heightForcer.style.borderBottom = sizes.bottom + "px solid transparent"
if (sizes.right && sizes.bottom) {
d.scrollbarFiller.style.display = "block"
d.scrollbarFiller.style.height = sizes.bottom + "px"
d.scrollbarFiller.style.width = sizes.right + "px"
} else d.scrollbarFiller.style.display = ""
if (sizes.bottom && cm.options.coverGutterNextToScrollbar && cm.options.fixedGutter) {
d.gutterFiller.style.display = "block"
d.gutterFiller.style.height = sizes.bottom + "px"
d.gutterFiller.style.width = measure.gutterWidth + "px"
} else d.gutterFiller.style.display = ""
}
export let scrollbarModel = {"native": NativeScrollbars, "null": NullScrollbars}
export function initScrollbars(cm) {
if (cm.display.scrollbars) {
cm.display.scrollbars.clear()
if (cm.display.scrollbars.addClass)
rmClass(cm.display.wrapper, cm.display.scrollbars.addClass)
}
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", () => {
if (cm.state.focused) setTimeout(() => cm.display.input.focus(), 0)
})
node.setAttribute("cm-not-content", "true")
}, (pos, axis) => {
if (axis == "horizontal") setScrollLeft(cm, pos)
else setScrollTop(cm, pos)
}, cm)
if (cm.display.scrollbars.addClass)
addClass(cm.display.wrapper, cm.display.scrollbars.addClass)
}
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="File" module="OFS.Image"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_Cacheable__manager_id</string> </key>
<value> <string>http_cache</string> </value>
</item>
<item>
<key> <string>__name__</string> </key>
<value> <string>scrollbars.js</string> </value>
</item>
<item>
<key> <string>content_type</string> </key>
<value> <string>application/javascript</string> </value>
</item>
<item>
<key> <string>precondition</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
import { Pos } from "../line/pos"
import { cursorCoords, displayHeight, displayWidth, estimateCoords, paddingTop, paddingVert, scrollGap, textHeight } from "../measurement/position_measurement"
import { phantom } from "../util/browser"
import { elt } from "../util/dom"
import { signalDOMEvent } from "../util/event"
import { setScrollLeft, setScrollTop } from "./scroll_events"
// SCROLLING THINGS INTO VIEW
// If an editor sits on the top or bottom of the window, partially
// scrolled out of view, this ensures that the cursor is visible.
export function maybeScrollWindow(cm, coords) {
if (signalDOMEvent(cm, "scrollCursorIntoView")) return
let display = cm.display, box = display.sizer.getBoundingClientRect(), doScroll = null
if (coords.top + box.top < 0) doScroll = true
else if (coords.bottom + box.top > (window.innerHeight || document.documentElement.clientHeight)) doScroll = false
if (doScroll != null && !phantom) {
let scrollNode = elt("div", "\u200b", null, `position: absolute;
top: ${coords.top - display.viewOffset - paddingTop(cm.display)}px;
height: ${coords.bottom - coords.top + scrollGap(cm) + display.barHeight}px;
left: ${coords.left}px; width: 2px;`)
cm.display.lineSpace.appendChild(scrollNode)
scrollNode.scrollIntoView(doScroll)
cm.display.lineSpace.removeChild(scrollNode)
}
}
// Scroll a given position into view (immediately), verifying that
// it actually became visible (as line heights are accurately
// measured, the position of something may 'drift' during drawing).
export function scrollPosIntoView(cm, pos, end, margin) {
if (margin == null) margin = 0
let coords
for (let limit = 0; limit < 5; limit++) {
let changed = false
coords = cursorCoords(cm, pos)
let endCoords = !end || end == pos ? coords : cursorCoords(cm, end)
let scrollPos = calculateScrollPos(cm, Math.min(coords.left, endCoords.left),
Math.min(coords.top, endCoords.top) - margin,
Math.max(coords.left, endCoords.left),
Math.max(coords.bottom, endCoords.bottom) + margin)
let startTop = cm.doc.scrollTop, startLeft = cm.doc.scrollLeft
if (scrollPos.scrollTop != null) {
setScrollTop(cm, scrollPos.scrollTop)
if (Math.abs(cm.doc.scrollTop - startTop) > 1) changed = true
}
if (scrollPos.scrollLeft != null) {
setScrollLeft(cm, scrollPos.scrollLeft)
if (Math.abs(cm.doc.scrollLeft - startLeft) > 1) changed = true
}
if (!changed) break
}
return coords
}
// Scroll a given set of coordinates into view (immediately).
export function scrollIntoView(cm, x1, y1, x2, y2) {
let scrollPos = calculateScrollPos(cm, x1, y1, x2, y2)
if (scrollPos.scrollTop != null) setScrollTop(cm, scrollPos.scrollTop)
if (scrollPos.scrollLeft != null) setScrollLeft(cm, scrollPos.scrollLeft)
}
// Calculate a new scroll position needed to scroll the given
// rectangle into view. Returns an object with scrollTop and
// scrollLeft properties. When these are undefined, the
// vertical/horizontal position does not need to be adjusted.
export function calculateScrollPos(cm, x1, y1, x2, y2) {
let display = cm.display, snapMargin = textHeight(cm.display)
if (y1 < 0) y1 = 0
let screentop = cm.curOp && cm.curOp.scrollTop != null ? cm.curOp.scrollTop : display.scroller.scrollTop
let screen = displayHeight(cm), result = {}
if (y2 - y1 > screen) y2 = y1 + screen
let docBottom = cm.doc.height + paddingVert(display)
let atTop = y1 < snapMargin, atBottom = y2 > docBottom - snapMargin
if (y1 < screentop) {
result.scrollTop = atTop ? 0 : y1
} else if (y2 > screentop + screen) {
let newTop = Math.min(y1, (atBottom ? docBottom : y2) - screen)
if (newTop != screentop) result.scrollTop = newTop
}
let screenleft = cm.curOp && cm.curOp.scrollLeft != null ? cm.curOp.scrollLeft : display.scroller.scrollLeft
let screenw = displayWidth(cm) - (cm.options.fixedGutter ? display.gutters.offsetWidth : 0)
let tooWide = x2 - x1 > screenw
if (tooWide) x2 = x1 + screenw
if (x1 < 10)
result.scrollLeft = 0
else if (x1 < screenleft)
result.scrollLeft = Math.max(0, x1 - (tooWide ? 0 : 10))
else if (x2 > screenw + screenleft - 3)
result.scrollLeft = x2 + (tooWide ? 0 : 10) - screenw
return result
}
// Store a relative adjustment to the scroll position in the current
// operation (to be applied when the operation finishes).
export function addToScrollPos(cm, left, top) {
if (left != null || top != null) resolveScrollToPos(cm)
if (left != null)
cm.curOp.scrollLeft = (cm.curOp.scrollLeft == null ? cm.doc.scrollLeft : cm.curOp.scrollLeft) + left
if (top != null)
cm.curOp.scrollTop = (cm.curOp.scrollTop == null ? cm.doc.scrollTop : cm.curOp.scrollTop) + top
}
// Make sure that at the end of the operation the current cursor is
// shown.
export function ensureCursorVisible(cm) {
resolveScrollToPos(cm)
let cur = cm.getCursor(), from = cur, to = cur
if (!cm.options.lineWrapping) {
from = cur.ch ? Pos(cur.line, cur.ch - 1) : cur
to = Pos(cur.line, cur.ch + 1)
}
cm.curOp.scrollToPos = {from: from, to: to, margin: cm.options.cursorScrollMargin, isCursor: true}
}
// When an operation has its scrollToPos property set, and another
// scroll action is applied before the end of the operation, this
// 'simulates' scrolling that position into view in a cheap way, so
// that the effect of intermediate scroll commands is not ignored.
export function resolveScrollToPos(cm) {
let range = cm.curOp.scrollToPos
if (range) {
cm.curOp.scrollToPos = null
let from = estimateCoords(cm, range.from), to = estimateCoords(cm, range.to)
let sPos = calculateScrollPos(cm, Math.min(from.left, to.left),
Math.min(from.top, to.top) - range.margin,
Math.max(from.right, to.right),
Math.max(from.bottom, to.bottom) + range.margin)
cm.scrollTo(sPos.scrollLeft, sPos.scrollTop)
}
}
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="File" module="OFS.Image"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_Cacheable__manager_id</string> </key>
<value> <string>http_cache</string> </value>
</item>
<item>
<key> <string>__name__</string> </key>
<value> <string>scrolling.js</string> </value>
</item>
<item>
<key> <string>content_type</string> </key>
<value> <string>application/javascript</string> </value>
</item>
<item>
<key> <string>precondition</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
import { Pos } from "../line/pos"
import { visualLine } from "../line/spans"
import { getLine } from "../line/utils_line"
import { charCoords, cursorCoords, displayWidth, paddingH } from "../measurement/position_measurement"
import { getOrder, iterateBidiSections } from "../util/bidi"
import { elt } from "../util/dom"
export function updateSelection(cm) {
cm.display.input.showSelection(cm.display.input.prepareSelection())
}
export function prepareSelection(cm, primary) {
let doc = cm.doc, result = {}
let curFragment = result.cursors = document.createDocumentFragment()
let selFragment = result.selection = document.createDocumentFragment()
for (let i = 0; i < doc.sel.ranges.length; i++) {
if (primary === false && i == doc.sel.primIndex) continue
let range = doc.sel.ranges[i]
if (range.from().line >= cm.display.viewTo || range.to().line < cm.display.viewFrom) continue
let collapsed = range.empty()
if (collapsed || cm.options.showCursorWhenSelecting)
drawSelectionCursor(cm, range.head, curFragment)
if (!collapsed)
drawSelectionRange(cm, range, selFragment)
}
return result
}
// Draws a cursor for the given range
export function drawSelectionCursor(cm, head, output) {
let pos = cursorCoords(cm, head, "div", null, null, !cm.options.singleCursorHeightPerLine)
let cursor = output.appendChild(elt("div", "\u00a0", "CodeMirror-cursor"))
cursor.style.left = pos.left + "px"
cursor.style.top = pos.top + "px"
cursor.style.height = Math.max(0, pos.bottom - pos.top) * cm.options.cursorHeight + "px"
if (pos.other) {
// Secondary cursor, shown when on a 'jump' in bi-directional text
let otherCursor = output.appendChild(elt("div", "\u00a0", "CodeMirror-cursor CodeMirror-secondarycursor"))
otherCursor.style.display = ""
otherCursor.style.left = pos.other.left + "px"
otherCursor.style.top = pos.other.top + "px"
otherCursor.style.height = (pos.other.bottom - pos.other.top) * .85 + "px"
}
}
// Draws the given range as a highlighted selection
function drawSelectionRange(cm, range, output) {
let display = cm.display, doc = cm.doc
let fragment = document.createDocumentFragment()
let padding = paddingH(cm.display), leftSide = padding.left
let rightSide = Math.max(display.sizerWidth, displayWidth(cm) - display.sizer.offsetLeft) - padding.right
function add(left, top, width, bottom) {
if (top < 0) top = 0
top = Math.round(top)
bottom = Math.round(bottom)
fragment.appendChild(elt("div", null, "CodeMirror-selected", `position: absolute; left: ${left}px;
top: ${top}px; width: ${width == null ? rightSide - left : width}px;
height: ${bottom - top}px`))
}
function drawForLine(line, fromArg, toArg) {
let lineObj = getLine(doc, line)
let lineLen = lineObj.text.length
let start, end
function coords(ch, bias) {
return charCoords(cm, Pos(line, ch), "div", lineObj, bias)
}
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
left = right = leftPos.left
} else {
rightPos = coords(to - 1, "right")
if (dir == "rtl") { let tmp = leftPos; leftPos = rightPos; rightPos = tmp }
left = leftPos.left
right = rightPos.right
}
if (fromArg == null && from == 0) left = leftSide
if (rightPos.top - leftPos.top > 3) { // Different lines, draw top part
add(left, leftPos.top, null, leftPos.bottom)
left = leftSide
if (leftPos.bottom < rightPos.top) add(left, leftPos.bottom, null, rightPos.top)
}
if (toArg == null && to == lineLen) right = rightSide
if (!start || leftPos.top < start.top || leftPos.top == start.top && leftPos.left < start.left)
start = leftPos
if (!end || rightPos.bottom > end.bottom || rightPos.bottom == end.bottom && rightPos.right > end.right)
end = rightPos
if (left < leftSide + 1) left = leftSide
add(left, rightPos.top, right - left, rightPos.bottom)
})
return {start: start, end: end}
}
let sFrom = range.from(), sTo = range.to()
if (sFrom.line == sTo.line) {
drawForLine(sFrom.line, sFrom.ch, sTo.ch)
} else {
let fromLine = getLine(doc, sFrom.line), toLine = getLine(doc, sTo.line)
let singleVLine = visualLine(fromLine) == visualLine(toLine)
let leftEnd = drawForLine(sFrom.line, sFrom.ch, singleVLine ? fromLine.text.length + 1 : null).end
let rightStart = drawForLine(sTo.line, singleVLine ? 0 : null, sTo.ch).start
if (singleVLine) {
if (leftEnd.top < rightStart.top - 2) {
add(leftEnd.right, leftEnd.top, null, leftEnd.bottom)
add(leftSide, rightStart.top, rightStart.left, rightStart.bottom)
} else {
add(leftEnd.right, leftEnd.top, rightStart.left - leftEnd.right, leftEnd.bottom)
}
}
if (leftEnd.bottom < rightStart.top)
add(leftSide, leftEnd.bottom, null, rightStart.top)
}
output.appendChild(fragment)
}
// Cursor-blinking
export function restartBlink(cm) {
if (!cm.state.focused) return
let display = cm.display
clearInterval(display.blinker)
let on = true
display.cursorDiv.style.visibility = ""
if (cm.options.cursorBlinkRate > 0)
display.blinker = setInterval(() => display.cursorDiv.style.visibility = (on = !on) ? "" : "hidden",
cm.options.cursorBlinkRate)
else if (cm.options.cursorBlinkRate < 0)
display.cursorDiv.style.visibility = "hidden"
}
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="File" module="OFS.Image"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_Cacheable__manager_id</string> </key>
<value> <string>http_cache</string> </value>
</item>
<item>
<key> <string>__name__</string> </key>
<value> <string>selection.js</string> </value>
</item>
<item>
<key> <string>content_type</string> </key>
<value> <string>application/javascript</string> </value>
</item>
<item>
<key> <string>precondition</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
import { sawCollapsedSpans } from "../line/saw_special_spans"
import { heightAtLine, visualLineEndNo, visualLineNo } from "../line/spans"
import { getLine, lineNumberFor } from "../line/utils_line"
import { displayHeight, displayWidth, getDimensions, paddingVert, scrollGap } from "../measurement/position_measurement"
import { mac, webkit } from "../util/browser"
import { activeElt, removeChildren } from "../util/dom"
import { hasHandler, signal } from "../util/event"
import { indexOf } from "../util/misc"
import { buildLineElement, updateLineForChanges } from "./update_line"
import { startWorker } from "./highlight_worker"
import { maybeUpdateLineNumberWidth } from "./line_numbers"
import { measureForScrollbars, updateScrollbars } from "./scrollbars"
import { updateSelection } from "./selection"
import { updateHeightsInViewport, visibleLines } from "./update_lines"
import { adjustView, countDirtyView, resetView } from "./view_tracking"
// DISPLAY DRAWING
export class DisplayUpdate {
constructor(cm, viewport, force) {
let display = cm.display
this.viewport = viewport
// Store some values that we'll need later (but don't want to force a relayout for)
this.visible = visibleLines(display, cm.doc, viewport)
this.editorIsHidden = !display.wrapper.offsetWidth
this.wrapperHeight = display.wrapper.clientHeight
this.wrapperWidth = display.wrapper.clientWidth
this.oldDisplayWidth = displayWidth(cm)
this.force = force
this.dims = getDimensions(cm)
this.events = []
}
signal(emitter, type) {
if (hasHandler(emitter, type))
this.events.push(arguments)
}
finish() {
for (let i = 0; i < this.events.length; i++)
signal.apply(null, this.events[i])
}
}
export function maybeClipScrollbars(cm) {
let display = cm.display
if (!display.scrollbarsClipped && display.scroller.offsetWidth) {
display.nativeBarWidth = display.scroller.offsetWidth - display.scroller.clientWidth
display.heightForcer.style.height = scrollGap(cm) + "px"
display.sizer.style.marginBottom = -display.nativeBarWidth + "px"
display.sizer.style.borderRightWidth = scrollGap(cm) + "px"
display.scrollbarsClipped = true
}
}
// Does the actual updating of the line display. Bails out
// (returning false) when there is nothing to be done and forced is
// false.
export function updateDisplayIfNeeded(cm, update) {
let display = cm.display, doc = cm.doc
if (update.editorIsHidden) {
resetView(cm)
return false
}
// Bail out if the visible area is already rendered and nothing changed.
if (!update.force &&
update.visible.from >= display.viewFrom && update.visible.to <= display.viewTo &&
(display.updateLineNumbers == null || display.updateLineNumbers >= display.viewTo) &&
display.renderedView == display.view && countDirtyView(cm) == 0)
return false
if (maybeUpdateLineNumberWidth(cm)) {
resetView(cm)
update.dims = getDimensions(cm)
}
// Compute a suitable new viewport (from & to)
let end = doc.first + doc.size
let from = Math.max(update.visible.from - cm.options.viewportMargin, doc.first)
let to = Math.min(end, update.visible.to + cm.options.viewportMargin)
if (display.viewFrom < from && from - display.viewFrom < 20) from = Math.max(doc.first, display.viewFrom)
if (display.viewTo > to && display.viewTo - to < 20) to = Math.min(end, display.viewTo)
if (sawCollapsedSpans) {
from = visualLineNo(cm.doc, from)
to = visualLineEndNo(cm.doc, to)
}
let different = from != display.viewFrom || to != display.viewTo ||
display.lastWrapHeight != update.wrapperHeight || display.lastWrapWidth != update.wrapperWidth
adjustView(cm, from, to)
display.viewOffset = heightAtLine(getLine(cm.doc, display.viewFrom))
// Position the mover div to align with the current scroll position
cm.display.mover.style.top = display.viewOffset + "px"
let toUpdate = countDirtyView(cm)
if (!different && toUpdate == 0 && !update.force && display.renderedView == display.view &&
(display.updateLineNumbers == null || display.updateLineNumbers >= display.viewTo))
return false
// For big changes, we hide the enclosing element during the
// update, since that speeds up the operations on most browsers.
let focused = activeElt()
if (toUpdate > 4) display.lineDiv.style.display = "none"
patchDisplay(cm, display.updateLineNumbers, update.dims)
if (toUpdate > 4) display.lineDiv.style.display = ""
display.renderedView = display.view
// There might have been a widget with a focused element that got
// hidden or updated, if so re-focus it.
if (focused && activeElt() != focused && focused.offsetHeight) focused.focus()
// Prevent selection and cursors from interfering with the scroll
// width and height.
removeChildren(display.cursorDiv)
removeChildren(display.selectionDiv)
display.gutters.style.height = display.sizer.style.minHeight = 0
if (different) {
display.lastWrapHeight = update.wrapperHeight
display.lastWrapWidth = update.wrapperWidth
startWorker(cm, 400)
}
display.updateLineNumbers = null
return true
}
export function postUpdateDisplay(cm, update) {
let viewport = update.viewport
for (let first = true;; first = false) {
if (!first || !cm.options.lineWrapping || update.oldDisplayWidth == displayWidth(cm)) {
// Clip forced viewport to actual scrollable area.
if (viewport && viewport.top != null)
viewport = {top: Math.min(cm.doc.height + paddingVert(cm.display) - displayHeight(cm), viewport.top)}
// Updated line heights might result in the drawn area not
// actually covering the viewport. Keep looping until it does.
update.visible = visibleLines(cm.display, cm.doc, viewport)
if (update.visible.from >= cm.display.viewFrom && update.visible.to <= cm.display.viewTo)
break
}
if (!updateDisplayIfNeeded(cm, update)) break
updateHeightsInViewport(cm)
let barMeasure = measureForScrollbars(cm)
updateSelection(cm)
updateScrollbars(cm, barMeasure)
setDocumentHeight(cm, barMeasure)
}
update.signal(cm, "update", cm)
if (cm.display.viewFrom != cm.display.reportedViewFrom || cm.display.viewTo != cm.display.reportedViewTo) {
update.signal(cm, "viewportChange", cm, cm.display.viewFrom, cm.display.viewTo)
cm.display.reportedViewFrom = cm.display.viewFrom; cm.display.reportedViewTo = cm.display.viewTo
}
}
export function updateDisplaySimple(cm, viewport) {
let update = new DisplayUpdate(cm, viewport)
if (updateDisplayIfNeeded(cm, update)) {
updateHeightsInViewport(cm)
postUpdateDisplay(cm, update)
let barMeasure = measureForScrollbars(cm)
updateSelection(cm)
updateScrollbars(cm, barMeasure)
setDocumentHeight(cm, barMeasure)
update.finish()
}
}
// Sync the actual display DOM structure with display.view, removing
// nodes for lines that are no longer in view, and creating the ones
// that are not there yet, and updating the ones that are out of
// date.
function patchDisplay(cm, updateNumbersFrom, dims) {
let display = cm.display, lineNumbers = cm.options.lineNumbers
let container = display.lineDiv, cur = container.firstChild
function rm(node) {
let next = node.nextSibling
// Works around a throw-scroll bug in OS X Webkit
if (webkit && mac && cm.display.currentWheelTarget == node)
node.style.display = "none"
else
node.parentNode.removeChild(node)
return next
}
let view = display.view, lineN = display.viewFrom
// Loop over the elements in the view, syncing cur (the DOM nodes
// in display.lineDiv) with the view as we go.
for (let i = 0; i < view.length; i++) {
let lineView = view[i]
if (lineView.hidden) {
} else if (!lineView.node || lineView.node.parentNode != container) { // Not drawn yet
let node = buildLineElement(cm, lineView, lineN, dims)
container.insertBefore(node, cur)
} else { // Already drawn
while (cur != lineView.node) cur = rm(cur)
let updateNumber = lineNumbers && updateNumbersFrom != null &&
updateNumbersFrom <= lineN && lineView.lineNumber
if (lineView.changes) {
if (indexOf(lineView.changes, "gutter") > -1) updateNumber = false
updateLineForChanges(cm, lineView, lineN, dims)
}
if (updateNumber) {
removeChildren(lineView.lineNumber)
lineView.lineNumber.appendChild(document.createTextNode(lineNumberFor(cm.options, lineN)))
}
cur = lineView.node.nextSibling
}
lineN += lineView.size
}
while (cur) cur = rm(cur)
}
export function updateGutterSpace(cm) {
let width = cm.display.gutters.offsetWidth
cm.display.sizer.style.marginLeft = width + "px"
}
export function setDocumentHeight(cm, measure) {
cm.display.sizer.style.minHeight = measure.docHeight + "px"
cm.display.heightForcer.style.top = measure.docHeight + "px"
cm.display.gutters.style.height = (measure.docHeight + cm.display.barHeight + scrollGap(cm)) + "px"
}
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="File" module="OFS.Image"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_Cacheable__manager_id</string> </key>
<value> <string>http_cache</string> </value>
</item>
<item>
<key> <string>__name__</string> </key>
<value> <string>update_display.js</string> </value>
</item>
<item>
<key> <string>content_type</string> </key>
<value> <string>application/javascript</string> </value>
</item>
<item>
<key> <string>precondition</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
import { buildLineContent } from "../line/line_data"
import { lineNumberFor } from "../line/utils_line"
import { ie, ie_version } from "../util/browser"
import { elt } from "../util/dom"
import { signalLater } from "../util/operation_group"
// When an aspect of a line changes, a string is added to
// lineView.changes. This updates the relevant part of the line's
// DOM structure.
export function updateLineForChanges(cm, lineView, lineN, dims) {
for (let j = 0; j < lineView.changes.length; j++) {
let type = lineView.changes[j]
if (type == "text") updateLineText(cm, lineView)
else if (type == "gutter") updateLineGutter(cm, lineView, lineN, dims)
else if (type == "class") updateLineClasses(lineView)
else if (type == "widget") updateLineWidgets(cm, lineView, dims)
}
lineView.changes = null
}
// Lines with gutter elements, widgets or a background class need to
// be wrapped, and have the extra elements added to the wrapper div
function ensureLineWrapped(lineView) {
if (lineView.node == lineView.text) {
lineView.node = elt("div", null, null, "position: relative")
if (lineView.text.parentNode)
lineView.text.parentNode.replaceChild(lineView.node, lineView.text)
lineView.node.appendChild(lineView.text)
if (ie && ie_version < 8) lineView.node.style.zIndex = 2
}
return lineView.node
}
function updateLineBackground(lineView) {
let cls = lineView.bgClass ? lineView.bgClass + " " + (lineView.line.bgClass || "") : lineView.line.bgClass
if (cls) cls += " CodeMirror-linebackground"
if (lineView.background) {
if (cls) lineView.background.className = cls
else { lineView.background.parentNode.removeChild(lineView.background); lineView.background = null }
} else if (cls) {
let wrap = ensureLineWrapped(lineView)
lineView.background = wrap.insertBefore(elt("div", null, cls), wrap.firstChild)
}
}
// Wrapper around buildLineContent which will reuse the structure
// in display.externalMeasured when possible.
function getLineContent(cm, lineView) {
let ext = cm.display.externalMeasured
if (ext && ext.line == lineView.line) {
cm.display.externalMeasured = null
lineView.measure = ext.measure
return ext.built
}
return buildLineContent(cm, lineView)
}
// Redraw the line's text. Interacts with the background and text
// classes because the mode may output tokens that influence these
// classes.
function updateLineText(cm, lineView) {
let cls = lineView.text.className
let built = getLineContent(cm, lineView)
if (lineView.text == lineView.node) lineView.node = built.pre
lineView.text.parentNode.replaceChild(built.pre, lineView.text)
lineView.text = built.pre
if (built.bgClass != lineView.bgClass || built.textClass != lineView.textClass) {
lineView.bgClass = built.bgClass
lineView.textClass = built.textClass
updateLineClasses(lineView)
} else if (cls) {
lineView.text.className = cls
}
}
function updateLineClasses(lineView) {
updateLineBackground(lineView)
if (lineView.line.wrapClass)
ensureLineWrapped(lineView).className = lineView.line.wrapClass
else if (lineView.node != lineView.text)
lineView.node.className = ""
let textClass = lineView.textClass ? lineView.textClass + " " + (lineView.line.textClass || "") : lineView.line.textClass
lineView.text.className = textClass || ""
}
function updateLineGutter(cm, lineView, lineN, dims) {
if (lineView.gutter) {
lineView.node.removeChild(lineView.gutter)
lineView.gutter = null
}
if (lineView.gutterBackground) {
lineView.node.removeChild(lineView.gutterBackground)
lineView.gutterBackground = null
}
if (lineView.line.gutterClass) {
let wrap = ensureLineWrapped(lineView)
lineView.gutterBackground = elt("div", null, "CodeMirror-gutter-background " + lineView.line.gutterClass,
`left: ${cm.options.fixedGutter ? dims.fixedPos : -dims.gutterTotalWidth}px; width: ${dims.gutterTotalWidth}px`)
wrap.insertBefore(lineView.gutterBackground, lineView.text)
}
let markers = lineView.line.gutterMarkers
if (cm.options.lineNumbers || markers) {
let wrap = ensureLineWrapped(lineView)
let gutterWrap = lineView.gutter = elt("div", null, "CodeMirror-gutter-wrapper", `left: ${cm.options.fixedGutter ? dims.fixedPos : -dims.gutterTotalWidth}px`)
cm.display.input.setUneditable(gutterWrap)
wrap.insertBefore(gutterWrap, lineView.text)
if (lineView.line.gutterClass)
gutterWrap.className += " " + lineView.line.gutterClass
if (cm.options.lineNumbers && (!markers || !markers["CodeMirror-linenumbers"]))
lineView.lineNumber = gutterWrap.appendChild(
elt("div", lineNumberFor(cm.options, lineN),
"CodeMirror-linenumber CodeMirror-gutter-elt",
`left: ${dims.gutterLeft["CodeMirror-linenumbers"]}px; width: ${cm.display.lineNumInnerWidth}px`))
if (markers) for (let k = 0; k < cm.options.gutters.length; ++k) {
let id = cm.options.gutters[k], found = markers.hasOwnProperty(id) && markers[id]
if (found)
gutterWrap.appendChild(elt("div", [found], "CodeMirror-gutter-elt",
`left: ${dims.gutterLeft[id]}px; width: ${dims.gutterWidth[id]}px`))
}
}
}
function updateLineWidgets(cm, lineView, dims) {
if (lineView.alignable) lineView.alignable = null
for (let node = lineView.node.firstChild, next; node; node = next) {
next = node.nextSibling
if (node.className == "CodeMirror-linewidget")
lineView.node.removeChild(node)
}
insertLineWidgets(cm, lineView, dims)
}
// Build a line's DOM representation from scratch
export function buildLineElement(cm, lineView, lineN, dims) {
let built = getLineContent(cm, lineView)
lineView.text = lineView.node = built.pre
if (built.bgClass) lineView.bgClass = built.bgClass
if (built.textClass) lineView.textClass = built.textClass
updateLineClasses(lineView)
updateLineGutter(cm, lineView, lineN, dims)
insertLineWidgets(cm, lineView, dims)
return lineView.node
}
// A lineView may contain multiple logical lines (when merged by
// collapsed spans). The widgets for all of them need to be drawn.
function insertLineWidgets(cm, lineView, dims) {
insertLineWidgetsFor(cm, lineView.line, lineView, dims, true)
if (lineView.rest) for (let i = 0; i < lineView.rest.length; i++)
insertLineWidgetsFor(cm, lineView.rest[i], lineView, dims, false)
}
function insertLineWidgetsFor(cm, line, lineView, dims, allowAbove) {
if (!line.widgets) return
let wrap = ensureLineWrapped(lineView)
for (let i = 0, ws = line.widgets; i < ws.length; ++i) {
let widget = ws[i], node = elt("div", [widget.node], "CodeMirror-linewidget")
if (!widget.handleMouseEvents) node.setAttribute("cm-ignore-events", "true")
positionLineWidget(widget, node, lineView, dims)
cm.display.input.setUneditable(node)
if (allowAbove && widget.above)
wrap.insertBefore(node, lineView.gutter || lineView.text)
else
wrap.appendChild(node)
signalLater(widget, "redraw")
}
}
function positionLineWidget(widget, node, lineView, dims) {
if (widget.noHScroll) {
;(lineView.alignable || (lineView.alignable = [])).push(node)
let width = dims.wrapperWidth
node.style.left = dims.fixedPos + "px"
if (!widget.coverGutter) {
width -= dims.gutterTotalWidth
node.style.paddingLeft = dims.gutterTotalWidth + "px"
}
node.style.width = width + "px"
}
if (widget.coverGutter) {
node.style.zIndex = 5
node.style.position = "relative"
if (!widget.noHScroll) node.style.marginLeft = -dims.gutterTotalWidth + "px"
}
}
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="File" module="OFS.Image"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_Cacheable__manager_id</string> </key>
<value> <string>http_cache</string> </value>
</item>
<item>
<key> <string>__name__</string> </key>
<value> <string>update_line.js</string> </value>
</item>
<item>
<key> <string>content_type</string> </key>
<value> <string>application/javascript</string> </value>
</item>
<item>
<key> <string>precondition</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
import { heightAtLine } from "../line/spans"
import { getLine, lineAtHeight, updateLineHeight } from "../line/utils_line"
import { paddingTop, textHeight } from "../measurement/position_measurement"
import { ie, ie_version } from "../util/browser"
// Read the actual heights of the rendered lines, and update their
// stored heights to match.
export function updateHeightsInViewport(cm) {
let display = cm.display
let prevBottom = display.lineDiv.offsetTop
for (let i = 0; i < display.view.length; i++) {
let cur = display.view[i], height
if (cur.hidden) continue
if (ie && ie_version < 8) {
let bot = cur.node.offsetTop + cur.node.offsetHeight
height = bot - prevBottom
prevBottom = bot
} else {
let box = cur.node.getBoundingClientRect()
height = box.bottom - box.top
}
let diff = cur.line.height - height
if (height < 2) height = textHeight(display)
if (diff > .001 || diff < -.001) {
updateLineHeight(cur.line, height)
updateWidgetHeight(cur.line)
if (cur.rest) for (let j = 0; j < cur.rest.length; j++)
updateWidgetHeight(cur.rest[j])
}
}
}
// Read and store the height of line widgets associated with the
// given line.
function updateWidgetHeight(line) {
if (line.widgets) for (let i = 0; i < line.widgets.length; ++i)
line.widgets[i].height = line.widgets[i].node.parentNode.offsetHeight
}
// Compute the lines that are visible in a given viewport (defaults
// the the current scroll position). viewport may contain top,
// height, and ensure (see op.scrollToPos) properties.
export function visibleLines(display, doc, viewport) {
let top = viewport && viewport.top != null ? Math.max(0, viewport.top) : display.scroller.scrollTop
top = Math.floor(top - paddingTop(display))
let bottom = viewport && viewport.bottom != null ? viewport.bottom : top + display.wrapper.clientHeight
let from = lineAtHeight(doc, top), to = lineAtHeight(doc, bottom)
// Ensure is a {from: {line, ch}, to: {line, ch}} object, and
// forces those lines into the viewport (if possible).
if (viewport && viewport.ensure) {
let ensureFrom = viewport.ensure.from.line, ensureTo = viewport.ensure.to.line
if (ensureFrom < from) {
from = ensureFrom
to = lineAtHeight(doc, heightAtLine(getLine(doc, ensureFrom)) + display.wrapper.clientHeight)
} else if (Math.min(ensureTo, doc.lastLine()) >= to) {
from = lineAtHeight(doc, heightAtLine(getLine(doc, ensureTo)) - display.wrapper.clientHeight)
to = ensureTo
}
}
return {from: from, to: Math.max(to, from + 1)}
}
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="File" module="OFS.Image"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_Cacheable__manager_id</string> </key>
<value> <string>http_cache</string> </value>
</item>
<item>
<key> <string>__name__</string> </key>
<value> <string>update_lines.js</string> </value>
</item>
<item>
<key> <string>content_type</string> </key>
<value> <string>application/javascript</string> </value>
</item>
<item>
<key> <string>precondition</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
import { buildViewArray } from "../line/line_data"
import { sawCollapsedSpans } from "../line/saw_special_spans"
import { visualLineEndNo, visualLineNo } from "../line/spans"
import { findViewIndex } from "../measurement/position_measurement"
import { indexOf } from "../util/misc"
// Updates the display.view data structure for a given change to the
// document. From and to are in pre-change coordinates. Lendiff is
// the amount of lines added or subtracted by the change. This is
// used for changes that span multiple lines, or change the way
// lines are divided into visual lines. regLineChange (below)
// registers single-line changes.
export function regChange(cm, from, to, lendiff) {
if (from == null) from = cm.doc.first
if (to == null) to = cm.doc.first + cm.doc.size
if (!lendiff) lendiff = 0
let display = cm.display
if (lendiff && to < display.viewTo &&
(display.updateLineNumbers == null || display.updateLineNumbers > from))
display.updateLineNumbers = from
cm.curOp.viewChanged = true
if (from >= display.viewTo) { // Change after
if (sawCollapsedSpans && visualLineNo(cm.doc, from) < display.viewTo)
resetView(cm)
} else if (to <= display.viewFrom) { // Change before
if (sawCollapsedSpans && visualLineEndNo(cm.doc, to + lendiff) > display.viewFrom) {
resetView(cm)
} else {
display.viewFrom += lendiff
display.viewTo += lendiff
}
} else if (from <= display.viewFrom && to >= display.viewTo) { // Full overlap
resetView(cm)
} else if (from <= display.viewFrom) { // Top overlap
let cut = viewCuttingPoint(cm, to, to + lendiff, 1)
if (cut) {
display.view = display.view.slice(cut.index)
display.viewFrom = cut.lineN
display.viewTo += lendiff
} else {
resetView(cm)
}
} else if (to >= display.viewTo) { // Bottom overlap
let cut = viewCuttingPoint(cm, from, from, -1)
if (cut) {
display.view = display.view.slice(0, cut.index)
display.viewTo = cut.lineN
} else {
resetView(cm)
}
} else { // Gap in the middle
let cutTop = viewCuttingPoint(cm, from, from, -1)
let cutBot = viewCuttingPoint(cm, to, to + lendiff, 1)
if (cutTop && cutBot) {
display.view = display.view.slice(0, cutTop.index)
.concat(buildViewArray(cm, cutTop.lineN, cutBot.lineN))
.concat(display.view.slice(cutBot.index))
display.viewTo += lendiff
} else {
resetView(cm)
}
}
let ext = display.externalMeasured
if (ext) {
if (to < ext.lineN)
ext.lineN += lendiff
else if (from < ext.lineN + ext.size)
display.externalMeasured = null
}
}
// Register a change to a single line. Type must be one of "text",
// "gutter", "class", "widget"
export function regLineChange(cm, line, type) {
cm.curOp.viewChanged = true
let display = cm.display, ext = cm.display.externalMeasured
if (ext && line >= ext.lineN && line < ext.lineN + ext.size)
display.externalMeasured = null
if (line < display.viewFrom || line >= display.viewTo) return
let lineView = display.view[findViewIndex(cm, line)]
if (lineView.node == null) return
let arr = lineView.changes || (lineView.changes = [])
if (indexOf(arr, type) == -1) arr.push(type)
}
// Clear the view.
export function resetView(cm) {
cm.display.viewFrom = cm.display.viewTo = cm.doc.first
cm.display.view = []
cm.display.viewOffset = 0
}
function viewCuttingPoint(cm, oldN, newN, dir) {
let index = findViewIndex(cm, oldN), diff, view = cm.display.view
if (!sawCollapsedSpans || newN == cm.doc.first + cm.doc.size)
return {index: index, lineN: newN}
let n = cm.display.viewFrom
for (let i = 0; i < index; i++)
n += view[i].size
if (n != oldN) {
if (dir > 0) {
if (index == view.length - 1) return null
diff = (n + view[index].size) - oldN
index++
} else {
diff = n - oldN
}
oldN += diff; newN += diff
}
while (visualLineNo(cm.doc, newN) != newN) {
if (index == (dir < 0 ? 0 : view.length - 1)) return null
newN += dir * view[index - (dir < 0 ? 1 : 0)].size
index += dir
}
return {index: index, lineN: newN}
}
// Force the view to cover a given range, adding empty view element
// or clipping off existing ones as needed.
export function adjustView(cm, from, to) {
let display = cm.display, view = display.view
if (view.length == 0 || from >= display.viewTo || to <= display.viewFrom) {
display.view = buildViewArray(cm, from, to)
display.viewFrom = from
} else {
if (display.viewFrom > from)
display.view = buildViewArray(cm, from, display.viewFrom).concat(display.view)
else if (display.viewFrom < from)
display.view = display.view.slice(findViewIndex(cm, from))
display.viewFrom = from
if (display.viewTo < to)
display.view = display.view.concat(buildViewArray(cm, display.viewTo, to))
else if (display.viewTo > to)
display.view = display.view.slice(0, findViewIndex(cm, to))
}
display.viewTo = to
}
// Count the number of lines in the view whose DOM representation is
// out of date (or nonexistent).
export function countDirtyView(cm) {
let view = cm.display.view, dirty = 0
for (let i = 0; i < view.length; i++) {
let lineView = view[i]
if (!lineView.hidden && (!lineView.node || lineView.changes)) ++dirty
}
return dirty
}
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="File" module="OFS.Image"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_Cacheable__manager_id</string> </key>
<value> <string>http_cache</string> </value>
</item>
<item>
<key> <string>__name__</string> </key>
<value> <string>view_tracking.js</string> </value>
</item>
<item>
<key> <string>content_type</string> </key>
<value> <string>application/javascript</string> </value>
</item>
<item>
<key> <string>precondition</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Folder" module="OFS.Folder"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_objects</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>edit</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
import { Display } from "../display/Display"
import { onFocus, onBlur } from "../display/focus"
import { setGuttersForLineNumbers, updateGutters } from "../display/gutters"
import { maybeUpdateLineNumberWidth } from "../display/line_numbers"
import { endOperation, operation, startOperation } from "../display/operations"
import { initScrollbars } from "../display/scrollbars"
import { onScrollWheel, setScrollLeft, setScrollTop } from "../display/scroll_events"
import { clipPos, Pos } from "../line/pos"
import { posFromMouse } from "../measurement/position_measurement"
import { eventInWidget } from "../measurement/widgets"
import Doc from "../model/Doc"
import { attachDoc } from "../model/document_data"
import { Range } from "../model/selection"
import { extendSelection } from "../model/selection_updates"
import { captureRightClick, ie, ie_version, mobile, webkit } from "../util/browser"
import { e_preventDefault, e_stop, on, signal, signalDOMEvent } from "../util/event"
import { bind, copyObj, Delayed } from "../util/misc"
import { clearDragCursor, onDragOver, onDragStart, onDrop } from "./drop_events"
import { ensureGlobalHandlers } from "./global_events"
import { onKeyDown, onKeyPress, onKeyUp } from "./key_events"
import { clickInGutter, onContextMenu, onMouseDown } from "./mouse_events"
import { themeChanged } from "./utils"
import { defaults, optionHandlers, Init } from "./options"
// A CodeMirror instance represents an editor. This is the object
// that user code is usually dealing with.
export function CodeMirror(place, options) {
if (!(this instanceof CodeMirror)) return new CodeMirror(place, options)
this.options = options = options ? copyObj(options) : {}
// Determine effective options based on given values and defaults.
copyObj(defaults, options, false)
setGuttersForLineNumbers(options)
let doc = options.value
if (typeof doc == "string") doc = new Doc(doc, options.mode, null, options.lineSeparator)
this.doc = doc
let input = new CodeMirror.inputStyles[options.inputStyle](this)
let display = this.display = new Display(place, doc, input)
display.wrapper.CodeMirror = this
updateGutters(this)
themeChanged(this)
if (options.lineWrapping)
this.display.wrapper.className += " CodeMirror-wrap"
initScrollbars(this)
this.state = {
keyMaps: [], // stores maps added by addKeyMap
overlays: [], // highlighting overlays, as added by addOverlay
modeGen: 0, // bumped when mode/overlay changes, used to invalidate highlighting info
overwrite: false,
delayingBlurEvent: false,
focused: false,
suppressEdits: false, // used to disable editing during key handlers when in readOnly mode
pasteIncoming: false, cutIncoming: false, // help recognize paste/cut edits in input.poll
selectingText: false,
draggingText: false,
highlight: new Delayed(), // stores highlight worker timeout
keySeq: null, // Unfinished key sequence
specialChars: null
}
if (options.autofocus && !mobile) display.input.focus()
// Override magic textarea content restore that IE sometimes does
// on our hidden textarea on reload
if (ie && ie_version < 11) setTimeout(() => this.display.input.reset(true), 20)
registerEventHandlers(this)
ensureGlobalHandlers()
startOperation(this)
this.curOp.forceUpdate = true
attachDoc(this, doc)
if ((options.autofocus && !mobile) || this.hasFocus())
setTimeout(bind(onFocus, this), 20)
else
onBlur(this)
for (let opt in optionHandlers) if (optionHandlers.hasOwnProperty(opt))
optionHandlers[opt](this, options[opt], Init)
maybeUpdateLineNumberWidth(this)
if (options.finishInit) options.finishInit(this)
for (let i = 0; i < initHooks.length; ++i) initHooks[i](this)
endOperation(this)
// Suppress optimizelegibility in Webkit, since it breaks text
// measuring on line wrapping boundaries.
if (webkit && options.lineWrapping &&
getComputedStyle(display.lineDiv).textRendering == "optimizelegibility")
display.lineDiv.style.textRendering = "auto"
}
// The default configuration options.
CodeMirror.defaults = defaults
// Functions to run when options are changed.
CodeMirror.optionHandlers = optionHandlers
export default CodeMirror
// Attach the necessary event handlers when initializing the editor
function registerEventHandlers(cm) {
let d = cm.display
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, e => {
if (signalDOMEvent(cm, e)) return
let pos = posFromMouse(cm, e)
if (!pos || clickInGutter(cm, e) || eventInWidget(cm.display, e)) return
e_preventDefault(e)
let word = cm.findWordAt(pos)
extendSelection(cm.doc, word.anchor, word.head)
}))
else
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", 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(() => d.activeTouch = null, 1000)
prevTouch = d.activeTouch
prevTouch.end = +new Date
}
}
function isMouseLikeTouchEvent(e) {
if (e.touches.length != 1) return false
let touch = e.touches[0]
return touch.radiusX <= 1 && touch.radiusY <= 1
}
function farAway(touch, other) {
if (other.left == null) return true
let dx = other.left - touch.left, dy = other.top - touch.top
return dx * dx + dy * dy > 20 * 20
}
on(d.scroller, "touchstart", e => {
if (!signalDOMEvent(cm, e) && !isMouseLikeTouchEvent(e)) {
d.input.ensurePolled()
clearTimeout(touchFinished)
let now = +new Date
d.activeTouch = {start: now, moved: false,
prev: now - prevTouch.end <= 300 ? prevTouch : null}
if (e.touches.length == 1) {
d.activeTouch.left = e.touches[0].pageX
d.activeTouch.top = e.touches[0].pageY
}
}
})
on(d.scroller, "touchmove", () => {
if (d.activeTouch) d.activeTouch.moved = true
})
on(d.scroller, "touchend", e => {
let touch = d.activeTouch
if (touch && !eventInWidget(d, e) && touch.left != null &&
!touch.moved && new Date - touch.start < 300) {
let pos = cm.coordsChar(d.activeTouch, "page"), range
if (!touch.prev || farAway(touch, touch.prev)) // Single tap
range = new Range(pos, pos)
else if (!touch.prev.prev || farAway(touch, touch.prev.prev)) // Double tap
range = cm.findWordAt(pos)
else // Triple tap
range = new Range(Pos(pos.line, 0), clipPos(cm.doc, Pos(pos.line + 1, 0)))
cm.setSelection(range.anchor, range.head)
cm.focus()
e_preventDefault(e)
}
finishTouch()
})
on(d.scroller, "touchcancel", finishTouch)
// Sync scrolling between fake scrollbars and real scrollable
// area, ensure viewport is updated when scrolling.
on(d.scroller, "scroll", () => {
if (d.scroller.clientHeight) {
setScrollTop(cm, d.scroller.scrollTop)
setScrollLeft(cm, d.scroller.scrollLeft, true)
signal(cm, "scroll", cm)
}
})
// Listen to wheel events in order to try and update the viewport on time.
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", () => d.wrapper.scrollTop = d.wrapper.scrollLeft = 0)
d.dragFunctions = {
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: e => {if (!signalDOMEvent(cm, e)) { clearDragCursor(cm) }}
}
let inp = d.input.getField()
on(inp, "keyup", e => onKeyUp.call(cm, e))
on(inp, "keydown", operation(cm, onKeyDown))
on(inp, "keypress", operation(cm, onKeyPress))
on(inp, "focus", e => onFocus(cm, e))
on(inp, "blur", e => onBlur(cm, e))
}
let initHooks = []
CodeMirror.defineInitHook = f => initHooks.push(f)
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="File" module="OFS.Image"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_Cacheable__manager_id</string> </key>
<value> <string>http_cache</string> </value>
</item>
<item>
<key> <string>__name__</string> </key>
<value> <string>CodeMirror.js</string> </value>
</item>
<item>
<key> <string>content_type</string> </key>
<value> <string>application/javascript</string> </value>
</item>
<item>
<key> <string>precondition</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
import { deleteNearSelection } from "./deleteNearSelection"
import { runInOp } from "../display/operations"
import { ensureCursorVisible } from "../display/scrolling"
import { endOfLine } from "../input/movement"
import { clipPos, Pos } from "../line/pos"
import { visualLine, visualLineEnd } from "../line/spans"
import { getLine, lineNo } from "../line/utils_line"
import { Range } from "../model/selection"
import { selectAll } from "../model/selection_updates"
import { countColumn, sel_dontScroll, sel_move, spaceStr } from "../util/misc"
import { getOrder } from "../util/bidi"
// Commands are parameter-less actions that can be performed on an
// editor, mostly used for keybindings.
export let commands = {
selectAll: selectAll,
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()
let col = countColumn(cm.getLine(pos.line), pos.ch, tabSize)
spaces.push(spaceStr(tabSize - col % tabSize))
}
cm.replaceSelections(spaces)
},
defaultTab: cm => {
if (cm.somethingSelected()) cm.indentSelection("add")
else cm.execCommand("insertTab")
},
// Swap the two chars left and right of each selection's head.
// Move cursor behind the two swapped characters afterwards.
//
// Doesn't consider line feeds a character.
// Doesn't scan more than one line above to find a character.
// Doesn't do anything on an empty line.
// Doesn't do anything with non-empty selections.
transposeChars: cm => runInOp(cm, () => {
let ranges = cm.listSelections(), newSel = []
for (let i = 0; i < ranges.length; i++) {
if (!ranges[i].empty()) continue
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) {
cur = new Pos(cur.line, 1)
cm.replaceRange(line.charAt(0) + cm.doc.lineSeparator() +
prev.charAt(prev.length - 1),
Pos(cur.line - 1, prev.length - 1), cur, "+transpose")
}
}
}
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()
}
function lineStart(cm, lineN) {
let line = getLine(cm.doc, lineN)
let visual = visualLine(line)
if (visual != line) lineN = lineNo(visual)
return endOfLine(true, cm, visual, lineN, 1)
}
function lineEnd(cm, lineN) {
let line = getLine(cm.doc, lineN)
let visual = visualLineEnd(line)
if (visual != line) lineN = lineNo(visual)
return endOfLine(true, cm, line, lineN, -1)
}
function lineStartSmart(cm, pos) {
let start = lineStart(cm, pos.line)
let line = getLine(cm.doc, start.line)
let order = getOrder(line)
if (!order || order[0].level == 0) {
let firstNonWS = Math.max(0, line.text.search(/\S/))
let inWS = pos.line == start.line && pos.ch <= firstNonWS && pos.ch
return Pos(start.line, inWS ? 0 : firstNonWS, start.sticky)
}
return start
}
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="File" module="OFS.Image"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_Cacheable__manager_id</string> </key>
<value> <string>http_cache</string> </value>
</item>
<item>
<key> <string>__name__</string> </key>
<value> <string>commands.js</string> </value>
</item>
<item>
<key> <string>content_type</string> </key>
<value> <string>application/javascript</string> </value>
</item>
<item>
<key> <string>precondition</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
import { runInOp } from "../display/operations"
import { ensureCursorVisible } from "../display/scrolling"
import { cmp } from "../line/pos"
import { replaceRange } from "../model/changes"
import { lst } from "../util/misc"
// Helper for deleting text near the selection(s), used to implement
// backspace, delete, and similar functionality.
export function deleteNearSelection(cm, compute) {
let ranges = cm.doc.sel.ranges, kill = []
// Build up a set of ranges to kill first, merging overlapping
// ranges.
for (let i = 0; i < ranges.length; i++) {
let toKill = compute(ranges[i])
while (kill.length && cmp(toKill.from, lst(kill).to) <= 0) {
let replaced = kill.pop()
if (cmp(replaced.from, toKill.from) < 0) {
toKill.from = replaced.from
break
}
}
kill.push(toKill)
}
// Next, remove those actual ranges.
runInOp(cm, () => {
for (let i = kill.length - 1; i >= 0; i--)
replaceRange(cm.doc, "", kill[i].from, kill[i].to, "+delete")
ensureCursorVisible(cm)
})
}
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="File" module="OFS.Image"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_Cacheable__manager_id</string> </key>
<value> <string>http_cache</string> </value>
</item>
<item>
<key> <string>__name__</string> </key>
<value> <string>deleteNearSelection.js</string> </value>
</item>
<item>
<key> <string>content_type</string> </key>
<value> <string>application/javascript</string> </value>
</item>
<item>
<key> <string>precondition</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
import { drawSelectionCursor } from "../display/selection"
import { operation } from "../display/operations"
import { clipPos } from "../line/pos"
import { posFromMouse } from "../measurement/position_measurement"
import { eventInWidget } from "../measurement/widgets"
import { makeChange, replaceRange } from "../model/changes"
import { changeEnd } from "../model/change_measurement"
import { simpleSelection } from "../model/selection"
import { setSelectionNoUndo, setSelectionReplaceHistory } from "../model/selection_updates"
import { ie, presto, safari } from "../util/browser"
import { elt, removeChildrenAndAdd } from "../util/dom"
import { e_preventDefault, e_stop, signalDOMEvent } from "../util/event"
import { indexOf } from "../util/misc"
// Kludge to work around strange IE behavior where it'll sometimes
// re-fire a series of drag-related events right after the drop (#1551)
let lastDrop = 0
export function onDrop(e) {
let cm = this
clearDragCursor(cm)
if (signalDOMEvent(cm, e) || eventInWidget(cm.display, e))
return
e_preventDefault(e)
if (ie) lastDrop = +new Date
let pos = posFromMouse(cm, e, true), files = e.dataTransfer.files
if (!pos || cm.isReadOnly()) return
// Might be a file drop, in which case we simply extract the text
// and insert it.
if (files && files.length && window.FileReader && window.File) {
let n = files.length, text = Array(n), read = 0
let loadFile = (file, i) => {
if (cm.options.allowDropFileTypes &&
indexOf(cm.options.allowDropFileTypes, file.type) == -1)
return
let reader = new FileReader
reader.onload = operation(cm, () => {
let content = reader.result
if (/[\x00-\x08\x0e-\x1f]{2}/.test(content)) content = ""
text[i] = content
if (++read == n) {
pos = clipPos(cm.doc, pos)
let change = {from: pos, to: pos,
text: cm.doc.splitLines(text.join(cm.doc.lineSeparator())),
origin: "paste"}
makeChange(cm.doc, change)
setSelectionReplaceHistory(cm.doc, simpleSelection(pos, changeEnd(change)))
}
})
reader.readAsText(file)
}
for (let i = 0; i < n; ++i) loadFile(files[i], i)
} else { // Normal drop
// Don't do a replace if the drop happened inside of the selected text.
if (cm.state.draggingText && cm.doc.sel.contains(pos) > -1) {
cm.state.draggingText(e)
// Ensure the editor is re-focused
setTimeout(() => cm.display.input.focus(), 20)
return
}
try {
let text = e.dataTransfer.getData("Text")
if (text) {
let selected
if (cm.state.draggingText && !cm.state.draggingText.copy)
selected = cm.listSelections()
setSelectionNoUndo(cm.doc, simpleSelection(pos, pos))
if (selected) for (let i = 0; i < selected.length; ++i)
replaceRange(cm.doc, "", selected[i].anchor, selected[i].head, "drag")
cm.replaceSelection(text, "around", "paste")
cm.display.input.focus()
}
}
catch(e){}
}
}
export function onDragStart(cm, e) {
if (ie && (!cm.state.draggingText || +new Date - lastDrop < 100)) { e_stop(e); return }
if (signalDOMEvent(cm, e) || eventInWidget(cm.display, e)) return
e.dataTransfer.setData("Text", cm.getSelection())
e.dataTransfer.effectAllowed = "copyMove"
// Use dummy image instead of default browsers image.
// Recent Safari (~6.0.2) have a tendency to segfault when this happens, so we don't do it there.
if (e.dataTransfer.setDragImage && !safari) {
let img = elt("img", null, null, "position: fixed; left: 0; top: 0;")
img.src = "data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw=="
if (presto) {
img.width = img.height = 1
cm.display.wrapper.appendChild(img)
// Force a relayout, or Opera won't use our image for some obscure reason
img._top = img.offsetTop
}
e.dataTransfer.setDragImage(img, 0, 0)
if (presto) img.parentNode.removeChild(img)
}
}
export function onDragOver(cm, e) {
let pos = posFromMouse(cm, e)
if (!pos) return
let frag = document.createDocumentFragment()
drawSelectionCursor(cm, pos, frag)
if (!cm.display.dragCursor) {
cm.display.dragCursor = elt("div", null, "CodeMirror-cursors CodeMirror-dragcursors")
cm.display.lineSpace.insertBefore(cm.display.dragCursor, cm.display.cursorDiv)
}
removeChildrenAndAdd(cm.display.dragCursor, frag)
}
export function clearDragCursor(cm) {
if (cm.display.dragCursor) {
cm.display.lineSpace.removeChild(cm.display.dragCursor)
cm.display.dragCursor = null
}
}
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="File" module="OFS.Image"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_Cacheable__manager_id</string> </key>
<value> <string>http_cache</string> </value>
</item>
<item>
<key> <string>__name__</string> </key>
<value> <string>drop_events.js</string> </value>
</item>
<item>
<key> <string>content_type</string> </key>
<value> <string>application/javascript</string> </value>
</item>
<item>
<key> <string>precondition</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
import { CodeMirror } from "./CodeMirror"
import { activeElt } from "../util/dom"
import { off, on } from "../util/event"
import { copyObj } from "../util/misc"
export function fromTextArea(textarea, options) {
options = options ? copyObj(options) : {}
options.value = textarea.value
if (!options.tabindex && textarea.tabIndex)
options.tabindex = textarea.tabIndex
if (!options.placeholder && textarea.placeholder)
options.placeholder = textarea.placeholder
// Set autofocus to true if this textarea is focused, or if it has
// autofocus and no other element is focused.
if (options.autofocus == null) {
let hasFocus = activeElt()
options.autofocus = hasFocus == textarea ||
textarea.getAttribute("autofocus") != null && hasFocus == document.body
}
function save() {textarea.value = cm.getValue()}
let realSubmit
if (textarea.form) {
on(textarea.form, "submit", save)
// Deplorable hack to make the submit method do the right thing.
if (!options.leaveSubmitMethodAlone) {
let form = textarea.form
realSubmit = form.submit
try {
let wrappedSubmit = form.submit = () => {
save()
form.submit = realSubmit
form.submit()
form.submit = wrappedSubmit
}
} catch(e) {}
}
}
options.finishInit = cm => {
cm.save = save
cm.getTextArea = () => textarea
cm.toTextArea = () => {
cm.toTextArea = isNaN // Prevent this from being ran twice
save()
textarea.parentNode.removeChild(cm.getWrapperElement())
textarea.style.display = ""
if (textarea.form) {
off(textarea.form, "submit", save)
if (typeof textarea.form.submit == "function")
textarea.form.submit = realSubmit
}
}
}
textarea.style.display = "none"
let cm = CodeMirror(node => textarea.parentNode.insertBefore(node, textarea.nextSibling),
options)
return cm
}
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="File" module="OFS.Image"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_Cacheable__manager_id</string> </key>
<value> <string>http_cache</string> </value>
</item>
<item>
<key> <string>__name__</string> </key>
<value> <string>fromTextArea.js</string> </value>
</item>
<item>
<key> <string>content_type</string> </key>
<value> <string>application/javascript</string> </value>
</item>
<item>
<key> <string>precondition</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
import { onBlur } from "../display/focus"
import { on } from "../util/event"
// These must be handled carefully, because naively registering a
// handler for each editor will cause the editors to never be
// garbage collected.
function forEachCodeMirror(f) {
if (!document.body.getElementsByClassName) return
let byClass = document.body.getElementsByClassName("CodeMirror")
for (let i = 0; i < byClass.length; i++) {
let cm = byClass[i].CodeMirror
if (cm) f(cm)
}
}
let globalsRegistered = false
export function ensureGlobalHandlers() {
if (globalsRegistered) return
registerGlobalHandlers()
globalsRegistered = true
}
function registerGlobalHandlers() {
// When the window resizes, we need to refresh active editors.
let resizeTimer
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", () => forEachCodeMirror(onBlur))
}
// Called when the window resizes
function onResize(cm) {
let d = cm.display
if (d.lastWrapHeight == d.wrapper.clientHeight && d.lastWrapWidth == d.wrapper.clientWidth)
return
// Might be a text scaling operation, clear size caches.
d.cachedCharWidth = d.cachedTextHeight = d.cachedPaddingH = null
d.scrollbarsClipped = false
cm.setSize()
}
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="File" module="OFS.Image"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_Cacheable__manager_id</string> </key>
<value> <string>http_cache</string> </value>
</item>
<item>
<key> <string>__name__</string> </key>
<value> <string>global_events.js</string> </value>
</item>
<item>
<key> <string>content_type</string> </key>
<value> <string>application/javascript</string> </value>
</item>
<item>
<key> <string>precondition</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
import { signalLater } from "../util/operation_group"
import { restartBlink } from "../display/selection"
import { isModifierKey, keyName, lookupKey } from "../input/keymap"
import { eventInWidget } from "../measurement/widgets"
import { ie, ie_version, mac, presto } from "../util/browser"
import { activeElt, addClass, rmClass } from "../util/dom"
import { e_preventDefault, off, on, signalDOMEvent } from "../util/event"
import { hasCopyEvent } from "../util/feature_detection"
import { Delayed, Pass } from "../util/misc"
import { commands } from "./commands"
// Run a handler that was bound to a key.
function doHandleBinding(cm, bound, dropShift) {
if (typeof bound == "string") {
bound = commands[bound]
if (!bound) return false
}
// Ensure previous input has been read, so that the handler sees a
// consistent view of the document
cm.display.input.ensurePolled()
let prevShift = cm.display.shift, done = false
try {
if (cm.isReadOnly()) cm.state.suppressEdits = true
if (dropShift) cm.display.shift = false
done = bound(cm) != Pass
} finally {
cm.display.shift = prevShift
cm.state.suppressEdits = false
}
return done
}
function lookupKeyForEditor(cm, name, handle) {
for (let i = 0; i < cm.state.keyMaps.length; i++) {
let result = lookupKey(name, cm.state.keyMaps[i], handle, cm)
if (result) return result
}
return (cm.options.extraKeys && lookupKey(name, cm.options.extraKeys, handle, cm))
|| lookupKey(name, cm.options.keyMap, handle, cm)
}
let stopSeq = new Delayed
function dispatchKey(cm, name, e, handle) {
let seq = cm.state.keySeq
if (seq) {
if (isModifierKey(name)) return "handled"
stopSeq.set(50, () => {
if (cm.state.keySeq == seq) {
cm.state.keySeq = null
cm.display.input.reset()
}
})
name = seq + " " + name
}
let result = lookupKeyForEditor(cm, name, handle)
if (result == "multi")
cm.state.keySeq = name
if (result == "handled")
signalLater(cm, "keyHandled", cm, name, e)
if (result == "handled" || result == "multi") {
e_preventDefault(e)
restartBlink(cm)
}
if (seq && !result && /\'$/.test(name)) {
e_preventDefault(e)
return true
}
return !!result
}
// Handle a key from the keydown event.
function handleKeyBinding(cm, e) {
let name = keyName(e, true)
if (!name) return false
if (e.shiftKey && !cm.state.keySeq) {
// 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, 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, b => doHandleBinding(cm, b))
}
}
// Handle a key from the keypress event
function handleCharBinding(cm, e, ch) {
return dispatchKey(cm, "'" + ch + "'", e, b => doHandleBinding(cm, b, true))
}
let lastStoppedKey = null
export function onKeyDown(e) {
let cm = this
cm.curOp.focus = activeElt()
if (signalDOMEvent(cm, e)) return
// IE does strange things with escape.
if (ie && ie_version < 11 && e.keyCode == 27) e.returnValue = false
let code = e.keyCode
cm.display.shift = code == 16 || e.shiftKey
let handled = handleKeyBinding(cm, e)
if (presto) {
lastStoppedKey = handled ? code : null
// Opera has no cut event... we try to at least catch the key combo
if (!handled && code == 88 && !hasCopyEvent && (mac ? e.metaKey : e.ctrlKey))
cm.replaceSelection("", null, "cut")
}
// Turn mouse into crosshair when Alt is held on Mac.
if (code == 18 && !/\bCodeMirror-crosshair\b/.test(cm.display.lineDiv.className))
showCrossHair(cm)
}
function showCrossHair(cm) {
let lineDiv = cm.display.lineDiv
addClass(lineDiv, "CodeMirror-crosshair")
function up(e) {
if (e.keyCode == 18 || !e.altKey) {
rmClass(lineDiv, "CodeMirror-crosshair")
off(document, "keyup", up)
off(document, "mouseover", up)
}
}
on(document, "keyup", up)
on(document, "mouseover", up)
}
export function onKeyUp(e) {
if (e.keyCode == 16) this.doc.sel.shift = false
signalDOMEvent(this, e)
}
export function onKeyPress(e) {
let cm = this
if (eventInWidget(cm.display, e) || signalDOMEvent(cm, e) || e.ctrlKey && !e.altKey || mac && e.metaKey) return
let keyCode = e.keyCode, charCode = e.charCode
if (presto && keyCode == lastStoppedKey) {lastStoppedKey = null; e_preventDefault(e); return}
if ((presto && (!e.which || e.which < 10)) && handleKeyBinding(cm, e)) return
let ch = String.fromCharCode(charCode == null ? keyCode : charCode)
// Some browsers fire keypress events for backspace
if (ch == "\x08") return
if (handleCharBinding(cm, e, ch)) return
cm.display.input.onKeyPress(e)
}
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="File" module="OFS.Image"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_Cacheable__manager_id</string> </key>
<value> <string>http_cache</string> </value>
</item>
<item>
<key> <string>__name__</string> </key>
<value> <string>key_events.js</string> </value>
</item>
<item>
<key> <string>content_type</string> </key>
<value> <string>application/javascript</string> </value>
</item>
<item>
<key> <string>precondition</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
import { scrollbarModel } from "../display/scrollbars"
import { wheelEventPixels } from "../display/scroll_events"
import { keyMap, keyName, isModifierKey, lookupKey, normalizeKeyMap } from "../input/keymap"
import { keyNames } from "../input/keynames"
import { Line } from "../line/line_data"
import { cmp, Pos } from "../line/pos"
import { changeEnd } from "../model/change_measurement"
import Doc from "../model/Doc"
import { LineWidget } from "../model/line_widget"
import { SharedTextMarker, TextMarker } from "../model/mark_text"
import { copyState, extendMode, getMode, innerMode, mimeModes, modeExtensions, modes, resolveMode, startState } from "../modes"
import { addClass, contains, rmClass } from "../util/dom"
import { e_preventDefault, e_stop, e_stopPropagation, off, on, signal } from "../util/event"
import { splitLinesAuto } from "../util/feature_detection"
import { countColumn, findColumn, isWordCharBasic, Pass } from "../util/misc"
import StringStream from "../util/StringStream"
import { commands } from "./commands"
export function addLegacyProps(CodeMirror) {
CodeMirror.off = off
CodeMirror.on = on
CodeMirror.wheelEventPixels = wheelEventPixels
CodeMirror.Doc = Doc
CodeMirror.splitLines = splitLinesAuto
CodeMirror.countColumn = countColumn
CodeMirror.findColumn = findColumn
CodeMirror.isWordChar = isWordCharBasic
CodeMirror.Pass = Pass
CodeMirror.signal = signal
CodeMirror.Line = Line
CodeMirror.changeEnd = changeEnd
CodeMirror.scrollbarModel = scrollbarModel
CodeMirror.Pos = Pos
CodeMirror.cmpPos = cmp
CodeMirror.modes = modes
CodeMirror.mimeModes = mimeModes
CodeMirror.resolveMode = resolveMode
CodeMirror.getMode = getMode
CodeMirror.modeExtensions = modeExtensions
CodeMirror.extendMode = extendMode
CodeMirror.copyState = copyState
CodeMirror.startState = startState
CodeMirror.innerMode = innerMode
CodeMirror.commands = commands
CodeMirror.keyMap = keyMap
CodeMirror.keyName = keyName
CodeMirror.isModifierKey = isModifierKey
CodeMirror.lookupKey = lookupKey
CodeMirror.normalizeKeyMap = normalizeKeyMap
CodeMirror.StringStream = StringStream
CodeMirror.SharedTextMarker = SharedTextMarker
CodeMirror.TextMarker = TextMarker
CodeMirror.LineWidget = LineWidget
CodeMirror.e_preventDefault = e_preventDefault
CodeMirror.e_stopPropagation = e_stopPropagation
CodeMirror.e_stop = e_stop
CodeMirror.addClass = addClass
CodeMirror.contains = contains
CodeMirror.rmClass = rmClass
CodeMirror.keyNames = keyNames
}
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="File" module="OFS.Image"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_Cacheable__manager_id</string> </key>
<value> <string>http_cache</string> </value>
</item>
<item>
<key> <string>__name__</string> </key>
<value> <string>legacy.js</string> </value>
</item>
<item>
<key> <string>content_type</string> </key>
<value> <string>application/javascript</string> </value>
</item>
<item>
<key> <string>precondition</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
// EDITOR CONSTRUCTOR
import { CodeMirror } from "./CodeMirror"
export { CodeMirror } from "./CodeMirror"
import { eventMixin } from "../util/event"
import { indexOf } from "../util/misc"
import { defineOptions } from "./options"
defineOptions(CodeMirror)
import addEditorMethods from "./methods"
addEditorMethods(CodeMirror)
import Doc from "../model/Doc"
// Set up methods on CodeMirror's prototype to redirect to the editor's document.
let dontDelegate = "iter insert remove copy getEditor constructor".split(" ")
for (let prop in Doc.prototype) if (Doc.prototype.hasOwnProperty(prop) && indexOf(dontDelegate, prop) < 0)
CodeMirror.prototype[prop] = (function(method) {
return function() {return method.apply(this.doc, arguments)}
})(Doc.prototype[prop])
eventMixin(Doc)
// INPUT HANDLING
import ContentEditableInput from "../input/ContentEditableInput"
import TextareaInput from "../input/TextareaInput"
CodeMirror.inputStyles = {"textarea": TextareaInput, "contenteditable": ContentEditableInput}
// MODE DEFINITION AND QUERYING
import { defineMIME, defineMode } from "../modes"
// Extra arguments are stored as the mode's dependencies, which is
// used by (legacy) mechanisms like loadmode.js to automatically
// load a mode. (Preferred mechanism is the require/define calls.)
CodeMirror.defineMode = function(name/*, mode, …*/) {
if (!CodeMirror.defaults.mode && name != "null") CodeMirror.defaults.mode = name
defineMode.apply(this, arguments)
}
CodeMirror.defineMIME = defineMIME
// Minimal default mode.
CodeMirror.defineMode("null", () => ({token: stream => stream.skipToEnd()}))
CodeMirror.defineMIME("text/plain", "null")
// EXTENSIONS
CodeMirror.defineExtension = (name, func) => {
CodeMirror.prototype[name] = func
}
CodeMirror.defineDocExtension = (name, func) => {
Doc.prototype[name] = func
}
import { fromTextArea } from "./fromTextArea"
CodeMirror.fromTextArea = fromTextArea
import { addLegacyProps } from "./legacy"
addLegacyProps(CodeMirror)
CodeMirror.version = "5.24.2"
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="File" module="OFS.Image"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_Cacheable__manager_id</string> </key>
<value> <string>http_cache</string> </value>
</item>
<item>
<key> <string>__name__</string> </key>
<value> <string>main.js</string> </value>
</item>
<item>
<key> <string>content_type</string> </key>
<value> <string>application/javascript</string> </value>
</item>
<item>
<key> <string>precondition</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="File" module="OFS.Image"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_Cacheable__manager_id</string> </key>
<value> <string>http_cache</string> </value>
</item>
<item>
<key> <string>__name__</string> </key>
<value> <string>methods.js</string> </value>
</item>
<item>
<key> <string>content_type</string> </key>
<value> <string>application/javascript</string> </value>
</item>
<item>
<key> <string>precondition</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="File" module="OFS.Image"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_Cacheable__manager_id</string> </key>
<value> <string>http_cache</string> </value>
</item>
<item>
<key> <string>__name__</string> </key>
<value> <string>mouse_events.js</string> </value>
</item>
<item>
<key> <string>content_type</string> </key>
<value> <string>application/javascript</string> </value>
</item>
<item>
<key> <string>precondition</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
import { onBlur } from "../display/focus"
import { setGuttersForLineNumbers, updateGutters } from "../display/gutters"
import { alignHorizontally } from "../display/line_numbers"
import { loadMode, resetModeState } from "../display/mode_state"
import { initScrollbars, updateScrollbars } from "../display/scrollbars"
import { updateSelection } from "../display/selection"
import { regChange } from "../display/view_tracking"
import { getKeyMap } from "../input/keymap"
import { defaultSpecialCharPlaceholder } from "../line/line_data"
import { Pos } from "../line/pos"
import { findMaxLine } from "../line/spans"
import { clearCaches, compensateForHScroll, estimateLineHeights } from "../measurement/position_measurement"
import { replaceRange } from "../model/changes"
import { mobile, windows } from "../util/browser"
import { addClass, rmClass } from "../util/dom"
import { off, on } from "../util/event"
import { themeChanged } from "./utils"
export let Init = {toString: function(){return "CodeMirror.Init"}}
export let defaults = {}
export let optionHandlers = {}
export function defineOptions(CodeMirror) {
let optionHandlers = CodeMirror.optionHandlers
function option(name, deflt, handle, notOnInit) {
CodeMirror.defaults[name] = deflt
if (handle) optionHandlers[name] =
notOnInit ? (cm, val, old) => {if (old != Init) handle(cm, val, old)} : handle
}
CodeMirror.defineOption = option
// Passed to option handlers when there is no old value.
CodeMirror.Init = Init
// These two are, on init, called from the constructor because they
// have to be initialized before the editor can start at all.
option("value", "", (cm, val) => cm.setValue(val), true)
option("mode", null, (cm, val) => {
cm.doc.modeOption = val
loadMode(cm)
}, true)
option("indentUnit", 2, loadMode, true)
option("indentWithTabs", false)
option("smartIndent", true)
option("tabSize", 4, cm => {
resetModeState(cm)
clearCaches(cm)
regChange(cm)
}, true)
option("lineSeparator", null, (cm, val) => {
cm.doc.lineSep = val
if (!val) return
let newBreaks = [], lineNo = cm.doc.first
cm.doc.iter(line => {
for (let pos = 0;;) {
let found = line.text.indexOf(val, pos)
if (found == -1) break
pos = found + val.length
newBreaks.push(Pos(lineNo, found))
}
lineNo++
})
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\u061c\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, cm => cm.refresh(), true)
option("electricChars", true)
option("inputStyle", mobile ? "contenteditable" : "textarea", () => {
throw new Error("inputStyle can not (yet) be changed in a running editor") // FIXME
}, true)
option("spellcheck", false, (cm, val) => cm.getInputField().spellcheck = val, true)
option("rtlMoveVisually", !windows)
option("wholeLineUpdateBefore", true)
option("theme", "default", cm => {
themeChanged(cm)
guttersChanged(cm)
}, true)
option("keyMap", "default", (cm, val, old) => {
let next = getKeyMap(val)
let prev = old != Init && getKeyMap(old)
if (prev && prev.detach) prev.detach(cm, next)
if (next.attach) next.attach(cm, prev || null)
})
option("extraKeys", null)
option("lineWrapping", false, wrappingChanged, true)
option("gutters", [], cm => {
setGuttersForLineNumbers(cm.options)
guttersChanged(cm)
}, true)
option("fixedGutter", true, (cm, val) => {
cm.display.gutters.style.left = val ? compensateForHScroll(cm.display) + "px" : "0"
cm.refresh()
}, true)
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, cm => {
setGuttersForLineNumbers(cm.options)
guttersChanged(cm)
}, true)
option("firstLineNumber", 1, guttersChanged, true)
option("lineNumberFormatter", integer => integer, guttersChanged, true)
option("showCursorWhenSelecting", false, updateSelection, true)
option("resetSelectionOnContextMenu", true)
option("lineWiseCopyCut", true)
option("readOnly", false, (cm, val) => {
if (val == "nocursor") {
onBlur(cm)
cm.display.input.blur()
cm.display.disabled = true
} else {
cm.display.disabled = false
}
cm.display.input.readOnlyChanged(val)
})
option("disableInput", false, (cm, val) => {if (!val) cm.display.input.reset()}, true)
option("dragDrop", true, dragDropChanged)
option("allowDropFileTypes", null)
option("cursorBlinkRate", 530)
option("cursorScrollMargin", 0)
option("cursorHeight", 1, updateSelection, true)
option("singleCursorHeightPerLine", true, updateSelection, true)
option("workTime", 100)
option("workDelay", 100)
option("flattenSpans", true, resetModeState, true)
option("addModeClass", false, resetModeState, true)
option("pollInterval", 100)
option("undoDepth", 200, (cm, val) => cm.doc.history.undoDepth = val)
option("historyEventDelay", 1250)
option("viewportMargin", 10, cm => cm.refresh(), true)
option("maxHighlightLength", 10000, resetModeState, true)
option("moveInputWithCursor", true, (cm, val) => {
if (!val) cm.display.input.resetPosition()
})
option("tabindex", null, (cm, val) => cm.display.input.getField().tabIndex = val || "")
option("autofocus", null)
}
function guttersChanged(cm) {
updateGutters(cm)
regChange(cm)
alignHorizontally(cm)
}
function dragDropChanged(cm, value, old) {
let wasOn = old && old != Init
if (!value != !wasOn) {
let funcs = cm.display.dragFunctions
let toggle = value ? on : off
toggle(cm.display.scroller, "dragstart", funcs.start)
toggle(cm.display.scroller, "dragenter", funcs.enter)
toggle(cm.display.scroller, "dragover", funcs.over)
toggle(cm.display.scroller, "dragleave", funcs.leave)
toggle(cm.display.scroller, "drop", funcs.drop)
}
}
function wrappingChanged(cm) {
if (cm.options.lineWrapping) {
addClass(cm.display.wrapper, "CodeMirror-wrap")
cm.display.sizer.style.minWidth = ""
cm.display.sizerWidth = null
} else {
rmClass(cm.display.wrapper, "CodeMirror-wrap")
findMaxLine(cm)
}
estimateLineHeights(cm)
regChange(cm)
clearCaches(cm)
setTimeout(() => updateScrollbars(cm), 100)
}
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="File" module="OFS.Image"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_Cacheable__manager_id</string> </key>
<value> <string>http_cache</string> </value>
</item>
<item>
<key> <string>__name__</string> </key>
<value> <string>options.js</string> </value>
</item>
<item>
<key> <string>content_type</string> </key>
<value> <string>application/javascript</string> </value>
</item>
<item>
<key> <string>precondition</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
import { clearCaches } from "../measurement/position_measurement"
export function themeChanged(cm) {
cm.display.wrapper.className = cm.display.wrapper.className.replace(/\s*cm-s-\S+/g, "") +
cm.options.theme.replace(/(^|\s)\s*/g, " cm-s-")
clearCaches(cm)
}
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="File" module="OFS.Image"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_Cacheable__manager_id</string> </key>
<value> <string>http_cache</string> </value>
</item>
<item>
<key> <string>__name__</string> </key>
<value> <string>utils.js</string> </value>
</item>
<item>
<key> <string>content_type</string> </key>
<value> <string>application/javascript</string> </value>
</item>
<item>
<key> <string>precondition</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Folder" module="OFS.Folder"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_objects</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>input</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="File" module="OFS.Image"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_Cacheable__manager_id</string> </key>
<value> <string>http_cache</string> </value>
</item>
<item>
<key> <string>__name__</string> </key>
<value> <string>ContentEditableInput.js</string> </value>
</item>
<item>
<key> <string>content_type</string> </key>
<value> <string>application/javascript</string> </value>
</item>
<item>
<key> <string>precondition</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="File" module="OFS.Image"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_Cacheable__manager_id</string> </key>
<value> <string>http_cache</string> </value>
</item>
<item>
<key> <string>__name__</string> </key>
<value> <string>TextareaInput.js</string> </value>
</item>
<item>
<key> <string>content_type</string> </key>
<value> <string>application/javascript</string> </value>
</item>
<item>
<key> <string>precondition</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
import { getStateBefore } from "../line/highlight"
import { Pos } from "../line/pos"
import { getLine } from "../line/utils_line"
import { replaceRange } from "../model/changes"
import { Range } from "../model/selection"
import { replaceOneSelection } from "../model/selection_updates"
import { countColumn, Pass, spaceStr } from "../util/misc"
// Indent the given line. The how parameter can be "smart",
// "add"/null, "subtract", or "prev". When aggressive is false
// (typically set to true for forced single-line indents), empty
// lines are not indented, and places where the mode returns Pass
// are left alone.
export function indentLine(cm, n, how, aggressive) {
let doc = cm.doc, state
if (how == null) how = "add"
if (how == "smart") {
// Fall back to "prev" when the mode doesn't have an indentation
// method.
if (!doc.mode.indent) how = "prev"
else state = getStateBefore(cm, n)
}
let tabSize = cm.options.tabSize
let line = getLine(doc, n), curSpace = countColumn(line.text, null, tabSize)
if (line.stateAfter) line.stateAfter = null
let curSpaceString = line.text.match(/^\s*/)[0], indentation
if (!aggressive && !/\S/.test(line.text)) {
indentation = 0
how = "not"
} else if (how == "smart") {
indentation = doc.mode.indent(state, line.text.slice(curSpaceString.length), line.text)
if (indentation == Pass || indentation > 150) {
if (!aggressive) return
how = "prev"
}
}
if (how == "prev") {
if (n > doc.first) indentation = countColumn(getLine(doc, n-1).text, null, tabSize)
else indentation = 0
} else if (how == "add") {
indentation = curSpace + cm.options.indentUnit
} else if (how == "subtract") {
indentation = curSpace - cm.options.indentUnit
} else if (typeof how == "number") {
indentation = curSpace + how
}
indentation = Math.max(0, indentation)
let indentString = "", pos = 0
if (cm.options.indentWithTabs)
for (let i = Math.floor(indentation / tabSize); i; --i) {pos += tabSize; indentString += "\t"}
if (pos < indentation) indentString += spaceStr(indentation - pos)
if (indentString != curSpaceString) {
replaceRange(doc, indentString, Pos(n, 0), Pos(n, curSpaceString.length), "+input")
line.stateAfter = null
return true
} else {
// Ensure that, if the cursor was in the whitespace at the start
// of the line, it is moved to the end of that space.
for (let i = 0; i < doc.sel.ranges.length; i++) {
let range = doc.sel.ranges[i]
if (range.head.line == n && range.head.ch < curSpaceString.length) {
let pos = Pos(n, curSpaceString.length)
replaceOneSelection(doc, i, new Range(pos, pos))
break
}
}
}
}
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="File" module="OFS.Image"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_Cacheable__manager_id</string> </key>
<value> <string>http_cache</string> </value>
</item>
<item>
<key> <string>__name__</string> </key>
<value> <string>indent.js</string> </value>
</item>
<item>
<key> <string>content_type</string> </key>
<value> <string>application/javascript</string> </value>
</item>
<item>
<key> <string>precondition</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="File" module="OFS.Image"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_Cacheable__manager_id</string> </key>
<value> <string>http_cache</string> </value>
</item>
<item>
<key> <string>__name__</string> </key>
<value> <string>input.js</string> </value>
</item>
<item>
<key> <string>content_type</string> </key>
<value> <string>application/javascript</string> </value>
</item>
<item>
<key> <string>precondition</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="File" module="OFS.Image"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_Cacheable__manager_id</string> </key>
<value> <string>http_cache</string> </value>
</item>
<item>
<key> <string>__name__</string> </key>
<value> <string>keymap.js</string> </value>
</item>
<item>
<key> <string>content_type</string> </key>
<value> <string>application/javascript</string> </value>
</item>
<item>
<key> <string>precondition</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment