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

Function leftButtonSelect

server/src/main/resources/static/js/codemirror.js:1586–1612  ·  view source on GitHub ↗
(cm,event,start,behavior)

Source from the content-addressed store, hash-verified

1584if(unit=="line"){return new Range(Pos(pos.line,0),clipPos(cm.doc,Pos(pos.line+1,0)))}
1585var result=unit(cm,pos);return new Range(result.from,result.to)}
1586function leftButtonSelect(cm,event,start,behavior){if(ie){delayBlurEvent(cm);}
1587var display=cm.display,doc=cm.doc;e_preventDefault(event);var ourRange,ourIndex,startSel=doc.sel,ranges=startSel.ranges;if(behavior.addNew&&!behavior.extend){ourIndex=doc.sel.contains(start);if(ourIndex>-1)
1588{ourRange=ranges[ourIndex];}
1589else
1590{ourRange=new Range(start,start);}}else{ourRange=doc.sel.primary();ourIndex=doc.sel.primIndex;}
1591if(behavior.unit=="rectangle"){if(!behavior.addNew){ourRange=new Range(start,start);}
1592start=posFromMouse(cm,event,true,true);ourIndex=-1;}else{var range=rangeForUnit(cm,start,behavior.unit);if(behavior.extend)
1593{ourRange=extendRange(ourRange,range.anchor,range.head,behavior.extend);}
1594else
1595{ourRange=range;}}
1596if(!behavior.addNew){ourIndex=0;setSelection(doc,new Selection([ourRange],0),sel_mouse);startSel=doc.sel;}else if(ourIndex==-1){ourIndex=ranges.length;setSelection(doc,normalizeSelection(cm,ranges.concat([ourRange]),ourIndex),{scroll:false,origin:"*mouse"});}else if(ranges.length>1&&ranges[ourIndex].empty()&&behavior.unit=="char"&&!behavior.extend){setSelection(doc,normalizeSelection(cm,ranges.slice(0,ourIndex).concat(ranges.slice(ourIndex+1)),0),{scroll:false,origin:"*mouse"});startSel=doc.sel;}else{replaceOneSelection(doc,ourIndex,ourRange,sel_mouse);}
1597var lastPos=start;function extendTo(pos){if(cmp(lastPos,pos)==0){return}
1598lastPos=pos;if(behavior.unit=="rectangle"){var ranges=[],tabSize=cm.options.tabSize;var startCol=countColumn(getLine(doc,start.line).text,start.ch,tabSize);var posCol=countColumn(getLine(doc,pos.line).text,pos.ch,tabSize);var left=Math.min(startCol,posCol),right=Math.max(startCol,posCol);for(var line=Math.min(start.line,pos.line),end=Math.min(cm.lastLine(),Math.max(start.line,pos.line));line<=end;line++){var text=getLine(doc,line).text,leftPos=findColumn(text,left,tabSize);if(left==right)
1599{ranges.push(new Range(Pos(line,leftPos),Pos(line,leftPos)));}
1600else if(text.length>leftPos)
1601{ranges.push(new Range(Pos(line,leftPos),Pos(line,findColumn(text,right,tabSize))));}}
1602if(!ranges.length){ranges.push(new Range(start,start));}
1603setSelection(doc,normalizeSelection(cm,startSel.ranges.slice(0,ourIndex).concat(ranges),ourIndex),{origin:"*mouse",scroll:false});cm.scrollIntoView(pos);}else{var oldRange=ourRange;var range=rangeForUnit(cm,pos,behavior.unit);var anchor=oldRange.anchor,head;if(cmp(range.anchor,anchor)>0){head=range.head;anchor=minPos(oldRange.from(),range.anchor);}else{head=range.anchor;anchor=maxPos(oldRange.to(),range.head);}
1604var ranges$1=startSel.ranges.slice(0);ranges$1[ourIndex]=bidiSimplify(cm,new Range(clipPos(doc,anchor),head));setSelection(doc,normalizeSelection(cm,ranges$1,ourIndex),sel_mouse);}}
1605var editorSize=display.wrapper.getBoundingClientRect();var counter=0;function extend(e){var curCount=++counter;var cur=posFromMouse(cm,e,true,behavior.unit=="rectangle");if(!cur){return}
1606if(cmp(cur,lastPos)!=0){cm.curOp.focus=activeElt(root(cm));extendTo(cur);var visible=visibleLines(display,doc);if(cur.line>=visible.to||cur.line<visible.from)
1607{setTimeout(operation(cm,function(){if(counter==curCount){extend(e);}}),150);}}else{var outside=e.clientY<editorSize.top?-20:e.clientY>editorSize.bottom?20:0;if(outside){setTimeout(operation(cm,function(){if(counter!=curCount){return}
1608display.scroller.scrollTop+=outside;extend(e);}),50);}}}
1609function done(e){cm.state.selectingText=false;counter=Infinity;if(e){e_preventDefault(e);display.input.focus();}
1610off(display.wrapper.ownerDocument,"mousemove",move);off(display.wrapper.ownerDocument,"mouseup",up);doc.history.lastSelOrigin=null;}
1611var move=operation(cm,function(e){if(e.buttons===0||!e_button(e)){done(e);}
1612else{extend(e);}});var up=operation(cm,done);cm.state.selectingText=up;on(display.wrapper.ownerDocument,"mousemove",move);on(display.wrapper.ownerDocument,"mouseup",up);}
1613function bidiSimplify(cm,range){var anchor=range.anchor;var head=range.head;var anchorLine=getLine(cm.doc,anchor.line);if(cmp(anchor,head)==0&&anchor.sticky==head.sticky){return range}
1614var order=getOrder(anchorLine);if(!order){return range}
1615var index=getBidiPartAt(order,anchor.ch,anchor.sticky),part=order[index];if(part.from!=anchor.ch&&part.to!=anchor.ch){return range}

Callers 1

leftButtonDownFunction · 0.85

Calls 15

delayBlurEventFunction · 0.85
e_preventDefaultFunction · 0.85
posFromMouseFunction · 0.85
rangeForUnitFunction · 0.85
extendRangeFunction · 0.85
normalizeSelectionFunction · 0.85
replaceOneSelectionFunction · 0.85
operationFunction · 0.85
e_buttonFunction · 0.85
sliceMethod · 0.80
setSelectionFunction · 0.70
doneFunction · 0.70

Tested by

no test coverage detected