Source/WebInspectorUI/ChangeLog

 12015-07-01 Devin Rousso <drousso@apple.com>
 2
 3 Make the first click on a rule section create a newline for easy property addition
 4 https://bugs.webkit.org/show_bug.cgi?id=146490
 5
 6 Reviewed by NOBODY (OOPS!).
 7
 8 * UserInterface/Views/CSSStyleDeclarationTextEditor.js:
 9 (WebInspector.CSSStyleDeclarationTextEditor):
 10 (WebInspector.CSSStyleDeclarationTextEditor.prototype._highlightNextNameOrValue):
 11 (WebInspector.CSSStyleDeclarationTextEditor.prototype._handleEnterKey): Inserts a semicolon if the line is missing one.
 12 (WebInspector.CSSStyleDeclarationTextEditor.prototype._handleMouseDown): If the user clicks on a property with the editor being
 13 unfocused, the name/value containing the cursor will be highlighted. If instead the user clicks at the end of a line, the
 14 cursor's position is saved for mouseUp.
 15 (WebInspector.CSSStyleDeclarationTextEditor.prototype._handleMouseUp): If the mouseDown cursor position was saved and is equal
 16 to the current cursor's position (the user did not drag), add a newline after the current line and place the cursor on that line.
 17 (WebInspector.CSSStyleDeclarationTextEditor.prototype._handleTabKey):
 18 (WebInspector.CSSStyleDeclarationTextEditor.prototype._handleTabKey.highlightNextNameOrValue): Deleted.
 19
1202015-06-30 Devin Rousso <drousso@apple.com>
221
322 Web Inspector: add " = $0" hint after selected element in main DOMTreeOutline

Source/WebInspectorUI/UserInterface/Views/CSSStyleDeclarationTextEditor.js

@@WebInspector.CSSStyleDeclarationTextEditor = class CSSStyleDeclarationTextEditor
3333 this._element = element || document.createElement("div");
3434 this._element.classList.add(WebInspector.CSSStyleDeclarationTextEditor.StyleClassName);
3535 this._element.classList.add(WebInspector.SyntaxHighlightedStyleClassName);
 36 this._element.addEventListener("mousedown", this._handleMouseDown.bind(this));
 37 this._element.addEventListener("mouseup", this._handleMouseUp.bind(this));
 38
 39 this._mouseDownCursorPosition = null;
3640
3741 this._showsImplicitProperties = true;
3842 this._alwaysShowPropertyNames = {};

@@WebInspector.CSSStyleDeclarationTextEditor = class CSSStyleDeclarationTextEditor
5862 });
5963
6064 this._codeMirror.addKeyMap({
 65 "Enter": this._handleEnterKey.bind(this),
6166 "Shift-Enter": this._insertNewlineAfterCurrentLine.bind(this),
6267 "Shift-Tab": this._handleShiftTabKey.bind(this),
6368 "Tab": this._handleTabKey.bind(this)

@@WebInspector.CSSStyleDeclarationTextEditor = class CSSStyleDeclarationTextEditor
389394
390395 // Private
391396
 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
392459 _insertNewlineAfterCurrentLine(codeMirror)
393460 {
394461 var cursor = codeMirror.getCursor();

@@WebInspector.CSSStyleDeclarationTextEditor = class CSSStyleDeclarationTextEditor
459526 return CodeMirror.Pass;
460527 }
461528
462  function highlightNextNameOrValue(text)
463  {
464  var match = text.match(/(?:[^:;\s]\s*)+/g);
465  var firstMatch = text.indexOf(match[0]) + match[0].length;
466  var nextHead = cursor.ch < firstMatch ? text.indexOf(match[0]) : text.indexOf(match[1]);
467  var nextAnchor = cursor.ch < firstMatch ? firstMatch : text.indexOf(match[1]) + match[1].length;
468 
469  codeMirror.setSelection({line: cursor.line, ch: nextHead}, {line: cursor.line, ch: nextAnchor});
470  }
471 
472529 var cursor = codeMirror.getCursor();
473530 var line = codeMirror.getLine(cursor.line);
474531 var trimmedLine = line.trimRight();

@@WebInspector.CSSStyleDeclarationTextEditor = class CSSStyleDeclarationTextEditor
486543 }
487544
488545 ++cursor.line;
489  highlightNextNameOrValue(nextLine);
 546 this._highlightNextNameOrValue(codeMirror, cursor, nextLine);
490547 return;
491548 }
492549

@@WebInspector.CSSStyleDeclarationTextEditor = class CSSStyleDeclarationTextEditor
526583 return;
527584 }
528585
529  highlightNextNameOrValue(line);
 586 this._highlightNextNameOrValue(codeMirror, cursor, line);
530587 }
531588
532589 _clearRemoveEditingLineClassesTimeout()