Changeset 160552 in webkit
- Timestamp:
- Dec 13, 2013 11:32:49 AM (10 years ago)
- Location:
- trunk/Source/WebInspectorUI
- Files:
-
- 1 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebInspectorUI/ChangeLog
r160548 r160552 1 2013-12-13 Antoine Quint <graouts@apple.com> 2 3 Web Inspector: provide an abstraction for CodeMirror's TextMarker 4 https://bugs.webkit.org/show_bug.cgi?id=125695 5 6 Reviewed by Timothy Hatcher. 7 8 Introduce a new WebInspector.TextMarker class which is used by code with CodeMirror knowledge 9 to return information related to text markers to objects that should have no direct knowledge 10 of CodeMirror. Start using this class in TextEditor and SourceCodeTextEditor to remove the 11 last remaining pieces of CodeMirror knowledge added to SourceCodeTextEditor to fix 12 https://webkit.org/b/124364. 13 14 * UserInterface/CodeMirrorAdditions.js: 15 Stop using __markedColor to identify a color marker and instead use the type on the matching 16 WebInspector.TextMarker. Additionally, create a WebInspector.TextMarker with type 17 WebInspector.TextMarker.Type.Color in createColorMarkers(). 18 19 * UserInterface/CodeMirrorColorEditingController.js: 20 (WebInspector.CodeMirrorColorEditingController): 21 Use a WebInspector.TextRange to track the edited range and obtain it directly from the 22 WebInspector.TextMaker used to instantiate the object. We also use the new "text" public 23 property to create the color. 24 25 (WebInspector.CodeMirrorColorEditingController.prototype.set color): 26 Simply assing the serialized color to the new "text" public property. 27 28 (WebInspector.CodeMirrorColorEditingController.prototype.get text): 29 (WebInspector.CodeMirrorColorEditingController.prototype.set text): 30 New public property to set get and set the text for the edited range, automatically updating 31 the range upon setting to a new text. 32 33 (WebInspector.CodeMirrorColorEditingController.prototype.presentHoverMenu): 34 Obtain the bounds directly from the WebInspector.TextMarker object. 35 36 * UserInterface/CodeMirrorTokenTrackingController.js: 37 (WebInspector.CodeMirrorTokenTrackingController.prototype._updateHoveredTokenInfo): 38 Since we're now tracking the hoveredMarker as a WebInspector.TextMarker, get the CodeMirror 39 TextMarker from that object to check if it's contained within the text markers at the 40 hovered position. 41 42 * UserInterface/Main.html: 43 Add the new TextMarker class source. 44 45 * UserInterface/SourceCodeTextEditor.js: 46 (WebInspector.SourceCodeTextEditor.prototype._hasColorMarkers): 47 Use the WebInspector.TextMarker type to identify a given text marker is marking a color. 48 49 (WebInspector.SourceCodeTextEditor.prototype.tokenTrackingControllerNewHighlightCandidate): 50 Use the renamed markersAtPosition() method from TextEditor. 51 52 (WebInspector.SourceCodeTextEditor.prototype._tokenTrackingControllerHighlightedMarkedExpression): 53 Use the WebInspector.TextMarker type to identify a given text marker is marking a color. 54 55 (WebInspector.SourceCodeTextEditor.prototype.colorEditingControllerDidFinishEditing): 56 Since the CodeMirrorColorEditingController is now using a WebInspector.TextRange for its range, 57 update to use a WebInspector.TextRange API to get the range's start line. 58 59 * UserInterface/TextEditor.js: 60 (WebInspector.TextEditor.prototype.get markers): 61 Return WebInspector.TextMarker objects instead of CodeMirror TextRange objects. 62 63 (WebInspector.TextEditor.prototype.markersAtPosition): 64 Rename method to a better name instead of using the CodeMirror-influenced name. Also, return 65 WebInspector.TextMarker objects instead of CodeMirror TextRange objects. 66 67 * UserInterface/TextMarker.js: Added. 68 (WebInspector.TextMarker): 69 Create a WebInspector.TextMarker with a CodeMirror TextMarker and an optional type. 70 71 (WebInspector.TextMarker.textMarkerForCodeMirrorTextMarker): 72 Static method to either obtain the existing WebInspector.TextMarker for a given CodeMirror 73 TextMarker, or create a new WebInspector.TextMarker. 74 75 (WebInspector.TextMarker.prototype.get codeMirrorTextMarker): 76 Public property to access the CodeMirror TextMarker objects for classes that have direct 77 knowledge of CodeMirror. 78 79 (WebInspector.TextMarker.prototype.get type): 80 Public property to access the type used to create this text marker. 81 82 (WebInspector.TextMarker.prototype.get range): 83 (WebInspector.TextMarker.prototype.get bounds): 84 Public properties allowing easy access to generally useful information related to marked text. 85 86 (WebInspector.TextMarker.prototype.clear): 87 Wrapper for the CodeMirror TextMarker clear() method. 88 1 89 2013-12-13 Brent Fulgham <bfulgham@apple.com> 2 90 -
trunk/Source/WebInspectorUI/UserInterface/CodeMirrorAdditions.js
r160483 r160552 451 451 var markers = this.findMarksAt(to); 452 452 for (var j = 0; j < markers.length; ++j) { 453 if ( !markers[j].__markedColor)454 continue;455 foundColorMarker = true;456 break;453 if (WebInspector.TextMarker.textMarkerForCodeMirrorTextMarker(markers[j]).type === WebInspector.TextMarker.Type.Color) { 454 foundColorMarker = true; 455 break; 456 } 457 457 } 458 458 … … 470 470 471 471 var marker = this.markText(from, to); 472 marker .__markedColor = true;472 marker = new WebInspector.TextMarker(marker, WebInspector.TextMarker.Type.Color); 473 473 474 474 createdMarkers.push(marker); -
trunk/Source/WebInspectorUI/UserInterface/CodeMirrorColorEditingController.js
r160483 r160552 32 32 this._delegate = null; 33 33 34 this._range = marker.find(); 35 36 this._color = WebInspector.Color.fromString(codeMirror.getRange(this._range.from, this._range.to)); 34 this._range = marker.range; 35 this._color = WebInspector.Color.fromString(this.text); 37 36 38 37 this._keyboardShortcutEsc = new WebInspector.KeyboardShortcut(null, WebInspector.KeyboardShortcut.Key.Escape); … … 62 61 set color(color) 63 62 { 64 var colorText = color.toString(); 65 this._codeMirror.replaceRange(colorText, this._range.from, this._range.to); 66 this._range.to.ch = this._range.from.ch + colorText.length; 67 63 this.text = color.toString(); 68 64 this._color = color; 69 65 }, … … 78 74 this._delegate = delegate; 79 75 }, 76 77 get text() 78 { 79 var from = {line: this._range.startLine, ch: this._range.startColumn}; 80 var to = {line: this._range.endLine, ch: this._range.endColumn}; 81 return this._codeMirror.getRange(from, to); 82 }, 83 84 set text(text) 85 { 86 var from = {line: this._range.startLine, ch: this._range.startColumn}; 87 var to = {line: this._range.endLine, ch: this._range.endColumn}; 88 this._codeMirror.replaceRange(text, from, to); 89 90 var lines = text.split("\n"); 91 var endLine = this._range.startLine + lines.length - 1; 92 var endColumn = lines.length > 1 ? lines.lastValue.length : this._range.startColumn + text.length; 93 this._range = new WebInspector.TextRange(this._range.startLine, this._range.startColumn, endLine, endColumn); 94 }, 80 95 81 96 presentHoverMenu: function() … … 83 98 this._hoverMenu = new WebInspector.HoverMenu(this); 84 99 this._hoverMenu.element.classList.add("color"); 85 this._bounds = this._codeMirror.boundsForRange({ 86 start: this._range.from, 87 end: this._range.to 88 }); 100 this._bounds = this._marker.bounds; 89 101 this._hoverMenu.present(this._bounds); 90 102 }, -
trunk/Source/WebInspectorUI/UserInterface/CodeMirrorTokenTrackingController.js
r160483 r160552 306 306 if (!token || !token.type || !token.string) { 307 307 if (this._hoveredMarker && this._delegate && typeof this._delegate.tokenTrackingControllerMouseOutOfHoveredMarker === "function") { 308 var markers = this._codeMirror.findMarksAt(position); 309 if (!markers.contains(this._hoveredMarker)) 308 if (!this._codeMirror.findMarksAt(position).contains(this._hoveredMarker.codeMirrorTextMarker)) 310 309 this._delegate.tokenTrackingControllerMouseOutOfHoveredMarker(this, this._hoveredMarker); 311 310 } -
trunk/Source/WebInspectorUI/UserInterface/Main.html
r160483 r160552 287 287 <script src="SearchResultTreeElement.js"></script> 288 288 <script src="TextRange.js"></script> 289 <script src="TextMarker.js"></script> 289 290 <script src="ConsoleMessage.js"></script> 290 291 <script src="ConsoleMessageImpl.js"></script> -
trunk/Source/WebInspectorUI/UserInterface/SourceCodeTextEditor.js
r160483 r160552 1017 1017 { 1018 1018 for (var marker of this.markers) { 1019 if (marker. __markedColor)1019 if (marker.type === WebInspector.TextMarker.Type.Color) 1020 1020 return true; 1021 1021 } … … 1071 1071 1072 1072 if (this.tokenTrackingController.mode === WebInspector.CodeMirrorTokenTrackingController.Mode.MarkedTokens) { 1073 var markers = this. findMarkersAtPosition(candidate.hoveredTokenRange.start);1073 var markers = this.markersAtPosition(candidate.hoveredTokenRange.start); 1074 1074 if (markers.length > 0) 1075 1075 this._tokenTrackingControllerHighlightedMarkedExpression(candidate, markers); … … 1299 1299 var colorMarker; 1300 1300 for (var marker of markers) { 1301 if (marker. __markedColor) {1301 if (marker.type === WebInspector.TextMarker.Type.Color) { 1302 1302 colorMarker = marker; 1303 1303 break; … … 1357 1357 colorEditingControllerDidFinishEditing: function(colorEditingController) 1358 1358 { 1359 this._updateColorMarkers(colorEditingController.range. from.line);1359 this._updateColorMarkers(colorEditingController.range.startLine); 1360 1360 1361 1361 this._ignoreContentDidChange--; -
trunk/Source/WebInspectorUI/UserInterface/TextEditor.js
r160483 r160552 604 604 get markers() 605 605 { 606 // FIXME: we should not return CodeMirror TextMarker objects but rather wrappers. 607 return this._codeMirror.getAllMarks(); 608 }, 609 610 findMarkersAtPosition: function(position) 611 { 612 return this._codeMirror.findMarksAt(position); 606 return this._codeMirror.getAllMarks().map(function(codeMirrorTextMarker) { 607 return WebInspector.TextMarker.textMarkerForCodeMirrorTextMarker(codeMirrorTextMarker); 608 }); 609 }, 610 611 markersAtPosition: function(position) 612 { 613 return this._codeMirror.findMarksAt(position).map(function(codeMirrorTextMarker) { 614 return WebInspector.TextMarker.textMarkerForCodeMirrorTextMarker(codeMirrorTextMarker); 615 }); 613 616 }, 614 617
Note: See TracChangeset
for help on using the changeset viewer.