Changeset 56684 in webkit


Ignore:
Timestamp:
Mar 28, 2010 1:49:52 AM (14 years ago)
Author:
Joseph Pecoraro
Message:

2010-03-27 Joseph Pecoraro <Joseph Pecoraro>

Reviewed by Pavel Feldman.

Web Inspector: Edit Tag Names
https://bugs.webkit.org/show_bug.cgi?id=36481

Allow tabbing back and forth between the tag name and element
attributes when editing. Also, fixed a number of minor issues with
editing attributes and tabbing.

  • inspector/front-end/ElementsTreeOutline.js: (WebInspector.ElementsTreeElement.prototype._startEditingTagName): find the tag name if it wasn't provided. (WebInspector.ElementsTreeElement.prototype._attributeEditingCommitted): fix tabbing issues, enable tab to tag name. (WebInspector.ElementsTreeElement.prototype._attributeEditingCommitted.regenerateStyledAttribute): cleanup styles when tabbing.
  • inspector/front-end/inspector.css: do not display <br>s while editing
Location:
trunk/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r56683 r56684  
     12010-03-27  Joseph Pecoraro  <joepeck@webkit.org>
     2
     3        Reviewed by Pavel Feldman.
     4
     5        Web Inspector: Edit Tag Names
     6        https://bugs.webkit.org/show_bug.cgi?id=36481
     7
     8        Allow tabbing back and forth between the tag name and element
     9        attributes when editing. Also, fixed a number of minor issues with
     10        editing attributes and tabbing.
     11
     12        * inspector/front-end/ElementsTreeOutline.js:
     13        (WebInspector.ElementsTreeElement.prototype._startEditingTagName): find the tag name if it wasn't provided.
     14        (WebInspector.ElementsTreeElement.prototype._attributeEditingCommitted): fix tabbing issues, enable tab to tag name.
     15        (WebInspector.ElementsTreeElement.prototype._attributeEditingCommitted.regenerateStyledAttribute): cleanup styles when tabbing.
     16        * inspector/front-end/inspector.css: do not display <br>s while editing
     17
    1182010-03-27  Joseph Pecoraro  <joepeck@webkit.org>
    219
  • trunk/WebCore/inspector/front-end/ElementsTreeOutline.js

    r56683 r56684  
    811811
    812812                    if (elem.hasStyleClass("webkit-html-attribute-value"))
    813                         return this._startEditingAttribute(attributeElements[i].parentNode, elem);
     813                        return this._startEditingAttribute(elem.parentNode, elem);
    814814                }
    815815            }
     
    868868    _startEditingTagName: function(tagNameElement)
    869869    {
     870        if (!tagNameElement) {
     871            tagNameElement = this.listItemElement.getElementsByClassName("webkit-html-tag-name")[0];
     872            if (!tagNameElement)
     873                return false;
     874        }
     875 
    870876        if (WebInspector.isBeingEdited(tagNameElement))
    871877            return true;
     
    960966        // Before we do anything, determine where we should move
    961967        // next based on the current element's settings
    962         var moveToAttribute;
    963         var newAttribute;
     968        var moveToAttribute, moveToTagName, moveToNewAttribute;
    964969        if (moveDirection) {
    965970            var found = false;
     971
     972            // Search for the attribute's position, and then decide where to move to.
    966973            var attributes = this.representedObject.attributes;
    967             for (var i = 0, len = attributes.length; i < len; ++i) {
     974            for (var i = 0; i < attributes.length; ++i) {
    968975                if (attributes[i].name === attributeName) {
    969976                    found = true;
    970                     if (moveDirection === "backward" && i > 0)
    971                         moveToAttribute = attributes[i - 1].name;
    972                     else if (moveDirection === "forward" && i < attributes.length - 1)
    973                         moveToAttribute = attributes[i + 1].name;
    974                     else if (moveDirection === "forward" && i === attributes.length - 1)
    975                         newAttribute = true;
     977                    if (moveDirection === "backward") {
     978                        if (i === 0)
     979                            moveToTagName = true;
     980                        else
     981                            moveToAttribute = attributes[i - 1].name;
     982                    } else if (moveDirection === "forward") {
     983                        if (i === attributes.length - 1)
     984                            moveToNewAttribute = true;
     985                        else
     986                            moveToAttribute = attributes[i + 1].name;
     987                    }
    976988                }
    977989            }
    978990
    979             if (!found && moveDirection === "backward" && attributes.length > 0)
    980                 moveToAttribute = attributes[attributes.length - 1].name;
    981             else if (!found && moveDirection === "forward" && !/^\s*$/.test(newText))
    982                 newAttribute = true;
    983         }
    984 
    985         function moveToNextAttributeIfNeeded() {
     991            // Moving From the "New Attribute" position.
     992            if (!found) {
     993                if (moveDirection === "backward" && attributes.length > 0)
     994                    moveToAttribute = attributes[attributes.length - 1].name;
     995                else if (moveDirection === "forward" && !/^\s*$/.test(newText))
     996                    moveToNewAttribute = true;
     997            }
     998        }
     999
     1000        function moveToNextAttributeIfNeeded()
     1001        {
     1002            // Cleanup empty new attribute sections.
     1003            if (element.textContent.trim().length === 0)
     1004                element.parentNode.removeChild(element);
     1005
     1006            // Make the move.
    9861007            if (moveToAttribute)
    9871008                this._triggerEditAttribute(moveToAttribute);
    988             else if (newAttribute)
     1009            else if (moveToNewAttribute)
    9891010                this._addNewAttribute();
     1011            else if (moveToTagName)
     1012                this._startEditingTagName();
     1013        }
     1014
     1015        function regenerateStyledAttribute(name, value)
     1016        {
     1017            var previous = element.previousSibling;
     1018            if (!previous || previous.nodeType !== Node.TEXT_NODE)
     1019                element.parentNode.insertBefore(document.createTextNode(" "), element);
     1020            element.outerHTML = "<span class=\"webkit-html-attribute\">" +
     1021                                  "<span class=\"webkit-html-attribute-name\">" + attr.name.escapeHTML() + "</span>=&#8203;\"" +
     1022                                  "<span class=\"webkit-html-attribute-value\">" + attr.value.escapeHTML() + "</span>&#8203;\"" +
     1023                                "</span>";
    9901024        }
    9911025
     
    10121046            try {
    10131047                this.representedObject.setAttribute(attr.name, attr.value);
     1048                regenerateStyledAttribute(attr.name, attr.value);
    10141049            } catch(e) {} // ignore invalid attribute (innerHTML doesn't throw errors, but this can)
    10151050        }
  • trunk/WebCore/inspector/front-end/inspector.css

    r56664 r56684  
    14981498}
    14991499
     1500.editing br {
     1501    display: none;
     1502}
     1503
    15001504.elements-tree-editor {
    15011505    -webkit-user-select: text;
Note: See TracChangeset for help on using the changeset viewer.