(cm, event, start, behavior)
| 197 | |
| 198 | // Normal selection, as opposed to text dragging. |
| 199 | function leftButtonSelect(cm, event, start, behavior) { |
| 200 | if (ie) delayBlurEvent(cm) |
| 201 | let display = cm.display, doc = cm.doc |
| 202 | e_preventDefault(event) |
| 203 | |
| 204 | let ourRange, ourIndex, startSel = doc.sel, ranges = startSel.ranges |
| 205 | if (behavior.addNew && !behavior.extend) { |
| 206 | ourIndex = doc.sel.contains(start) |
| 207 | if (ourIndex > -1) |
| 208 | ourRange = ranges[ourIndex] |
| 209 | else |
| 210 | ourRange = new Range(start, start) |
| 211 | } else { |
| 212 | ourRange = doc.sel.primary() |
| 213 | ourIndex = doc.sel.primIndex |
| 214 | } |
| 215 | |
| 216 | if (behavior.unit == "rectangle") { |
| 217 | if (!behavior.addNew) ourRange = new Range(start, start) |
| 218 | start = posFromMouse(cm, event, true, true) |
| 219 | ourIndex = -1 |
| 220 | } else { |
| 221 | let range = rangeForUnit(cm, start, behavior.unit) |
| 222 | if (behavior.extend) |
| 223 | ourRange = extendRange(ourRange, range.anchor, range.head, behavior.extend) |
| 224 | else |
| 225 | ourRange = range |
| 226 | } |
| 227 | |
| 228 | if (!behavior.addNew) { |
| 229 | ourIndex = 0 |
| 230 | setSelection(doc, new Selection([ourRange], 0), sel_mouse) |
| 231 | startSel = doc.sel |
| 232 | } else if (ourIndex == -1) { |
| 233 | ourIndex = ranges.length |
| 234 | setSelection(doc, normalizeSelection(cm, ranges.concat([ourRange]), ourIndex), |
| 235 | {scroll: false, origin: "*mouse"}) |
| 236 | } else if (ranges.length > 1 && ranges[ourIndex].empty() && behavior.unit == "char" && !behavior.extend) { |
| 237 | setSelection(doc, normalizeSelection(cm, ranges.slice(0, ourIndex).concat(ranges.slice(ourIndex + 1)), 0), |
| 238 | {scroll: false, origin: "*mouse"}) |
| 239 | startSel = doc.sel |
| 240 | } else { |
| 241 | replaceOneSelection(doc, ourIndex, ourRange, sel_mouse) |
| 242 | } |
| 243 | |
| 244 | let lastPos = start |
| 245 | function extendTo(pos) { |
| 246 | if (cmp(lastPos, pos) == 0) return |
| 247 | lastPos = pos |
| 248 | |
| 249 | if (behavior.unit == "rectangle") { |
| 250 | let ranges = [], tabSize = cm.options.tabSize |
| 251 | let startCol = countColumn(getLine(doc, start.line).text, start.ch, tabSize) |
| 252 | let posCol = countColumn(getLine(doc, pos.line).text, pos.ch, tabSize) |
| 253 | let left = Math.min(startCol, posCol), right = Math.max(startCol, posCol) |
| 254 | for (let line = Math.min(start.line, pos.line), end = Math.min(cm.lastLine(), Math.max(start.line, pos.line)); |
| 255 | line <= end; line++) { |
| 256 | let text = getLine(doc, line).text, leftPos = findColumn(text, left, tabSize) |
no test coverage detected