Changeset 191416 in webkit


Ignore:
Timestamp:
Oct 21, 2015 5:13:29 PM (8 years ago)
Author:
commit-queue@webkit.org
Message:

Web Inspector: Option-Up doesn't increment certain attribute values
https://bugs.webkit.org/show_bug.cgi?id=149257

Patch by Devin Rousso <Devin Rousso> on 2015-10-21
Reviewed by Brian Burg.

If the user tries to modify a numerical attribute in HTML and the cursor
was at the beginning of the attribute value, the range of the selection
was within a sibling element instead of the text node containin the value.
This patch fixes this issue and ensures that the correct text is selected.

  • UserInterface/Views/EditingSupport.js:

(WebInspector.startEditing.handleEditingResult):
Replaced var with let.

Location:
trunk/Source/WebInspectorUI
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebInspectorUI/ChangeLog

    r191399 r191416  
     12015-10-21  Devin Rousso  <dcrousso+webkit@gmail.com>
     2
     3        Web Inspector: Option-Up doesn't increment certain attribute values
     4        https://bugs.webkit.org/show_bug.cgi?id=149257
     5
     6        Reviewed by Brian Burg.
     7
     8        If the user tries to modify a numerical attribute in HTML and the cursor
     9        was at the beginning of the attribute value, the range of the selection
     10        was within a sibling element instead of the text node containin the value.
     11        This patch fixes this issue and ensures that the correct text is selected.
     12
     13        * UserInterface/Views/EditingSupport.js:
     14        (WebInspector.startEditing.handleEditingResult):
     15        Replaced var with let.
     16
    1172015-10-21  Joseph Pecoraro  <pecoraro@apple.com>
    218
  • trunk/Source/WebInspectorUI/UserInterface/Views/EditingSupport.js

    r188138 r191416  
    219219                blurEventListener();
    220220        } else if (result && result.startsWith("modify-")) {
    221             var direction = result.substring(7);
    222             var modifyValue = direction.startsWith("up") ? 1 : -1;
     221            let direction = result.substring(7);
     222            let modifyValue = direction.startsWith("up") ? 1 : -1;
    223223            if (direction.endsWith("big"))
    224224                modifyValue *= 10;
     
    229229                modifyValue /= 10;
    230230
    231             var selection = element.ownerDocument.defaultView.getSelection();
     231            let selection = element.ownerDocument.defaultView.getSelection();
    232232            if (!selection.rangeCount)
    233233                return;
    234234
    235             var range = selection.getRangeAt(0);
     235            let range = selection.getRangeAt(0);
    236236            if (!range.commonAncestorContainer.isSelfOrDescendant(element))
    237237                return false;
    238238
    239             var wordRange = range.startContainer.rangeOfWord(range.startOffset, WebInspector.EditingSupport.StyleValueDelimiters, element);
    240             var word = wordRange.toString();
    241             var wordPrefix = "";
    242             var wordSuffix = "";
    243             var nonNumberInWord = /[^\d-\.]+/.exec(word);
     239            let wordRange = range.startContainer.rangeOfWord(range.startOffset, WebInspector.EditingSupport.StyleValueDelimiters, element);
     240            let word = wordRange.toString();
     241            let wordPrefix = "";
     242            let wordSuffix = "";
     243            let nonNumberInWord = /[^\d-\.]+/.exec(word);
    244244            if (nonNumberInWord) {
    245                 var nonNumberEndOffset = nonNumberInWord.index + nonNumberInWord[0].length;
     245                let nonNumberEndOffset = nonNumberInWord.index + nonNumberInWord[0].length;
    246246                if (range.startOffset > wordRange.startOffset + nonNumberInWord.index && nonNumberEndOffset < word.length && range.startOffset !== wordRange.startOffset) {
    247247                    wordPrefix = word.substring(0, nonNumberEndOffset);
     
    253253            }
    254254
    255             var matches = WebInspector.EditingSupport.CSSNumberRegex.exec(word);
     255            let matches = WebInspector.EditingSupport.CSSNumberRegex.exec(word);
    256256            if (!matches || matches.length !== 4)
    257257                return;
    258258
    259             var replacement = matches[1] + (Math.round((parseFloat(matches[2]) + modifyValue) * 100) / 100) + matches[3];
     259            let replacement = matches[1] + (Math.round((parseFloat(matches[2]) + modifyValue) * 100) / 100) + matches[3];
    260260
    261261            selection.removeAllRanges();
     
    263263            document.execCommand("insertText", false, wordPrefix + replacement + wordSuffix);
    264264
    265             var replacementSelectionRange = document.createRange();
    266             replacementSelectionRange.setStart(wordRange.commonAncestorContainer, wordRange.startOffset + wordPrefix.length);
    267             replacementSelectionRange.setEnd(wordRange.commonAncestorContainer, wordRange.startOffset + wordPrefix.length + replacement.length);
     265            let container = range.commonAncestorContainer;
     266            let startOffset = range.startOffset;
     267            // This check is for the situation when the cursor is in the space between the
     268            // opening quote of the attribute and the first character. In that spot, the
     269            // commonAncestorContainer is actually the entire attribute node since `="` is
     270            // added as a simple text node. Since the opening quote is immediately before
     271            // the attribute, the node for that attribute must be the next sibling and the
     272            // text of the attribute's value must be the first child of that sibling.
     273            if (container.parentNode.classList.contains("editing")) {
     274                container = container.nextSibling.firstChild;
     275                startOffset = 0;
     276            }
     277            startOffset += wordPrefix.length;
     278
     279            if (!container)
     280                return;
     281
     282            let replacementSelectionRange = document.createRange();
     283            replacementSelectionRange.setStart(container, startOffset);
     284            replacementSelectionRange.setEnd(container, startOffset + replacement.length);
    268285
    269286            selection.removeAllRanges();
Note: See TracChangeset for help on using the changeset viewer.