Changeset 191416 in webkit
- Timestamp:
- Oct 21, 2015 5:13:29 PM (8 years ago)
- Location:
- trunk/Source/WebInspectorUI
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebInspectorUI/ChangeLog
r191399 r191416 1 2015-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 1 17 2015-10-21 Joseph Pecoraro <pecoraro@apple.com> 2 18 -
trunk/Source/WebInspectorUI/UserInterface/Views/EditingSupport.js
r188138 r191416 219 219 blurEventListener(); 220 220 } else if (result && result.startsWith("modify-")) { 221 vardirection = result.substring(7);222 varmodifyValue = direction.startsWith("up") ? 1 : -1;221 let direction = result.substring(7); 222 let modifyValue = direction.startsWith("up") ? 1 : -1; 223 223 if (direction.endsWith("big")) 224 224 modifyValue *= 10; … … 229 229 modifyValue /= 10; 230 230 231 varselection = element.ownerDocument.defaultView.getSelection();231 let selection = element.ownerDocument.defaultView.getSelection(); 232 232 if (!selection.rangeCount) 233 233 return; 234 234 235 varrange = selection.getRangeAt(0);235 let range = selection.getRangeAt(0); 236 236 if (!range.commonAncestorContainer.isSelfOrDescendant(element)) 237 237 return false; 238 238 239 varwordRange = range.startContainer.rangeOfWord(range.startOffset, WebInspector.EditingSupport.StyleValueDelimiters, element);240 varword = wordRange.toString();241 varwordPrefix = "";242 varwordSuffix = "";243 varnonNumberInWord = /[^\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); 244 244 if (nonNumberInWord) { 245 varnonNumberEndOffset = nonNumberInWord.index + nonNumberInWord[0].length;245 let nonNumberEndOffset = nonNumberInWord.index + nonNumberInWord[0].length; 246 246 if (range.startOffset > wordRange.startOffset + nonNumberInWord.index && nonNumberEndOffset < word.length && range.startOffset !== wordRange.startOffset) { 247 247 wordPrefix = word.substring(0, nonNumberEndOffset); … … 253 253 } 254 254 255 varmatches = WebInspector.EditingSupport.CSSNumberRegex.exec(word);255 let matches = WebInspector.EditingSupport.CSSNumberRegex.exec(word); 256 256 if (!matches || matches.length !== 4) 257 257 return; 258 258 259 varreplacement = 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]; 260 260 261 261 selection.removeAllRanges(); … … 263 263 document.execCommand("insertText", false, wordPrefix + replacement + wordSuffix); 264 264 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); 268 285 269 286 selection.removeAllRanges();
Note: See TracChangeset
for help on using the changeset viewer.