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

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/sources/JavaScriptSourceFrame.js

Issue 2526013002: [DevTools] Added inline breakpoints (Closed)
Patch Set: rebased test Created 4 years 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011 Google Inc. All rights reserved. 2 * Copyright (C) 2011 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 * @override 204 * @override
205 * @return {!Promise} 205 * @return {!Promise}
206 */ 206 */
207 populateLineGutterContextMenu(contextMenu, lineNumber) { 207 populateLineGutterContextMenu(contextMenu, lineNumber) {
208 /** 208 /**
209 * @this {Sources.JavaScriptSourceFrame} 209 * @this {Sources.JavaScriptSourceFrame}
210 */ 210 */
211 function populate(resolve, reject) { 211 function populate(resolve, reject) {
212 var uiLocation = new Workspace.UILocation(this.uiSourceCode(), lineNumber, 0); 212 var uiLocation = new Workspace.UILocation(this.uiSourceCode(), lineNumber, 0);
213 this._scriptsPanel.appendUILocationItems(contextMenu, uiLocation); 213 this._scriptsPanel.appendUILocationItems(contextMenu, uiLocation);
214 var breakpoints = this._lineBreakpointDecorations(lineNumber).map(decorati on => decoration.breakpoint); 214 var breakpoints = this._lineBreakpointDecorations(lineNumber)
215 .map(decoration => decoration.breakpoint)
216 .filter(breakpoint => !!breakpoint);
215 if (!breakpoints.length) { 217 if (!breakpoints.length) {
216 // This row doesn't have a breakpoint: We want to show Add Breakpoint an d Add and Edit Breakpoint.
217 contextMenu.appendItem( 218 contextMenu.appendItem(
218 Common.UIString('Add breakpoint'), this._createNewBreakpoint.bind(th is, lineNumber, '', true)); 219 Common.UIString('Add breakpoint'), this._createNewBreakpoint.bind(th is, lineNumber, '', true));
219 contextMenu.appendItem( 220 contextMenu.appendItem(
220 Common.UIString('Add conditional breakpoint\u2026'), this._editBreak pointCondition.bind(this, lineNumber)); 221 Common.UIString('Add conditional breakpoint\u2026'),
222 this._editBreakpointCondition.bind(this, lineNumber, null, null));
221 contextMenu.appendItem( 223 contextMenu.appendItem(
222 Common.UIString('Never pause here'), this._createNewBreakpoint.bind( this, lineNumber, 'false', true)); 224 Common.UIString('Never pause here'), this._createNewBreakpoint.bind( this, lineNumber, 'false', true));
223 } else { 225 } else {
224 var hasOneBreakpoint = breakpoints.length === 1; 226 var hasOneBreakpoint = breakpoints.length === 1;
225 var removeTitle = 227 var removeTitle =
226 hasOneBreakpoint ? Common.UIString('Remove breakpoint') : Common.UIS tring('Remove all breakpoints in line'); 228 hasOneBreakpoint ? Common.UIString('Remove breakpoint') : Common.UIS tring('Remove all breakpoints in line');
227 contextMenu.appendItem(removeTitle, () => breakpoints.map(breakpoint => breakpoint.remove())); 229 contextMenu.appendItem(removeTitle, () => breakpoints.map(breakpoint => breakpoint.remove()));
228 if (hasOneBreakpoint) { 230 if (hasOneBreakpoint) {
229 contextMenu.appendItem( 231 contextMenu.appendItem(
230 Common.UIString('Edit breakpoint\u2026'), 232 Common.UIString('Edit breakpoint\u2026'),
231 this._editBreakpointCondition.bind(this, lineNumber, breakpoints[0 ])); 233 this._editBreakpointCondition.bind(this, lineNumber, breakpoints[0 ], null));
232 } 234 }
233 var hasEnabled = breakpoints.some(breakpoint => breakpoint.enabled()); 235 var hasEnabled = breakpoints.some(breakpoint => breakpoint.enabled());
234 if (hasEnabled) { 236 if (hasEnabled) {
235 var title = hasOneBreakpoint ? Common.UIString('Disable breakpoint') : 237 var title = hasOneBreakpoint ? Common.UIString('Disable breakpoint') :
236 Common.UIString('Disable all breakpoint s in line'); 238 Common.UIString('Disable all breakpoint s in line');
237 contextMenu.appendItem(title, () => breakpoints.map(breakpoint => brea kpoint.setEnabled(false))); 239 contextMenu.appendItem(title, () => breakpoints.map(breakpoint => brea kpoint.setEnabled(false)));
238 } 240 }
239 var hasDisabled = breakpoints.some(breakpoint => !breakpoint.enabled()); 241 var hasDisabled = breakpoints.some(breakpoint => !breakpoint.enabled());
240 if (hasDisabled) { 242 if (hasDisabled) {
241 var title = hasOneBreakpoint ? Common.UIString('Enable breakpoint') : 243 var title = hasOneBreakpoint ? Common.UIString('Enable breakpoint') :
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
340 return; 342 return;
341 } 343 }
342 344
343 this._restoreBreakpointsAfterEditing(); 345 this._restoreBreakpointsAfterEditing();
344 } 346 }
345 347
346 _restoreBreakpointsAfterEditing() { 348 _restoreBreakpointsAfterEditing() {
347 delete this._muted; 349 delete this._muted;
348 var decorations = Array.from(this._breakpointDecorations); 350 var decorations = Array.from(this._breakpointDecorations);
349 this._breakpointDecorations.clear(); 351 this._breakpointDecorations.clear();
352 this._textEditor.operation(() => decorations.map(decoration => decoration.hi de()));
350 for (var decoration of decorations) { 353 for (var decoration of decorations) {
354 if (!decoration.breakpoint)
355 continue;
356 var enabled = decoration.enabled;
351 decoration.breakpoint.remove(); 357 decoration.breakpoint.remove();
352 var location = decoration.handle.resolve(); 358 var location = decoration.handle.resolve();
353 if (location) 359 if (location)
354 this._setBreakpoint(location.lineNumber, location.columnNumber, decorati on.condition, decoration.enabled); 360 this._setBreakpoint(location.lineNumber, location.columnNumber, decorati on.condition, enabled);
355 } 361 }
356 } 362 }
357 363
358 /** 364 /**
359 * @param {string} tokenType 365 * @param {string} tokenType
360 * @return {boolean} 366 * @return {boolean}
361 */ 367 */
362 _isIdentifier(tokenType) { 368 _isIdentifier(tokenType) {
363 return tokenType.startsWith('js-variable') || tokenType.startsWith('js-prope rty') || tokenType === 'js-def'; 369 return tokenType.startsWith('js-variable') || tokenType.startsWith('js-prope rty') || tokenType === 'js-def';
364 } 370 }
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
483 if (event.key === 'Escape') { 489 if (event.key === 'Escape') {
484 if (this._popoverHelper.isPopoverVisible()) { 490 if (this._popoverHelper.isPopoverVisible()) {
485 this._popoverHelper.hidePopover(); 491 this._popoverHelper.hidePopover();
486 event.consume(); 492 event.consume();
487 } 493 }
488 } 494 }
489 } 495 }
490 496
491 /** 497 /**
492 * @param {number} lineNumber 498 * @param {number} lineNumber
493 * @param {!Bindings.BreakpointManager.Breakpoint=} breakpoint 499 * @param {?Bindings.BreakpointManager.Breakpoint} breakpoint
500 * @param {?{lineNumber: number, columnNumber: number}} location
494 */ 501 */
495 _editBreakpointCondition(lineNumber, breakpoint) { 502 _editBreakpointCondition(lineNumber, breakpoint, location) {
496 this._conditionElement = this._createConditionElement(lineNumber); 503 this._conditionElement = this._createConditionElement(lineNumber);
497 this.textEditor.addDecoration(this._conditionElement, lineNumber); 504 this.textEditor.addDecoration(this._conditionElement, lineNumber);
498 505
499 /** 506 /**
500 * @this {Sources.JavaScriptSourceFrame} 507 * @this {Sources.JavaScriptSourceFrame}
501 */ 508 */
502 function finishEditing(committed, element, newText) { 509 function finishEditing(committed, element, newText) {
503 this.textEditor.removeDecoration(this._conditionElement, lineNumber); 510 this.textEditor.removeDecoration(this._conditionElement, lineNumber);
504 delete this._conditionEditorElement; 511 delete this._conditionEditorElement;
505 delete this._conditionElement; 512 delete this._conditionElement;
506 if (!committed) 513 if (!committed)
507 return; 514 return;
508 515
509 if (breakpoint) 516 if (breakpoint)
510 breakpoint.setCondition(newText); 517 breakpoint.setCondition(newText);
518 else if (location)
519 this._setBreakpoint(location.lineNumber, location.columnNumber, newText, true);
511 else 520 else
512 this._createNewBreakpoint(lineNumber, newText, true); 521 this._createNewBreakpoint(lineNumber, newText, true);
513 } 522 }
514 523
515 var config = new UI.InplaceEditor.Config(finishEditing.bind(this, true), fin ishEditing.bind(this, false)); 524 var config = new UI.InplaceEditor.Config(finishEditing.bind(this, true), fin ishEditing.bind(this, false));
516 UI.InplaceEditor.startEditing(this._conditionEditorElement, config); 525 UI.InplaceEditor.startEditing(this._conditionEditorElement, config);
517 this._conditionEditorElement.value = breakpoint ? breakpoint.condition() : ' '; 526 this._conditionEditorElement.value = breakpoint ? breakpoint.condition() : ' ';
518 this._conditionEditorElement.select(); 527 this._conditionEditorElement.select();
519 } 528 }
520 529
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
730 /** 739 /**
731 * @param {number} lineNumber 740 * @param {number} lineNumber
732 * @return {!Array<!Sources.JavaScriptSourceFrame.BreakpointDecoration>} 741 * @return {!Array<!Sources.JavaScriptSourceFrame.BreakpointDecoration>}
733 */ 742 */
734 _lineBreakpointDecorations(lineNumber) { 743 _lineBreakpointDecorations(lineNumber) {
735 return Array.from(this._breakpointDecorations) 744 return Array.from(this._breakpointDecorations)
736 .filter(decoration => (decoration.handle.resolve() || {}).lineNumber === lineNumber); 745 .filter(decoration => (decoration.handle.resolve() || {}).lineNumber === lineNumber);
737 } 746 }
738 747
739 /** 748 /**
749 * @param {number} lineNumber
750 * @param {number} columnNumber
751 * @return {?Sources.JavaScriptSourceFrame.BreakpointDecoration}
752 */
753 _breakpointDecoration(lineNumber, columnNumber) {
754 for (var decoration of this._breakpointDecorations) {
755 var location = decoration.handle.resolve();
756 if (!location)
757 continue;
758 if (location.lineNumber === lineNumber && location.columnNumber === column Number)
759 return decoration;
760 }
761 return null;
762 }
763
764 /**
740 * @param {!Sources.JavaScriptSourceFrame.BreakpointDecoration} decoration 765 * @param {!Sources.JavaScriptSourceFrame.BreakpointDecoration} decoration
741 */ 766 */
742 _updateBreakpointDecoration(decoration) { 767 _updateBreakpointDecoration(decoration) {
743 if (!this._scheduledBreakpointDecorationUpdates) { 768 if (!this._scheduledBreakpointDecorationUpdates) {
744 /** @type {!Set<!Sources.JavaScriptSourceFrame.BreakpointDecoration>} */ 769 /** @type {!Set<!Sources.JavaScriptSourceFrame.BreakpointDecoration>} */
745 this._scheduledBreakpointDecorationUpdates = new Set(); 770 this._scheduledBreakpointDecorationUpdates = new Set();
746 setImmediate(() => this.textEditor.operation(update.bind(this))); 771 setImmediate(() => this.textEditor.operation(update.bind(this)));
747 } 772 }
748 this._scheduledBreakpointDecorationUpdates.add(decoration); 773 this._scheduledBreakpointDecorationUpdates.add(decoration);
749 774
750 /** 775 /**
751 * @this {Sources.JavaScriptSourceFrame} 776 * @this {Sources.JavaScriptSourceFrame}
752 */ 777 */
753 function update() { 778 function update() {
754 var lineNumbers = new Set(); 779 var lineNumbers = new Set();
755 for (var decoration of this._scheduledBreakpointDecorationUpdates) { 780 for (var decoration of this._scheduledBreakpointDecorationUpdates) {
756 var location = decoration.handle.resolve(); 781 var location = decoration.handle.resolve();
757 if (!location) 782 if (!location)
758 continue; 783 continue;
759 lineNumbers.add(location.lineNumber); 784 lineNumbers.add(location.lineNumber);
760 } 785 }
786 delete this._scheduledBreakpointDecorationUpdates;
761 for (var lineNumber of lineNumbers) { 787 for (var lineNumber of lineNumbers) {
762 this.textEditor.toggleLineClass(lineNumber, 'cm-breakpoint', false); 788 this.textEditor.toggleLineClass(lineNumber, 'cm-breakpoint', false);
763 this.textEditor.toggleLineClass(lineNumber, 'cm-breakpoint-disabled', fa lse); 789 this.textEditor.toggleLineClass(lineNumber, 'cm-breakpoint-disabled', fa lse);
764 this.textEditor.toggleLineClass(lineNumber, 'cm-breakpoint-conditional', false); 790 this.textEditor.toggleLineClass(lineNumber, 'cm-breakpoint-conditional', false);
791
765 var decorations = this._lineBreakpointDecorations(lineNumber); 792 var decorations = this._lineBreakpointDecorations(lineNumber);
793 var actualBookmarks =
794 new Set(decorations.map(decoration => decoration.bookmark).filter(bo okmark => !!bookmark));
795 var lineEnd = this._textEditor.line(lineNumber).length;
796 var bookmarks = this._textEditor.bookmarks(
797 new Common.TextRange(lineNumber, 0, lineEnd, 0),
798 Sources.JavaScriptSourceFrame.BreakpointDecoration.bookmarkSymbol);
799 for (var bookmark of bookmarks) {
800 if (!actualBookmarks.has(bookmark))
801 bookmark.clear();
802 }
766 if (!decorations.length) 803 if (!decorations.length)
767 continue; 804 continue;
768 decorations.sort(Sources.JavaScriptSourceFrame.BreakpointDecoration.most SpecificFirst); 805 decorations.sort(Sources.JavaScriptSourceFrame.BreakpointDecoration.most SpecificFirst);
769 this.textEditor.toggleLineClass(lineNumber, 'cm-breakpoint', true); 806 this.textEditor.toggleLineClass(lineNumber, 'cm-breakpoint', true);
770 this.textEditor.toggleLineClass(lineNumber, 'cm-breakpoint-disabled', !d ecorations[0].enabled || this._muted); 807 this.textEditor.toggleLineClass(lineNumber, 'cm-breakpoint-disabled', !d ecorations[0].enabled || this._muted);
771 this.textEditor.toggleLineClass(lineNumber, 'cm-breakpoint-conditional', !!decorations[0].condition); 808 this.textEditor.toggleLineClass(lineNumber, 'cm-breakpoint-conditional', !!decorations[0].condition);
809 if (decorations.length > 1) {
810 for (var decoration of decorations) {
811 decoration.update();
812 if (!this._muted)
813 decoration.show();
814 else
815 decoration.hide();
816 }
817 } else {
818 decorations[0].update();
819 decorations[0].hide();
820 }
772 } 821 }
773 delete this._scheduledBreakpointDecorationUpdates;
774 this._breakpointDecorationsUpdatedForTest(); 822 this._breakpointDecorationsUpdatedForTest();
775 } 823 }
776 } 824 }
777 825
778 _breakpointDecorationsUpdatedForTest() { 826 _breakpointDecorationsUpdatedForTest() {
779 } 827 }
780 828
781 /** 829 /**
830 * @param {!Sources.JavaScriptSourceFrame.BreakpointDecoration} decoration
831 * @param {!Event} event
832 */
833 _inlineBreakpointClick(decoration, event) {
834 event.consume(true);
835 if (decoration.breakpoint) {
836 if (event.shiftKey)
837 decoration.breakpoint.setEnabled(!decoration.breakpoint.enabled());
838 else
839 decoration.breakpoint.remove();
840 } else {
841 var location = decoration.handle.resolve();
842 if (!location)
843 return;
844 this._setBreakpoint(location.lineNumber, location.columnNumber, decoration .condition, true);
845 }
846 }
847
848 /**
849 * @param {!Sources.JavaScriptSourceFrame.BreakpointDecoration} decoration
850 * @param {!Event} event
851 */
852 _inlineBreakpointContextMenu(decoration, event) {
853 event.consume(true);
854 var location = decoration.handle.resolve();
855 if (!location)
856 return;
857 var contextMenu = new UI.ContextMenu(event);
858 if (decoration.breakpoint) {
859 contextMenu.appendItem(
860 Common.UIString('Edit breakpoint\u2026'),
861 this._editBreakpointCondition.bind(this, location.lineNumber, decorati on.breakpoint, null));
862 } else {
863 contextMenu.appendItem(
864 Common.UIString('Add conditional breakpoint\u2026'),
865 this._editBreakpointCondition.bind(this, location.lineNumber, null, lo cation));
866 contextMenu.appendItem(
867 Common.UIString('Never pause here'),
868 this._setBreakpoint.bind(this, location.lineNumber, location.columnNum ber, 'false', true));
869 }
870 contextMenu.show();
871 }
872
873 /**
782 * @param {!Common.Event} event 874 * @param {!Common.Event} event
783 * @return {boolean} 875 * @return {boolean}
784 */ 876 */
785 _shouldIgnoreExternalBreakpointEvents(event) { 877 _shouldIgnoreExternalBreakpointEvents(event) {
786 var uiLocation = /** @type {!Workspace.UILocation} */ (event.data.uiLocation ); 878 var uiLocation = /** @type {!Workspace.UILocation} */ (event.data.uiLocation );
787 if (uiLocation.uiSourceCode !== this.uiSourceCode() || !this.loaded) 879 if (uiLocation.uiSourceCode !== this.uiSourceCode() || !this.loaded)
788 return true; 880 return true;
789 if (this._supportsEnabledBreakpointsWhileEditing()) 881 if (this._supportsEnabledBreakpointsWhileEditing())
790 return false; 882 return false;
791 if (this._muted) 883 if (this._muted)
792 return true; 884 return true;
793 var scriptFiles = this._scriptFileForTarget.valuesArray(); 885 var scriptFiles = this._scriptFileForTarget.valuesArray();
794 for (var i = 0; i < scriptFiles.length; ++i) { 886 for (var i = 0; i < scriptFiles.length; ++i) {
795 if (scriptFiles[i].isDivergingFromVM() || scriptFiles[i].isMergingToVM()) 887 if (scriptFiles[i].isDivergingFromVM() || scriptFiles[i].isMergingToVM())
796 return true; 888 return true;
797 } 889 }
798 return false; 890 return false;
799 } 891 }
800 892
801 /** 893 /**
802 * @param {!Common.Event} event 894 * @param {!Common.Event} event
803 */ 895 */
804 _breakpointAdded(event) { 896 _breakpointAdded(event) {
805 if (this._shouldIgnoreExternalBreakpointEvents(event)) 897 if (this._shouldIgnoreExternalBreakpointEvents(event))
806 return; 898 return;
807 var uiLocation = /** @type {!Workspace.UILocation} */ (event.data.uiLocation ); 899 var uiLocation = /** @type {!Workspace.UILocation} */ (event.data.uiLocation );
808 var handle = this._textEditor.textEditorPositionHandle(uiLocation.lineNumber , uiLocation.columnNumber); 900 var lineDecorations = this._lineBreakpointDecorations(uiLocation.lineNumber) ;
809 var breakpoint = /** @type {!Bindings.BreakpointManager.Breakpoint} */ (even t.data.breakpoint); 901 var breakpoint = /** @type {!Bindings.BreakpointManager.Breakpoint} */ (even t.data.breakpoint);
810 var decoration = new Sources.JavaScriptSourceFrame.BreakpointDecoration(hand le, breakpoint); 902
811 this._breakpointDecorations.add(decoration); 903 var decoration = this._breakpointDecoration(uiLocation.lineNumber, uiLocatio n.columnNumber);
904 if (decoration) {
905 decoration.breakpoint = breakpoint;
906 decoration.condition = breakpoint.condition();
907 decoration.enabled = breakpoint.enabled();
908 } else {
909 var handle = this._textEditor.textEditorPositionHandle(uiLocation.lineNumb er, uiLocation.columnNumber);
910 decoration = new Sources.JavaScriptSourceFrame.BreakpointDecoration(
911 this._textEditor, handle, breakpoint.condition(), breakpoint.enabled() , breakpoint);
912 decoration.element.addEventListener('click', this._inlineBreakpointClick.b ind(this, decoration), true);
913 decoration.element.addEventListener(
914 'contextmenu', this._inlineBreakpointContextMenu.bind(this, decoration ), true);
915 this._breakpointDecorations.add(decoration);
916 }
812 breakpoint[Sources.JavaScriptSourceFrame.BreakpointDecoration._decorationSym bol] = decoration; 917 breakpoint[Sources.JavaScriptSourceFrame.BreakpointDecoration._decorationSym bol] = decoration;
813 this._updateBreakpointDecoration(decoration); 918 this._updateBreakpointDecoration(decoration);
919 if (!lineDecorations.length && Runtime.experiments.isEnabled('inlineBreakpoi nts')) {
920 this._willAddInlineDecorationsForTest();
921 this._breakpointManager
922 .possibleBreakpoints(
923 this.uiSourceCode(), new Common.TextRange(uiLocation.lineNumber, 0 , uiLocation.lineNumber + 1, 0))
924 .then(addInlineDecorations.bind(this, uiLocation.lineNumber));
925 }
926
927 /**
928 * @this {Sources.JavaScriptSourceFrame}
929 * @param {number} lineNumber
930 * @param {!Array<!Workspace.UILocation>} possibleLocations
931 */
932 function addInlineDecorations(lineNumber, possibleLocations) {
933 var decorations = this._lineBreakpointDecorations(lineNumber);
934 if (!decorations.some(decoration => !!decoration.breakpoint)) {
935 this._didAddInlineDecorationsForTest(false);
936 return;
937 }
938 /** @type {!Set<number>} */
939 var columns = new Set();
940 for (var decoration of decorations) {
941 var location = decoration.handle.resolve();
942 if (!location)
943 continue;
944 columns.add(location.columnNumber);
945 }
946 var updateWasScheduled = false;
947 for (var location of possibleLocations) {
948 if (columns.has(location.columnNumber))
949 continue;
950 var handle = this._textEditor.textEditorPositionHandle(location.lineNumb er, location.columnNumber);
951 var decoration =
952 new Sources.JavaScriptSourceFrame.BreakpointDecoration(this._textEdi tor, handle, '', false, null);
953 decoration.element.addEventListener('click', this._inlineBreakpointClick .bind(this, decoration), true);
954 decoration.element.addEventListener(
955 'contextmenu', this._inlineBreakpointContextMenu.bind(this, decorati on), true);
956 this._breakpointDecorations.add(decoration);
957 updateWasScheduled = true;
958 this._updateBreakpointDecoration(decoration);
959 }
960 this._didAddInlineDecorationsForTest(updateWasScheduled);
961 }
962 }
963
964 _willAddInlineDecorationsForTest() {
814 } 965 }
815 966
816 /** 967 /**
968 * @param {boolean} updateWasScheduled
969 */
970 _didAddInlineDecorationsForTest(updateWasScheduled) {
971 }
972
973 /**
817 * @param {!Common.Event} event 974 * @param {!Common.Event} event
818 */ 975 */
819 _breakpointRemoved(event) { 976 _breakpointRemoved(event) {
820 if (this._shouldIgnoreExternalBreakpointEvents(event)) 977 if (this._shouldIgnoreExternalBreakpointEvents(event))
821 return; 978 return;
979 var uiLocation = /** @type {!Workspace.UILocation} */ (event.data.uiLocation );
822 var breakpoint = /** @type {!Bindings.BreakpointManager.Breakpoint} */ (even t.data.breakpoint); 980 var breakpoint = /** @type {!Bindings.BreakpointManager.Breakpoint} */ (even t.data.breakpoint);
823 var decoration = breakpoint[Sources.JavaScriptSourceFrame.BreakpointDecorati on._decorationSymbol]; 981 var decoration = breakpoint[Sources.JavaScriptSourceFrame.BreakpointDecorati on._decorationSymbol];
824 if (!decoration) 982 if (!decoration)
825 return; 983 return;
826 this._breakpointDecorations.delete(decoration);
827 delete breakpoint[Sources.JavaScriptSourceFrame.BreakpointDecoration._decora tionSymbol]; 984 delete breakpoint[Sources.JavaScriptSourceFrame.BreakpointDecoration._decora tionSymbol];
828 this._updateBreakpointDecoration(decoration); 985
986 decoration.breakpoint = null;
987 decoration.enabled = false;
988
989 var lineDecorations = this._lineBreakpointDecorations(uiLocation.lineNumber) ;
990 if (!lineDecorations.some(decoration => !!decoration.breakpoint)) {
991 for (var lineDecoration of lineDecorations) {
992 this._breakpointDecorations.delete(lineDecoration);
993 this._updateBreakpointDecoration(lineDecoration);
994 }
995 } else {
996 this._updateBreakpointDecoration(decoration);
997 }
829 } 998 }
830 999
831 /** 1000 /**
832 * @param {!Common.Event} event 1001 * @param {!Common.Event} event
833 */ 1002 */
834 _onSourceMappingChanged(event) { 1003 _onSourceMappingChanged(event) {
835 var data = /** @type {{target: !SDK.Target}} */ (event.data); 1004 var data = /** @type {{target: !SDK.Target}} */ (event.data);
836 this._updateScriptFile(data.target); 1005 this._updateScriptFile(data.target);
837 this._updateLinesWithoutMappingHighlight(); 1006 this._updateLinesWithoutMappingHighlight();
838 } 1007 }
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
966 * @param {number} lineNumber 1135 * @param {number} lineNumber
967 * @param {boolean} onlyDisable 1136 * @param {boolean} onlyDisable
968 */ 1137 */
969 _toggleBreakpoint(lineNumber, onlyDisable) { 1138 _toggleBreakpoint(lineNumber, onlyDisable) {
970 var decorations = this._lineBreakpointDecorations(lineNumber); 1139 var decorations = this._lineBreakpointDecorations(lineNumber);
971 if (!decorations.length) { 1140 if (!decorations.length) {
972 this._createNewBreakpoint(lineNumber, '', true); 1141 this._createNewBreakpoint(lineNumber, '', true);
973 return; 1142 return;
974 } 1143 }
975 var hasDisabled = this._textEditor.hasLineClass(lineNumber, 'cm-breakpoint-d isabled'); 1144 var hasDisabled = this._textEditor.hasLineClass(lineNumber, 'cm-breakpoint-d isabled');
976 var breakpoints = decorations.map(decoration => decoration.breakpoint); 1145 var breakpoints = decorations.map(decoration => decoration.breakpoint).filte r(breakpoint => !!breakpoint);
977 for (var breakpoint of breakpoints) { 1146 for (var breakpoint of breakpoints) {
978 if (onlyDisable) 1147 if (onlyDisable)
979 breakpoint.setEnabled(hasDisabled); 1148 breakpoint.setEnabled(hasDisabled);
980 else 1149 else
981 breakpoint.remove(); 1150 breakpoint.remove();
982 } 1151 }
983 } 1152 }
984 1153
985 /** 1154 /**
986 * @param {number} lineNumber 1155 * @param {number} lineNumber
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
1090 Common.moduleSetting('skipContentScripts').removeChangeListener(this._showBl ackboxInfobarIfNeeded, this); 1259 Common.moduleSetting('skipContentScripts').removeChangeListener(this._showBl ackboxInfobarIfNeeded, this);
1091 super.dispose(); 1260 super.dispose();
1092 } 1261 }
1093 }; 1262 };
1094 1263
1095 /** 1264 /**
1096 * @unrestricted 1265 * @unrestricted
1097 */ 1266 */
1098 Sources.JavaScriptSourceFrame.BreakpointDecoration = class { 1267 Sources.JavaScriptSourceFrame.BreakpointDecoration = class {
1099 /** 1268 /**
1269 * @param {!TextEditor.CodeMirrorTextEditor} textEditor
1100 * @param {!TextEditor.TextEditorPositionHandle} handle 1270 * @param {!TextEditor.TextEditorPositionHandle} handle
1101 * @param {!Bindings.BreakpointManager.Breakpoint} breakpoint 1271 * @param {string} condition
1272 * @param {boolean} enabled
1273 * @param {?Bindings.BreakpointManager.Breakpoint} breakpoint
1102 */ 1274 */
1103 constructor(handle, breakpoint) { 1275 constructor(textEditor, handle, condition, enabled, breakpoint) {
1276 this._textEditor = textEditor;
1104 this.handle = handle; 1277 this.handle = handle;
1105 this.condition = breakpoint.condition(); 1278 this.condition = condition;
1106 this.enabled = breakpoint.enabled(); 1279 this.enabled = enabled;
1107 this.breakpoint = breakpoint; 1280 this.breakpoint = breakpoint;
1281 this.element = UI.Icon.create('smallicon-inline-breakpoint');
1282 this.element.classList.toggle('cm-inline-breakpoint', true);
1283
1284 /** @type {?TextEditor.TextEditorBookMark} */
1285 this.bookmark = null;
1108 } 1286 }
1109 1287
1110 /** 1288 /**
1111 * @param {!Sources.JavaScriptSourceFrame.BreakpointDecoration} decoration1 1289 * @param {!Sources.JavaScriptSourceFrame.BreakpointDecoration} decoration1
1112 * @param {!Sources.JavaScriptSourceFrame.BreakpointDecoration} decoration2 1290 * @param {!Sources.JavaScriptSourceFrame.BreakpointDecoration} decoration2
1113 * @return {number} 1291 * @return {number}
1114 */ 1292 */
1115 static mostSpecificFirst(decoration1, decoration2) { 1293 static mostSpecificFirst(decoration1, decoration2) {
1294 if (decoration1.enabled !== decoration2.enabled)
1295 return decoration1.enabled ? -1 : 1;
1116 if (!!decoration1.condition !== !!decoration2.condition) 1296 if (!!decoration1.condition !== !!decoration2.condition)
1117 return !!decoration1.condition ? -1 : 1; 1297 return !!decoration1.condition ? -1 : 1;
1118 if (decoration1.enabled !== decoration2.enabled)
1119 return decoration1.enabled ? -1 : 1;
1120 return 0; 1298 return 0;
1121 } 1299 }
1300
1301 update() {
1302 if (!!this.condition)
1303 this.element.setIconType('smallicon-inline-breakpoint');
1304 else
1305 this.element.setIconType('smallicon-inline-breakpoint-conditional');
1306 this.element.classList.toggle('cm-inline-disabled', !this.enabled);
1307 }
1308
1309 show() {
1310 if (this.bookmark || !Runtime.experiments.isEnabled('inlineBreakpoints'))
1311 return;
1312 var location = this.handle.resolve();
1313 if (!location)
1314 return;
1315 this.bookmark = this._textEditor.addBookmark(
1316 location.lineNumber, location.columnNumber, this.element,
1317 Sources.JavaScriptSourceFrame.BreakpointDecoration.bookmarkSymbol);
1318 this.bookmark[Sources.JavaScriptSourceFrame.BreakpointDecoration._elementSym bolForTest] = this.element;
1319 }
1320
1321 hide() {
1322 if (!this.bookmark)
1323 return;
1324 this.bookmark.clear();
1325 this.bookmark = null;
1326 }
1122 }; 1327 };
1123 1328
1124 Sources.JavaScriptSourceFrame.BreakpointDecoration._decorationSymbol = Symbol('d ecoration'); 1329 Sources.JavaScriptSourceFrame.BreakpointDecoration._decorationSymbol = Symbol('d ecoration');
1330 Sources.JavaScriptSourceFrame.BreakpointDecoration.bookmarkSymbol = Symbol('book mark');
1331 Sources.JavaScriptSourceFrame.BreakpointDecoration._elementSymbolForTest = Symbo l('element');
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698