Modified: branches/safari-537.73-branch/Source/WebInspectorUI/ChangeLog (158590 => 158591)
--- branches/safari-537.73-branch/Source/WebInspectorUI/ChangeLog 2013-11-04 21:44:24 UTC (rev 158590)
+++ branches/safari-537.73-branch/Source/WebInspectorUI/ChangeLog 2013-11-04 21:46:51 UTC (rev 158591)
@@ -1,5 +1,26 @@
2013-11-04 Lucas Forschler <[email protected]>
+ Merge r154897
+
+ 2013-08-29 Timothy Hatcher <[email protected]>
+
+ Only modify numbers if they are identified by CodeMirror as a number.
+
+ https://bugs.webkit.org/show_bug.cgi?id=120484
+
+ <rdar://problem/13877085> REGRESSION: Alt-up and Alt-down don't work when cursor is in unit
+ <rdar://problem/13058697> PARITY: Option-Up arrow in "translate3d" should not modify number to make" translate4d"
+
+ Reviewed by Joseph Pecoraro.
+
+ * UserInterface/CodeMirrorAdditions.js:
+ (CodeMirror.prototype.alterNumberInRange): Correctly preserve the selection, even if it differs from
+ the range passed in.
+ (alterNumber): Find number tokens and pass those to alterNumberInRange.
+ (alterNumber.findNumberToken): Added. Helper.
+
+2013-11-04 Lucas Forschler <[email protected]>
+
Merge r154851
2013-08-29 Timothy Hatcher <[email protected]>
Modified: branches/safari-537.73-branch/Source/WebInspectorUI/UserInterface/CodeMirrorAdditions.js (158590 => 158591)
--- branches/safari-537.73-branch/Source/WebInspectorUI/UserInterface/CodeMirrorAdditions.js 2013-11-04 21:44:24 UTC (rev 158590)
+++ branches/safari-537.73-branch/Source/WebInspectorUI/UserInterface/CodeMirrorAdditions.js 2013-11-04 21:46:51 UTC (rev 158591)
@@ -281,11 +281,17 @@
return true;
});
- CodeMirror.defineExtension("alterNumberInRange", function(amount, startPosition, endPosition, affectsSelection) {
+ CodeMirror.defineExtension("alterNumberInRange", function(amount, startPosition, endPosition, updateSelection) {
// We don't try if the range is multiline, pass to another key handler.
if (startPosition.line !== endPosition.line)
return false;
+ if (updateSelection) {
+ // Remember the cursor position/selection.
+ var selectionStart = this.getCursor("start");
+ var selectionEnd = this.getCursor("end");
+ }
+
var line = this.getLine(startPosition.line);
var foundPeriod = false;
@@ -349,17 +355,20 @@
this.replaceRange(alteredNumberString, from, to);
- if (affectsSelection) {
- var newTo = {line: startPosition.line, ch: from.ch + alteredNumberString.length};
+ if (updateSelection) {
+ var previousLength = to.ch - from.ch;
+ var newLength = alteredNumberString.length;
// Fix up the selection so it follows the increase or decrease in the replacement length.
- if (endPosition.ch >= to.ch)
- endPosition = newTo;
+ if (previousLength != newLength) {
+ if (selectionStart.line === from.line && selectionStart.ch > from.ch)
+ selectionStart.ch += newLength - previousLength;
- if (startPosition.ch >= to.ch)
- startPosition = newTo;
+ if (selectionEnd.line === from.line && selectionEnd.ch > from.ch)
+ selectionEnd.ch += newLength - previousLength;
+ }
- this.setSelection(startPosition, endPosition);
+ this.setSelection(selectionStart, selectionEnd);
}
return true;
@@ -367,10 +376,30 @@
function alterNumber(amount, codeMirror)
{
- var startPosition = codeMirror.getCursor("anchor");
- var endPosition = codeMirror.getCursor("head");
+ function findNumberToken(position)
+ {
+ // CodeMirror includes the unit in the number token, so searching for
+ // number tokens is the best way to get both the number and unit.
+ var token = codeMirror.getTokenAt(position);
+ if (token && token.type && /\bnumber\b/.test(token.type))
+ return token;
+ return null;
+ }
- var foundNumber = codeMirror.alterNumberInRange(amount, startPosition, endPosition, true);
+ var position = codeMirror.getCursor("head");
+ var token = findNumberToken(position);
+
+ if (!token) {
+ // If the cursor is at the outside beginning of the token, the previous
+ // findNumberToken wont find it. So check the next column for a number too.
+ position.ch += 1;
+ token = findNumberToken(position);
+ }
+
+ if (!token)
+ return CodeMirror.Pass;
+
+ var foundNumber = codeMirror.alterNumberInRange(amount, {ch: token.start, line: position.line}, {ch: token.end, line: position.line}, true);
if (!foundNumber)
return CodeMirror.Pass;
}