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

(开头部分) 2KB

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

import { runInOp } from "../display/operations"
import { addToScrollTop } from "../display/scrolling"
import { regLineChange } from "../display/view_tracking"
import { heightAtLine, lineIsHidden } from "../line/spans"
import { lineNo, updateLineHeight } from "../line/utils_line"
import { widgetHeight } from "../measurement/widgets"
import { changeLine } from "./changes"
import { eventMixin } from "../util/event"
import { signalLater } from "../util/operation_group"

// Line widgets are block elements displayed above or below a line.

export class LineWidget {
  constructor(doc, node, options) {
    if (options) for (let opt in options) if (options.hasOwnProperty(opt))
      this[opt] = options[opt]
    this.doc = doc
    this.node = node
  }

  clear() {
    let cm = this.doc.cm, ws = this.line.widgets, line = this.line, no = lineNo(line)
    if (no == null || !ws) return
    for (let i = 0; i < ws.length; ++i) if (ws[i] == this) ws.splice(i--, 1)
    if (!ws.length) line.widgets = null
    let height = widgetHeight(this)
    updateLineHeight(line, Math.max(0, line.height - height))
    if (cm) {
      runInOp(cm, () => {
        adjustScrollWhenAboveVisible(cm, line, -height)
        regLineChange(cm, no, "widget")
      })
      signalLater(cm, "lineWidgetCleared", cm, this, no)
    }
  }

  changed() {
    let oldH = this.height, cm = this.doc.cm, line = this.line
    this.height = null
    let diff = widgetHeight(this) - oldH
    if (!diff) return
    updateLineHeight(line, line.height + diff)
    if (cm) {
      runInOp(cm, () => {
        cm.curOp.forceUpdate = true
        adjustScrollWhenAboveVisible(cm, line, diff)
        signalLater(cm, "lineWidgetChanged", cm, this, lineNo(line))
      })
    }
  }
}
eventMixin(LineWidget)

function adjustScrollWhenAboveVisible(cm, line, diff) {
  if (heightAtLine(line) < ((cm.curOp && cm.curOp.scrollTop) || cm.doc.scrollTop))
    addToScrollTop(cm, diff)
}

export function addLineWidget(doc, handle, node, options) {
  let widget = new LineWidget(doc, node, options)
后面还有 18 行代码,解锁后查看完整代码

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

AI 解读

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

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