397 _highlightNextNameOrValue(codeMirror, cursor, text)
398 {
399 var match = text.match(/(?:[^:;\s]\s*)+/g);
400 var firstMatch = text.indexOf(match[0]) + match[0].length;
401 var nextHead = cursor.ch < firstMatch ? text.indexOf(match[0]) : text.indexOf(match[1]);
402 var nextAnchor = cursor.ch < firstMatch ? firstMatch : text.indexOf(match[1]) + match[1].length;
403
404 codeMirror.setSelection({line: cursor.line, ch: nextHead}, {line: cursor.line, ch: nextAnchor});
405 }
406
407 _handleMouseDown(event)
408 {
409 if (this._codeMirror.options.readOnly || this._codeMirror.state.focused)
410 return;
411
412 var cursor = this._codeMirror.coordsChar({left: event.x, top: event.y});
413 var line = this._codeMirror.getLine(cursor.line);
414 var trimmedLine = line.trimRight();
415
416 if (!trimmedLine.trimLeft().length)
417 return;
418
419 if (cursor.ch !== trimmedLine.length) {
420 this._highlightNextNameOrValue(this._codeMirror, cursor, line);
421 return;
422 }
423
424 this._mouseDownCursorPosition = cursor;
425 }
426
427 _handleMouseUp(event)
428 {
429 if (this._codeMirror.options.readOnly || !this._mouseDownCursorPosition)
430 return;
431
432 var cursor = this._codeMirror.coordsChar({left: event.x, top: event.y});
433 var line = this._codeMirror.getLine(cursor.line);
434
435 if (this._mouseDownCursorPosition.line === cursor.line && this._mouseDownCursorPosition.ch === cursor.ch)
436 this._codeMirror.replaceRange(line.trimRight().endsWith(";") ? "\n" : ";\n", cursor);
437
438 this._mouseDownCursorPosition = null;
439 }
440
441 _handleEnterKey(codeMirror)
442 {
443 var cursor = codeMirror.getCursor();
444 var line = codeMirror.getLine(cursor.line);
445 var trimmedLine = line.trimRight();
446 var hasEndingSemicolon = trimmedLine.endsWith(";");
447
448 if (hasEndingSemicolon && cursor.ch === trimmedLine.length - 1)
449 ++cursor.ch;
450
451 if (cursor.ch === trimmedLine.length) {
452 codeMirror.replaceRange(hasEndingSemicolon ? "\n" : ";\n", cursor);
453 return;
454 }
455
456 return CodeMirror.Pass;
457 }
458