MCPcopy
hub / github.com/witheve/Eve / markBetween

Method markBetween

src/ide.ts:1113–1175  ·  view source on GitHub ↗

Create new Spans wrapping the text between each given span id or range.

(idsOrRanges:(string[]|Range[]), source:any, bounds?:Range)

Source from the content-addressed store, hash-verified

1111
1112 /** Create new Spans wrapping the text between each given span id or range. */
1113 markBetween(idsOrRanges:(string[]|Range[]), source:any, bounds?:Range): Span[] {
1114 return this.cm.operation(() => {
1115 if(!idsOrRanges.length) return [];
1116 let ranges:Range[];
1117
1118 if(typeof idsOrRanges[0] === "string") {
1119 let ids:string[] = idsOrRanges as string[];
1120 ranges = [];
1121 let spans:Span[];
1122 if(bounds) {
1123 spans = this.findSpansAt(bounds.from).concat(this.findSpans(bounds.from, bounds.to));
1124 } else {
1125 spans = this.getAllSpans();
1126 }
1127 for(let span of spans) {
1128 if(ids.indexOf(span.source.id) !== -1) {
1129 let loc = span.find();
1130 if(!loc) continue;
1131 if(span.isLine()) {
1132 loc = {from: loc.from, to: {line: loc.from.line + 1, ch: 0}};
1133 }
1134 ranges.push(loc);
1135 }
1136 }
1137 } else {
1138 ranges = idsOrRanges as Range[];
1139 }
1140
1141 if(!ranges.length) return;
1142
1143 let doc = this.cm.getDoc();
1144 ranges.sort(compareRanges);
1145
1146 let createdSpans:Span[] = [];
1147
1148 let start = bounds && bounds.from || {line: 0, ch: 0};
1149 for(let range of ranges) {
1150 let from = doc.posFromIndex(doc.indexFromPos(range.from) - 1);
1151 if(comparePositions(start, from) < 0) {
1152 createdSpans.push(this.markSpan(start, {line: from.line, ch: 0}, source));
1153 }
1154
1155 start = doc.posFromIndex(doc.indexFromPos(range.to) + 1);
1156 }
1157
1158 let last = ranges[ranges.length - 1];
1159 let to = doc.posFromIndex(doc.indexFromPos(last.to) + 1);
1160 let end = bounds && bounds.to || doc.posFromIndex(doc.getValue().length);
1161 if(comparePositions(to, end) < 0) {
1162 createdSpans.push(this.markSpan(to, end, source));
1163 }
1164
1165 for(let range of ranges) {
1166 for(let span of this.findSpans(range.from, range.to)) {
1167 span.unhide();
1168 if(span.refresh) span.refresh();
1169
1170 }

Callers 2

updateElisionMethod · 0.80
IDEClass · 0.80

Calls 14

findSpansAtMethod · 0.95
findSpansMethod · 0.95
getAllSpansMethod · 0.95
markSpanMethod · 0.95
comparePositionsFunction · 0.90
operationMethod · 0.80
isLineMethod · 0.80
getDocMethod · 0.80
posFromIndexMethod · 0.80
indexFromPosMethod · 0.80
unhideMethod · 0.80
findMethod · 0.65

Tested by

no test coverage detected