Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(768)

Unified Diff: third_party/WebKit/Source/devtools/front_end/sources/UISourceCodeFrame.js

Issue 1768183003: DevTools: Support line markers in UISourceCode and Code Mirror (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: wrap setGutterMarker's in an operation. Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/devtools/front_end/sources/UISourceCodeFrame.js
diff --git a/third_party/WebKit/Source/devtools/front_end/sources/UISourceCodeFrame.js b/third_party/WebKit/Source/devtools/front_end/sources/UISourceCodeFrame.js
index df56d748899a2be33b825c6110a4fb8679790baa..3535938f070e9e9464da47cda191da314d61509d 100644
--- a/third_party/WebKit/Source/devtools/front_end/sources/UISourceCodeFrame.js
+++ b/third_party/WebKit/Source/devtools/front_end/sources/UISourceCodeFrame.js
@@ -37,10 +37,14 @@ WebInspector.UISourceCodeFrame = function(uiSourceCode)
WebInspector.SourceFrame.call(this, this._uiSourceCode);
this.textEditor.setAutocompleteDelegate(new WebInspector.SimpleAutocompleteDelegate());
this._rowMessageBuckets = {};
+ /** @type {!Map<string, !Array<!WebInspector.UISourceCode.LineMarker>>} */
+ this._markersToDecorate = new Map();
this._uiSourceCode.addEventListener(WebInspector.UISourceCode.Events.WorkingCopyChanged, this._onWorkingCopyChanged, this);
this._uiSourceCode.addEventListener(WebInspector.UISourceCode.Events.WorkingCopyCommitted, this._onWorkingCopyCommitted, this);
this._uiSourceCode.addEventListener(WebInspector.UISourceCode.Events.MessageAdded, this._onMessageAdded, this);
this._uiSourceCode.addEventListener(WebInspector.UISourceCode.Events.MessageRemoved, this._onMessageRemoved, this);
+ this._uiSourceCode.addEventListener(WebInspector.UISourceCode.Events.LineMarkerAdded, this._onLineMarkerAdded, this);
+ this._uiSourceCode.addEventListener(WebInspector.UISourceCode.Events.LineMarkerRemoved, this._onLineMarkerRemoved, this);
this._updateStyle();
this._errorPopoverHelper = new WebInspector.PopoverHelper(this.element, this._getErrorAnchor.bind(this), this._showErrorPopover.bind(this));
@@ -118,6 +122,7 @@ WebInspector.UISourceCodeFrame.prototype = {
WebInspector.SourceFrame.prototype.onTextEditorContentLoaded.call(this);
for (var message of this._uiSourceCode.messages())
this._addMessageToSource(message);
+ this._decorateLineMarkers();
},
/**
@@ -330,6 +335,70 @@ WebInspector.UISourceCodeFrame.prototype = {
}
},
+ /**
+ * @param {!WebInspector.Event} event
+ */
+ _onLineMarkerAdded: function(event)
+ {
+ var marker = /** @type {!WebInspector.UISourceCode.LineMarker} */ (event.data);
+ this._decorateLineMarker(marker);
pfeldman 2016/03/09 02:14:20 runtime.extensions(decorator, event.type).instance
alph 2016/03/09 22:42:18 Done.
+ },
+
+ /**
+ * @param {!WebInspector.Event} event
+ */
+ _onLineMarkerRemoved: function(event)
+ {
+ var marker = /** @type {!WebInspector.UISourceCode.LineMarker} */ (event.data);
pfeldman 2016/03/09 02:14:20 ditto
alph 2016/03/09 22:42:18 Done.
+ this._textEditor.setGutterMarker(marker.line(), marker.type(), null);
pfeldman 2016/03/09 02:14:20 How do you know what the decorator is doing? CodeM
alph 2016/03/09 22:42:18 Done.
+ },
+
+ _decorateLineMarkers: function()
+ {
+ for (var markers of this.uiSourceCode().lineMarkers().values())
+ markers.forEach(this._decorateLineMarker.bind(this));
+ },
+
+ /**
+ * @param {!WebInspector.UISourceCode.LineMarker} marker
+ */
+ _decorateLineMarker: function(marker)
+ {
+ var type = marker.type();
+ var markers = this._markersToDecorate.get(type);
+ if (markers) {
+ markers.push(marker);
+ return;
+ }
+ markers = [];
+ this._markersToDecorate.set(type, markers);
+ lineMarkerDecorator(marker.type()).then(decorateLineMarkers.bind(this, type, markers));
+
+ /**
+ * @param {string} type
+ * @param {!Array<!WebInspector.UISourceCode.LineMarker>} markers
+ * @param {!WebInspector.EditorLineMarkerDecorator} decorator
+ * @this {WebInspector.UISourceCodeFrame}
+ */
+ function decorateLineMarkers(type, markers, decorator)
+ {
+ for (var marker of markers)
+ this._textEditor.setGutterMarker(marker.line(), marker.type(), decorator.decorate(marker.data()));
+ this._markersToDecorate.delete(type);
+ }
+
+ /**
+ * @param {string} type
+ * @return {!Promise<!WebInspector.EditorLineMarkerDecorator>}
+ */
+ function lineMarkerDecorator(type)
+ {
+ var descriptor = self.runtime.extensions("@WebInspector.EditorLineMarkerDecorator").find(extension => extension.descriptor().marker === type);
+ console.assert(descriptor, "Unknown decorator type.");
+ return descriptor.instancePromise();
+ }
+ },
+
__proto__: WebInspector.SourceFrame.prototype
}

Powered by Google App Engine
This is Rietveld 408576698