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

(开头部分) 5KB

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

import { runInOp } from "../display/operations"
import { ensureCursorVisible } from "../display/scrolling"
import { Pos } from "../line/pos"
import { getLine } from "../line/utils_line"
import { makeChange } from "../model/changes"
import { ios, webkit } from "../util/browser"
import { elt } from "../util/dom"
import { lst, map } from "../util/misc"
import { signalLater } from "../util/operation_group"
import { splitLinesAuto } from "../util/feature_detection"

import { indentLine } from "./indent"

// This will be set to a {lineWise: bool, text: [string]} object, so
// that, when pasting, we know what kind of selections the copied
// text was made out of.
export let lastCopied = null

export function setLastCopied(newLastCopied) {
  lastCopied = newLastCopied
}

export function applyTextInput(cm, inserted, deleted, sel, origin) {
  let doc = cm.doc
  cm.display.shift = false
  if (!sel) sel = doc.sel

  let paste = cm.state.pasteIncoming || origin == "paste"
  let textLines = splitLinesAuto(inserted), multiPaste = null
  // When pasing N lines into N selections, insert one line per selection
  if (paste && sel.ranges.length > 1) {
    if (lastCopied && lastCopied.text.join("\n") == inserted) {
      if (sel.ranges.length % lastCopied.text.length == 0) {
        multiPaste = []
        for (let i = 0; i < lastCopied.text.length; i++)
          multiPaste.push(doc.splitLines(lastCopied.text[i]))
      }
    } else if (textLines.length == sel.ranges.length && cm.options.pasteLinesPerSelection) {
      multiPaste = map(textLines, l => [l])
    }
  }

  let updateInput
  // Normal behavior is to insert the new text into every selection
  for (let i = sel.ranges.length - 1; i >= 0; i--) {
    let range = sel.ranges[i]
    let from = range.from(), to = range.to()
    if (range.empty()) {
      if (deleted && deleted > 0) // Handle deletion
        from = Pos(from.line, from.ch - deleted)
      else if (cm.state.overwrite && !paste) // Handle overwrite
        to = Pos(to.line, Math.min(getLine(doc, to.line).text.length, to.ch + lst(textLines).length))
      else if (lastCopied && lastCopied.lineWise && lastCopied.text.join("\n") == inserted)
        from = to = Pos(from.line, 0)
    }
    updateInput = cm.curOp.updateInput
    let changeEvent = {from: from, to: to, text: multiPaste ? multiPaste[i % multiPaste.length] : textLines,
                       origin: origin || (paste ? "paste" : cm.state.cutIncoming ? "cut" : "+input")}
    makeChange(cm.doc, changeEvent)
    signalLater(cm, "inputRead", cm, changeEvent)
后面还有 75 行代码,解锁后查看完整代码

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

AI 解读

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

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