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

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

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

Powered by Google App Engine
This is Rietveld 408576698