MCPcopy
hub / github.com/kekingcn/kkFileView / normalizeSelection

Function normalizeSelection

server/src/main/resources/static/js/codemirror.js:1047–1049  ·  view source on GitHub ↗
(cm,ranges,primIndex)

Source from the content-addressed store, hash-verified

1045for(var i=0;i<this.ranges.length;i++){var range=this.ranges[i];if(cmp(end,range.from())>=0&&cmp(pos,range.to())<=0)
1046{return i}}
1047return-1};var Range=function(anchor,head){this.anchor=anchor;this.head=head;};Range.prototype.from=function(){return minPos(this.anchor,this.head)};Range.prototype.to=function(){return maxPos(this.anchor,this.head)};Range.prototype.empty=function(){return this.head.line==this.anchor.line&&this.head.ch==this.anchor.ch};function normalizeSelection(cm,ranges,primIndex){var mayTouch=cm&&cm.options.selectionsMayTouch;var prim=ranges[primIndex];ranges.sort(function(a,b){return cmp(a.from(),b.from());});primIndex=indexOf(ranges,prim);for(var i=1;i<ranges.length;i++){var cur=ranges[i],prev=ranges[i-1];var diff=cmp(prev.to(),cur.from());if(mayTouch&&!cur.empty()?diff>0:diff>=0){var from=minPos(prev.from(),cur.from()),to=maxPos(prev.to(),cur.to());var inv=prev.empty()?cur.from()==cur.head:prev.from()==prev.head;if(i<=primIndex){--primIndex;}
1048ranges.splice(--i,2,new Range(inv?to:from,inv?from:to));}}
1049return new Selection(ranges,primIndex)}
1050function simpleSelection(anchor,head){return new Selection([new Range(anchor,head||anchor)],0)}
1051function changeEnd(change){if(!change.text){return change.to}
1052return Pos(change.from.line+change.text.length-1,lst(change.text).length+(change.text.length==1?change.from.ch:0))}

Callers 8

computeSelAfterChangeFunction · 0.85
extendSelectionsFunction · 0.85
replaceOneSelectionFunction · 0.85
filterSelectionChangeFunction · 0.85
skipAtomicInSelectionFunction · 0.85
codemirror.jsFile · 0.85
leftButtonSelectFunction · 0.85
extendToFunction · 0.85

Calls 8

minPosFunction · 0.85
maxPosFunction · 0.85
fromMethod · 0.80
toMethod · 0.80
cmpFunction · 0.70
indexOfFunction · 0.70
sortMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected