General.Web/wwwroot/lib/codemirror-5.31.0/src/input/ContentEditableInput.js

(开头部分) 17KB

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

import { operation, runInOp } from "../display/operations"
import { prepareSelection } from "../display/selection"
import { regChange } from "../display/view_tracking"
import { applyTextInput, copyableRanges, disableBrowserMagic, handlePaste, hiddenTextarea, lastCopied, setLastCopied } from "./input"
import { cmp, maxPos, minPos, Pos } from "../line/pos"
import { getBetween, getLine, lineNo } from "../line/utils_line"
import { findViewForLine, findViewIndex, mapFromLineView, nodeAndOffsetInLineMap } from "../measurement/position_measurement"
import { replaceRange } from "../model/changes"
import { simpleSelection } from "../model/selection"
import { setSelection } from "../model/selection_updates"
import { getBidiPartAt, getOrder } from "../util/bidi"
import { android, chrome, gecko, ie_version } from "../util/browser"
import { contains, range, removeChildrenAndAdd, selectInput } from "../util/dom"
import { on, signalDOMEvent } from "../util/event"
import { Delayed, lst, sel_dontScroll } from "../util/misc"

// CONTENTEDITABLE INPUT STYLE

export default class ContentEditableInput {
  constructor(cm) {
    this.cm = cm
    this.lastAnchorNode = this.lastAnchorOffset = this.lastFocusNode = this.lastFocusOffset = null
    this.polling = new Delayed()
    this.composing = null
    this.gracePeriod = false
    this.readDOMTimeout = null
  }

  init(display) {
    let input = this, cm = input.cm
    let div = input.div = display.lineDiv
    disableBrowserMagic(div, cm.options.spellcheck)

    on(div, "paste", e => {
      if (signalDOMEvent(cm, e) || handlePaste(e, cm)) return
      // IE doesn't fire input events, so we schedule a read for the pasted content in this way
      if (ie_version <= 11) setTimeout(operation(cm, () => this.updateFromDOM()), 20)
    })

    on(div, "compositionstart", e => {
      this.composing = {data: e.data, done: false}
    })
    on(div, "compositionupdate", e => {
      if (!this.composing) this.composing = {data: e.data, done: false}
    })
    on(div, "compositionend", e => {
      if (this.composing) {
        if (e.data != this.composing.data) this.readFromDOMSoon()
        this.composing.done = true
      }
    })

    on(div, "touchstart", () => input.forceCompositionEnd())

    on(div, "input", () => {
      if (!this.composing) this.readFromDOMSoon()
    })

    function onCopyCut(e) {
      if (signalDOMEvent(cm, e)) return
后面还有 457 行代码,解锁后查看完整代码

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

AI 解读

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

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