Title: [191416] trunk/Source/WebInspectorUI
Revision
191416
Author
commit-qu...@webkit.org
Date
2015-10-21 17:13:29 -0700 (Wed, 21 Oct 2015)

Log Message

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

Patch by Devin Rousso <dcrousso+web...@gmail.com> 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.

Modified Paths

Diff

Modified: trunk/Source/WebInspectorUI/ChangeLog (191415 => 191416)


--- trunk/Source/WebInspectorUI/ChangeLog	2015-10-22 00:07:27 UTC (rev 191415)
+++ trunk/Source/WebInspectorUI/ChangeLog	2015-10-22 00:13:29 UTC (rev 191416)
@@ -1,3 +1,19 @@
+2015-10-21  Devin Rousso  <dcrousso+web...@gmail.com>
+
+        Web Inspector: Option-Up doesn't increment certain attribute values
+        https://bugs.webkit.org/show_bug.cgi?id=149257
+
+        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.
+
 2015-10-21  Joseph Pecoraro  <pecor...@apple.com>
 
         Web Inspector: Use some CSS Variables in Web Inspector

Modified: trunk/Source/WebInspectorUI/UserInterface/Views/EditingSupport.js (191415 => 191416)


--- trunk/Source/WebInspectorUI/UserInterface/Views/EditingSupport.js	2015-10-22 00:07:27 UTC (rev 191415)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/EditingSupport.js	2015-10-22 00:13:29 UTC (rev 191416)
@@ -218,8 +218,8 @@
             if (event.keyIdentifier !== "U+0009")
                 blurEventListener();
         } else if (result && result.startsWith("modify-")) {
-            var direction = result.substring(7);
-            var modifyValue = direction.startsWith("up") ? 1 : -1;
+            let direction = result.substring(7);
+            let modifyValue = direction.startsWith("up") ? 1 : -1;
             if (direction.endsWith("big"))
                 modifyValue *= 10;
 
@@ -228,21 +228,21 @@
             else if (event.ctrlKey)
                 modifyValue /= 10;
 
-            var selection = element.ownerDocument.defaultView.getSelection();
+            let selection = element.ownerDocument.defaultView.getSelection();
             if (!selection.rangeCount)
                 return;
 
-            var range = selection.getRangeAt(0);
+            let range = selection.getRangeAt(0);
             if (!range.commonAncestorContainer.isSelfOrDescendant(element))
                 return false;
 
-            var wordRange = range.startContainer.rangeOfWord(range.startOffset, WebInspector.EditingSupport.StyleValueDelimiters, element);
-            var word = wordRange.toString();
-            var wordPrefix = "";
-            var wordSuffix = "";
-            var nonNumberInWord = /[^\d-\.]+/.exec(word);
+            let wordRange = range.startContainer.rangeOfWord(range.startOffset, WebInspector.EditingSupport.StyleValueDelimiters, element);
+            let word = wordRange.toString();
+            let wordPrefix = "";
+            let wordSuffix = "";
+            let nonNumberInWord = /[^\d-\.]+/.exec(word);
             if (nonNumberInWord) {
-                var nonNumberEndOffset = nonNumberInWord.index + nonNumberInWord[0].length;
+                let nonNumberEndOffset = nonNumberInWord.index + nonNumberInWord[0].length;
                 if (range.startOffset > wordRange.startOffset + nonNumberInWord.index && nonNumberEndOffset < word.length && range.startOffset !== wordRange.startOffset) {
                     wordPrefix = word.substring(0, nonNumberEndOffset);
                     word = word.substring(nonNumberEndOffset);
@@ -252,20 +252,37 @@
                 }
             }
 
-            var matches = WebInspector.EditingSupport.CSSNumberRegex.exec(word);
+            let matches = WebInspector.EditingSupport.CSSNumberRegex.exec(word);
             if (!matches || matches.length !== 4)
                 return;
 
-            var replacement = matches[1] + (Math.round((parseFloat(matches[2]) + modifyValue) * 100) / 100) + matches[3];
+            let replacement = matches[1] + (Math.round((parseFloat(matches[2]) + modifyValue) * 100) / 100) + matches[3];
 
             selection.removeAllRanges();
             selection.addRange(wordRange);
             document.execCommand("insertText", false, wordPrefix + replacement + wordSuffix);
 
-            var replacementSelectionRange = document.createRange();
-            replacementSelectionRange.setStart(wordRange.commonAncestorContainer, wordRange.startOffset + wordPrefix.length);
-            replacementSelectionRange.setEnd(wordRange.commonAncestorContainer, wordRange.startOffset + wordPrefix.length + replacement.length);
+            let container = range.commonAncestorContainer;
+            let startOffset = range.startOffset;
+            // This check is for the situation when the cursor is in the space between the
+            // opening quote of the attribute and the first character. In that spot, the
+            // commonAncestorContainer is actually the entire attribute node since `="` is
+            // added as a simple text node. Since the opening quote is immediately before
+            // the attribute, the node for that attribute must be the next sibling and the
+            // text of the attribute's value must be the first child of that sibling.
+            if (container.parentNode.classList.contains("editing")) {
+                container = container.nextSibling.firstChild;
+                startOffset = 0;
+            }
+            startOffset += wordPrefix.length;
 
+            if (!container)
+                return;
+
+            let replacementSelectionRange = document.createRange();
+            replacementSelectionRange.setStart(container, startOffset);
+            replacementSelectionRange.setEnd(container, startOffset + replacement.length);
+
             selection.removeAllRanges();
             selection.addRange(replacementSelectionRange);
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to