Title: [152651] trunk/Source/WebInspectorUI
Revision
152651
Author
[email protected]
Date
2013-07-15 11:53:27 -0700 (Mon, 15 Jul 2013)

Log Message

Properly handle style text changes while the color popover is open.

https://bugs.webkit.org/show_bug.cgi?id=118575

Reviewed by Joseph Pecoraro.

* UserInterface/CSSStyleDeclarationTextEditor.js:
(WebInspector.CSSStyleDeclarationTextEditor.prototype._colorSwatchClicked.updateCodeMirror):
The original text marker might have been cleared by a style update, in this case we need to
find the new color text marker so we know the right range for the new style color text.

Modified Paths

Diff

Modified: trunk/Source/WebInspectorUI/ChangeLog (152650 => 152651)


--- trunk/Source/WebInspectorUI/ChangeLog	2013-07-15 18:48:56 UTC (rev 152650)
+++ trunk/Source/WebInspectorUI/ChangeLog	2013-07-15 18:53:27 UTC (rev 152651)
@@ -1,3 +1,16 @@
+2013-07-15  Timothy Hatcher  <[email protected]>
+
+        Properly handle style text changes while the color popover is open.
+
+        https://bugs.webkit.org/show_bug.cgi?id=118575
+
+        Reviewed by Joseph Pecoraro.
+
+        * UserInterface/CSSStyleDeclarationTextEditor.js:
+        (WebInspector.CSSStyleDeclarationTextEditor.prototype._colorSwatchClicked.updateCodeMirror):
+        The original text marker might have been cleared by a style update, in this case we need to
+        find the new color text marker so we know the right range for the new style color text.
+
 2013-07-14  Commit Queue  <[email protected]>
 
         Unreviewed, rolling out r152598.

Modified: trunk/Source/WebInspectorUI/UserInterface/CSSStyleDeclarationTextEditor.js (152650 => 152651)


--- trunk/Source/WebInspectorUI/UserInterface/CSSStyleDeclarationTextEditor.js	2013-07-15 18:48:56 UTC (rev 152650)
+++ trunk/Source/WebInspectorUI/UserInterface/CSSStyleDeclarationTextEditor.js	2013-07-15 18:53:27 UTC (rev 152651)
@@ -678,22 +678,52 @@
 
         function updateCodeMirror(newColorText)
         {
-            this._codeMirror.operation(function() 
+            function update()
             {
+                // The original text marker might have been cleared by a style update,
+                // in this case we need to find the new color text marker so we know
+                // the right range for the new style color text.
+                if (!colorTextMarker || !colorTextMarker.find()) {
+                    colorTextMarker = null;
+
+                    var marks = this._codeMirror.findMarksAt(range.from);
+                    if (!marks.length)
+                        return;
+
+                    for (var i = 0; i < marks.length; ++i) {
+                        var mark = marks[i];
+                        if (!mark.__markedColor)
+                            continue;
+                        colorTextMarker = mark;
+                        break;
+                    }
+                }
+
+                if (!colorTextMarker)
+                    return;
+
+                // Sometimes we still might find a stale text marker with findMarksAt.
+                var newRange = colorTextMarker.find();
+                if (!newRange)
+                    return;
+
+                range = newRange;
+
                 colorTextMarker.clear();
 
                 this._codeMirror.replaceRange(newColorText, range.from, range.to);
 
                 // The color's text format could have changed, so we need to update the "range" 
                 // variable to anticipate a different "range.to" property.
-                var to = {line: range.from.line, ch: range.from.ch + newColorText.length};
-                range.to = to;
+                range.to.ch = range.from.ch + newColorText.length;
 
-                colorTextMarker = this._codeMirror.markText(range.from, to);
+                colorTextMarker = this._codeMirror.markText(range.from, range.to);
                 colorTextMarker.__markedColor = true;
 
                 swatch.__colorTextMarker = colorTextMarker;
-            }.bind(this));
+            }
+
+            this._codeMirror.operation(update.bind(this));
         }
 
         if (event.shiftKey) {
@@ -710,7 +740,6 @@
             this._ignoreCodeMirrorContentDidChangeEvent = true;
             updateCodeMirror.call(this, newColorText);
             delete this._ignoreCodeMirrorContentDidChangeEvent;
-
         } else {
             this._colorPickerPopover = new WebInspector.Popover(this);
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to