@@ -62,6 +62,7 @@ define(function (require, exports, module) {
6262 NativeApp = require ( "utils/NativeApp" ) ,
6363 StringUtils = require ( "utils/StringUtils" ) ,
6464 FileSystem = require ( "filesystem/FileSystem" ) ,
65+ DropdownButton = require ( "widgets/DropdownButton" ) ,
6566 BrowserStaticServer = require ( "./BrowserStaticServer" ) ,
6667 NodeStaticServer = require ( "./NodeStaticServer" ) ,
6768 LivePreviewSettings = require ( "./LivePreviewSettings" ) ,
@@ -95,6 +96,9 @@ define(function (require, exports, module) {
9596 </iframe>
9697 ` ;
9798
99+ let isEditModeEnabled = true ;
100+ let isHighlightModeEnabled = true ;
101+
98102 if ( Phoenix . isTestWindow ) {
99103 // for integ tests
100104 window . _livePreviewIntegTest = {
@@ -120,7 +124,8 @@ define(function (require, exports, module) {
120124 $safariButtonBallast ,
121125 $edgeButtonBallast ,
122126 $firefoxButtonBallast ,
123- $panelTitle ;
127+ $panelTitle ,
128+ $modeBtn ;
124129
125130 let customLivePreviewBannerShown = false ;
126131
@@ -139,6 +144,71 @@ define(function (require, exports, module) {
139144 editor . focus ( ) ;
140145 } ) ;
141146
147+
148+ function _toggleLivePreviewEditMode ( ) {
149+ isEditModeEnabled = ! isEditModeEnabled ;
150+ LiveDevelopment . setLivePreviewEditFeaturesActive ( isEditModeEnabled ) ;
151+ }
152+
153+ function _toggleHighlightMode ( ) {
154+ isHighlightModeEnabled = ! isHighlightModeEnabled ;
155+
156+ // only toggle highlights if the current state doesn't match what we want
157+ const currentHighlightState = _isLiveHighlightEnabled ( ) ;
158+ if ( currentHighlightState !== isHighlightModeEnabled ) {
159+ _toggleLiveHighlights ( ) ;
160+ }
161+
162+ Metrics . countEvent (
163+ Metrics . EVENT_TYPE . LIVE_PREVIEW , "highlightMode" , isHighlightModeEnabled ? "enable" : "disable"
164+ ) ;
165+ }
166+
167+ function _showModeSelectionDropdown ( event ) {
168+ const items = [ "Edit Mode" , "Highlight Mode" ] ;
169+
170+ const dropdown = new DropdownButton . DropdownButton ( "" , items , function ( item , index ) {
171+ // Add checkmark if the mode is enabled
172+ if ( ( index === 0 && isEditModeEnabled ) || ( index === 1 && isHighlightModeEnabled ) ) {
173+ return "✓ " + item ;
174+ }
175+ // when disabled we remove the check, add spacing so that content remains aligned
176+ return " " . repeat ( 4 ) + item ;
177+ } ) ;
178+
179+ // Append to document body for absolute positioning
180+ $ ( "body" ) . append ( dropdown . $button ) ;
181+
182+ // Position the dropdown at the mouse coordinates
183+ dropdown . $button . css ( {
184+ position : "absolute" ,
185+ left : event . pageX + "px" ,
186+ top : event . pageY + "px" ,
187+ zIndex : 1000
188+ } ) ;
189+
190+ // Add a custom class to override the max-height
191+ dropdown . dropdownExtraClasses = "mode-context-menu" ;
192+
193+ dropdown . showDropdown ( ) ;
194+
195+ $ ( ".mode-context-menu" ) . css ( "max-height" , "300px" ) ;
196+
197+ // handle the option selection
198+ dropdown . on ( "select" , function ( e , item , index ) {
199+ if ( index === 0 ) {
200+ _toggleLivePreviewEditMode ( ) ;
201+ } else if ( index === 1 ) {
202+ _toggleHighlightMode ( ) ;
203+ }
204+ } ) ;
205+
206+ // Remove the button after the dropdown is hidden
207+ dropdown . $button . css ( {
208+ display : "none"
209+ } ) ;
210+ }
211+
142212 function _isLiveHighlightEnabled ( ) {
143213 return CommandManager . get ( Commands . FILE_LIVE_HIGHLIGHT ) . getChecked ( ) ;
144214 }
@@ -402,6 +472,9 @@ define(function (require, exports, module) {
402472 $firefoxButtonBallast = $panel . find ( "#firefoxButtonBallast" ) ;
403473 $panelTitle = $panel . find ( "#panel-live-preview-title" ) ;
404474 $settingsIcon = $panel . find ( "#livePreviewSettingsBtn" ) ;
475+ $modeBtn = $panel . find ( "#livePreviewModeBtn" ) ;
476+
477+ $modeBtn . on ( "click" , _showModeSelectionDropdown ) ;
405478
406479 $panel . find ( ".live-preview-settings-banner-btn" ) . on ( "click" , ( ) => {
407480 CommandManager . execute ( Commands . FILE_LIVE_FILE_PREVIEW_SETTINGS ) ;
0 commit comments