Changeset 49709 in webkit


Ignore:
Timestamp:
Oct 16, 2009 5:08:50 PM (15 years ago)
Author:
Joseph Pecoraro
Message:

2009-10-15 Joseph Pecoraro <Joseph Pecoraro>

Reviewed by Timothy Hatcher.

Web Inspector: Handle the Enter Key in the Elements Tree Hierarchy
https://bugs.webkit.org/show_bug.cgi?id=30428

TextNode => Edit Text Node
Has Attributes => Edit First Attribute
No Attributes => Start Editing New Attribute

  • inspector/front-end/ElementsTreeOutline.js: (WebInspector.ElementsTreeOutline.prototype.handleKeyEvent): handle the "Enter" key (WebInspector.ElementsTreeElement.prototype.set hovered): only add new attribute button on nodes with attributes (WebInspector.ElementsTreeElement.prototype._addNewAttribute): prevent moving backwards where there are no attributes (WebInspector.ElementsTreeElement.prototype._startEditingFromEvent): renamed to be clearer (WebInspector.ElementsTreeElement.prototype._startEditing): transition to the appropriate edit state for a tree element
Location:
trunk/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r49706 r49709  
     12009-10-15  Joseph Pecoraro  <joepeck@webkit.org>
     2
     3        Reviewed by Timothy Hatcher.
     4
     5        Web Inspector: Handle the Enter Key in the Elements Tree Hierarchy
     6        https://bugs.webkit.org/show_bug.cgi?id=30428
     7
     8        TextNode => Edit Text Node
     9        Has Attributes => Edit First Attribute
     10        No Attributes => Start Editing New Attribute
     11
     12        * inspector/front-end/ElementsTreeOutline.js:
     13        (WebInspector.ElementsTreeOutline.prototype.handleKeyEvent): handle the "Enter" key
     14        (WebInspector.ElementsTreeElement.prototype.set hovered): only add new attribute button on nodes with attributes
     15        (WebInspector.ElementsTreeElement.prototype._addNewAttribute): prevent moving backwards where there are no attributes
     16        (WebInspector.ElementsTreeElement.prototype._startEditingFromEvent): renamed to be clearer
     17        (WebInspector.ElementsTreeElement.prototype._startEditing): transition to the appropriate edit state for a tree element
     18
    1192009-10-16  Adam Barth  <abarth@webkit.org>
    220
  • trunk/WebCore/inspector/front-end/ElementsTreeOutline.js

    r49506 r49709  
    189189    {
    190190        var selectedElement = this.selectedTreeElement;
    191 
    192191        if (!selectedElement)
    193192            return;
    194        
    195         if (event.keyCode == 8 || event.keyCode == 46) {
    196             // Delete or backspace pressed, delete the node.
     193
     194        // Delete or backspace pressed, delete the node.
     195        if (event.keyCode === 8 || event.keyCode === 46) {
    197196            selectedElement.remove();
    198197            return;
    199198        }
    200        
     199
     200        // On Enter or Return start editing the first attribute
     201        // or create a new attribute on the selected element.
     202        if (event.keyIdentifier === "Enter") {
     203            if (this._editing)
     204                return;
     205
     206            selectedElement._startEditing();
     207
     208            // prevent a newline from being immediately inserted
     209            event.preventDefault();
     210            return;
     211        }
     212
    201213        TreeOutline.prototype.handleKeyEvent.call(this, event);
    202214    },
     
    296308                this.updateSelection();
    297309                this.listItemElement.addStyleClass("hovered");
    298                 this._pendingToggleNewAttribute = setTimeout(this.toggleNewAttributeButton.bind(this, true), 500);
     310                if (this._canAddAttributes)
     311                    this._pendingToggleNewAttribute = setTimeout(this.toggleNewAttributeButton.bind(this, true), 500);
    299312            } else {
    300313                this.listItemElement.removeStyleClass("hovered");
     
    507520            return;
    508521
    509         if (this._startEditing(event, treeElement))
     522        if (this._startEditingFromEvent(event, treeElement))
    510523            return;
    511524
     
    532545    },
    533546
    534     _startEditing: function(event, treeElement)
     547    _startEditingFromEvent: function(event, treeElement)
    535548    {
    536549        if (this.treeOutline.focusedDOMNode != this.representedObject)
     
    553566
    554567        return false;
     568    },
     569
     570    _startEditing: function()
     571    {
     572        if (this.treeOutline.focusedDOMNode !== this.representedObject)
     573            return;
     574
     575        var listItem = this._listItemNode;
     576
     577        if (this._canAddAttributes) {
     578            this.toggleNewAttributeButton(false);
     579            var attribute = listItem.getElementsByClassName("webkit-html-attribute")[0];
     580            if (attribute)
     581                return this._startEditingAttribute(attribute, attribute.getElementsByClassName("webkit-html-attribute-name")[0]);
     582
     583            return this._addNewAttribute(listItem);
     584        }
     585
     586        if (this.representedObject.nodeType === Node.TEXT_NODE) {
     587            var textNode = listItem.getElementsByClassName("webkit-html-text-node")[0];
     588            if (textNode)
     589                return this._startEditingTextNode(textNode);
     590            return;
     591        }
    555592    },
    556593
     
    662699            }
    663700
    664             if (!found && moveDirection === "backward")
     701            if (!found && moveDirection === "backward" && attributes.length > 0)
    665702                moveToAttribute = attributes[attributes.length - 1].name;
    666703            else if (!found && moveDirection === "forward" && !/^\s*$/.test(newText))
Note: See TracChangeset for help on using the changeset viewer.