General.Web/wwwroot/lib/codemirror-5.31.0/src/model/Doc.js

(开头部分) 16KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

import CodeMirror from "../edit/CodeMirror"
import { docMethodOp } from "../display/operations"
import { Line } from "../line/line_data"
import { clipPos, clipPosArray, Pos } from "../line/pos"
import { visualLine } from "../line/spans"
import { getBetween, getLine, getLines, isLine, lineNo } from "../line/utils_line"
import { classTest } from "../util/dom"
import { splitLinesAuto } from "../util/feature_detection"
import { createObj, map, isEmpty, sel_dontScroll } from "../util/misc"
import { ensureCursorVisible, scrollToCoords } from "../display/scrolling"

import { changeLine, makeChange, makeChangeFromHistory, replaceRange } from "./changes"
import { computeReplacedSel } from "./change_measurement"
import { BranchChunk, LeafChunk } from "./chunk"
import { directionChanged, linkedDocs, updateDoc } from "./document_data"
import { copyHistoryArray, History } from "./history"
import { addLineWidget } from "./line_widget"
import { copySharedMarkers, detachSharedMarkers, findSharedMarkers, markText } from "./mark_text"
import { normalizeSelection, Range, simpleSelection } from "./selection"
import { extendSelection, extendSelections, setSelection, setSelectionReplaceHistory, setSimpleSelection } from "./selection_updates"

let nextDocId = 0
let Doc = function(text, mode, firstLine, lineSep, direction) {
  if (!(this instanceof Doc)) return new Doc(text, mode, firstLine, lineSep, direction)
  if (firstLine == null) firstLine = 0

  BranchChunk.call(this, [new LeafChunk([new Line("", null)])])
  this.first = firstLine
  this.scrollTop = this.scrollLeft = 0
  this.cantEdit = false
  this.cleanGeneration = 1
  this.modeFrontier = this.highlightFrontier = firstLine
  let start = Pos(firstLine, 0)
  this.sel = simpleSelection(start)
  this.history = new History(null)
  this.id = ++nextDocId
  this.modeOption = mode
  this.lineSep = lineSep
  this.direction = (direction == "rtl") ? "rtl" : "ltr"
  this.extend = false

  if (typeof text == "string") text = this.splitLines(text)
  updateDoc(this, {from: start, to: start, text: text})
  setSelection(this, simpleSelection(start), sel_dontScroll)
}

Doc.prototype = createObj(BranchChunk.prototype, {
  constructor: Doc,
  // Iterate over the document. Supports two forms -- with only one
  // argument, it calls that for each line in the document. With
  // three, it iterates over the range given by the first two (with
  // the second being non-inclusive).
  iter: function(from, to, op) {
    if (op) this.iterN(from - this.first, to - from, op)
    else this.iterN(this.first, this.first + this.size, from)
  },

  // Non-public interface for adding and removing lines.
  insert: function(at, lines) {
    let height = 0
后面还有 372 行代码,解锁后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明

AI 解读

登录后可用,每次 10 积分,解读结果公开显示在下面。

还没有人解读过这个文件。