Skip to content
This repository was archived by the owner on Apr 16, 2026. It is now read-only.

Commit 3b6c52c

Browse files
author
Alexis DOUALLE
committed
Error thrown when inserting overlapping isolate markers
1 parent 5eb74de commit 3b6c52c

3 files changed

Lines changed: 29 additions & 4 deletions

File tree

src/line/saw_special_spans.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Optimize some code when these features are not used.
2-
export let sawReadOnlySpans = false, sawCollapsedSpans = false
2+
export let sawReadOnlySpans = false, sawCollapsedSpans = false, sawIsolateSpans = false
33

44
export function seeReadOnlySpans() {
55
sawReadOnlySpans = true
@@ -8,3 +8,7 @@ export function seeReadOnlySpans() {
88
export function seeCollapsedSpans() {
99
sawCollapsedSpans = true
1010
}
11+
12+
export function seeIsolateSpans() {
13+
sawIsolateSpans = true
14+
}

src/line/spans.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { indexOf, lst } from "../util/misc.js"
22

33
import { cmp } from "./pos.js"
4-
import { sawCollapsedSpans } from "./saw_special_spans.js"
4+
import { sawCollapsedSpans, sawIsolateSpans } from "./saw_special_spans.js"
55
import { getLine, isLine, lineNo } from "./utils_line.js"
66

77
// TEXTMARKER SPANS
@@ -247,6 +247,21 @@ export function conflictingCollapsedRange(doc, lineNo, from, to, marker) {
247247
}
248248
}
249249

250+
// Test whether two isolate ranges overlap, which is not allowed
251+
export function conflictingIsolateRange(doc, lineNo$$2, from, to, marker) {
252+
let line = getLine(doc, lineNo$$2)
253+
let sis = sawIsolateSpans && line.markedSpans
254+
if (sis) { for (let i = 0; i < sis.length; ++i) {
255+
let si = sis[i]
256+
if (!si.marker.isolate) { continue }
257+
let found = si.marker.find(0)
258+
let fromCmp = cmp(found.from, from) || extraLeft(si.marker) - extraLeft(marker)
259+
if (fromCmp <= 0 && (si.marker.inclusiveRight && marker.inclusiveLeft ? cmp(found.to, from) >= 0 : cmp(found.to, from) > 0) ||
260+
fromCmp >= 0 && (si.marker.inclusiveRight && marker.inclusiveLeft ? cmp(found.from, to) <= 0 : cmp(found.from, to) < 0))
261+
{ return true }
262+
} }
263+
}
264+
250265
// A visual line is a line as drawn on the screen. Folding, for
251266
// example, can cause multiple logical lines to appear on the same
252267
// visual line. This finds the start of the visual line that the

src/model/mark_text.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import { endOperation, operation, runInOp, startOperation } from "../display/ope
44
import { clipPos, cmp, Pos } from "../line/pos.js"
55
import { lineNo, updateLineHeight } from "../line/utils_line.js"
66
import { clearLineMeasurementCacheFor, findViewForLine, textHeight } from "../measurement/position_measurement.js"
7-
import { seeReadOnlySpans, seeCollapsedSpans } from "../line/saw_special_spans.js"
8-
import { addMarkedSpan, conflictingCollapsedRange, getMarkedSpanFor, lineIsHidden, lineLength, MarkedSpan, removeMarkedSpan, visualLine } from "../line/spans.js"
7+
import { seeReadOnlySpans, seeCollapsedSpans, seeIsolateSpans } from "../line/saw_special_spans.js"
8+
import { addMarkedSpan, conflictingCollapsedRange, conflictingIsolateRange, getMarkedSpanFor, lineIsHidden, lineLength, MarkedSpan, removeMarkedSpan, visualLine } from "../line/spans.js"
99
import { copyObj, indexOf, lst } from "../util/misc.js"
1010
import { signalLater } from "../util/operation_group.js"
1111
import { widgetHeight } from "../measurement/widgets.js"
@@ -177,6 +177,12 @@ export function markText(doc, from, to, options, type) {
177177
throw new Error("Inserting collapsed marker partially overlapping an existing one")
178178
seeCollapsedSpans()
179179
}
180+
if (marker.isolate) {
181+
if (conflictingIsolateRange(doc, from.line, from, to, marker) ||
182+
from.line != to.line && conflictingIsolateRange(doc, to.line, from, to, marker))
183+
{ throw new Error("Inserting isolate marker partially overlapping an existing one") }
184+
seeIsolateSpans()
185+
}
180186

181187
if (marker.addToHistory)
182188
addChangeToHistory(doc, {from: from, to: to, origin: "markText"}, doc.sel, NaN)

0 commit comments

Comments
 (0)