General.Web/wwwroot/lib/codemirror-5.31.0/src/model/selection.js
(开头部分) 2KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
import { cmp, copyPos, equalCursorPos, maxPos, minPos } from "../line/pos"
import { indexOf } from "../util/misc"
// Selection objects are immutable. A new one is created every time
// the selection changes. A selection is one or more non-overlapping
// (and non-touching) ranges, sorted, and an integer that indicates
// which one is the primary selection (the one that's scrolled into
// view, that getCursor returns, etc).
export class Selection {
constructor(ranges, primIndex) {
this.ranges = ranges
this.primIndex = primIndex
}
primary() { return this.ranges[this.primIndex] }
equals(other) {
if (other == this) return true
if (other.primIndex != this.primIndex || other.ranges.length != this.ranges.length) return false
for (let i = 0; i < this.ranges.length; i++) {
let here = this.ranges[i], there = other.ranges[i]
if (!equalCursorPos(here.anchor, there.anchor) || !equalCursorPos(here.head, there.head)) return false
}
return true
}
deepCopy() {
let out = []
for (let i = 0; i < this.ranges.length; i++)
out[i] = new Range(copyPos(this.ranges[i].anchor), copyPos(this.ranges[i].head))
return new Selection(out, this.primIndex)
}
somethingSelected() {
for (let i = 0; i < this.ranges.length; i++)
if (!this.ranges[i].empty()) return true
return false
}
contains(pos, end) {
if (!end) end = pos
for (let i = 0; i < this.ranges.length; i++) {
let range = this.ranges[i]
if (cmp(end, range.from()) >= 0 && cmp(pos, range.to()) <= 0)
return i
}
return -1
}
}
export class Range {
constructor(anchor, head) {
this.anchor = anchor; this.head = head
}
from() { return minPos(this.anchor, this.head) }
to() { return maxPos(this.anchor, this.head) }
empty() { return this.head.line == this.anchor.line && this.head.ch == this.anchor.ch }
}
后面还有 22 行代码,解锁后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明
AI 解读
登录后可用,每次 10 积分,解读结果公开显示在下面。
还没有人解读过这个文件。
