@@ -96,9 +96,6 @@ define(function (require, exports, module) {
9696 </iframe>
9797 ` ;
9898
99- let isEditModeEnabled = LiveDevelopment . isLPEditFeaturesActive ;
100- let isHighlightModeEnabled = null ; // Will be initialized later
101-
10299 if ( Phoenix . isTestWindow ) {
103100 // for integ tests
104101 window . _livePreviewIntegTest = {
@@ -144,42 +141,48 @@ define(function (require, exports, module) {
144141 } ) ;
145142
146143
147- function _toggleLivePreviewEditMode ( ) {
148- isEditModeEnabled = ! isEditModeEnabled ;
149- LiveDevelopment . setLivePreviewEditFeaturesActive ( isEditModeEnabled ) ;
144+ // this function is to check if the live highlight feature is enabled or not
145+ function _isLiveHighlightEnabled ( ) {
146+ return CommandManager . get ( Commands . FILE_LIVE_HIGHLIGHT ) . getChecked ( ) ;
147+ }
150148
151- // clear any existing markers and highlights when edit mode is disabled
152- if ( ! isEditModeEnabled ) {
153- LiveDevelopment . hideHighlight ( ) ;
154- LiveDevelopment . dismissLivePreviewBoxes ( ) ;
149+ /**
150+ * Live Preview 'Preview Mode'. in this mode no live preview highlight or any such features are active
151+ * Just the plain website
152+ */
153+ function _LPPreviewMode ( ) {
154+ LiveDevelopment . setLivePreviewEditFeaturesActive ( false ) ;
155+ if ( _isLiveHighlightEnabled ( ) ) {
156+ LiveDevelopment . togglePreviewHighlight ( ) ;
155157 }
156158 }
157159
158- function _toggleHighlightMode ( ) {
159- isHighlightModeEnabled = ! isHighlightModeEnabled ;
160-
161- // only toggle highlights if the current state doesn't match what we want
162- const currentHighlightState = _isLiveHighlightEnabled ( ) ;
163- if ( currentHighlightState !== isHighlightModeEnabled ) {
164- _toggleLiveHighlights ( ) ;
160+ /**
161+ * Live Preview 'Inspect Mode'. in this mode only the live preview matching with the source code is active
162+ * Meaning that if user clicks on some element that element's source code will be highlighted and vice versa
163+ */
164+ function _LPInspectMode ( ) {
165+ LiveDevelopment . setLivePreviewEditFeaturesActive ( false ) ;
166+ if ( ! _isLiveHighlightEnabled ( ) ) {
167+ LiveDevelopment . togglePreviewHighlight ( ) ;
165168 }
169+ }
166170
167- Metrics . countEvent (
168- Metrics . EVENT_TYPE . LIVE_PREVIEW , "highlightMode" , isHighlightModeEnabled ? "enable" : "disable"
169- ) ;
171+ /**
172+ * Live Preview 'Edit Mode'. this is the most interactive mode, in here the inspect features are available
173+ * along with that we also show element's highlighted boxes and such
174+ */
175+ function _LPEditMode ( ) {
176+ LiveDevelopment . setLivePreviewEditFeaturesActive ( true ) ;
177+ if ( ! _isLiveHighlightEnabled ( ) ) {
178+ LiveDevelopment . togglePreviewHighlight ( ) ;
179+ }
170180 }
171181
172182 function _showModeSelectionDropdown ( event ) {
173- const items = [ "Edit Mode" , "Highlight Mode" ] ;
183+ const items = [ "Preview Mode" , "Inspect Mode" , "Edit Mode"] ;
174184
175- const dropdown = new DropdownButton . DropdownButton ( "" , items , function ( item , index ) {
176- // Add checkmark if the mode is enabled
177- if ( ( index === 0 && isEditModeEnabled ) || ( index === 1 && isHighlightModeEnabled ) ) {
178- return "✓ " + item ;
179- }
180- // when disabled we remove the check, add spacing so that content remains aligned
181- return " " . repeat ( 4 ) + item ;
182- } ) ;
185+ const dropdown = new DropdownButton . DropdownButton ( "" , items ) ;
183186
184187 // Append to document body for absolute positioning
185188 $ ( "body" ) . append ( dropdown . $button ) ;
@@ -202,9 +205,18 @@ define(function (require, exports, module) {
202205 // handle the option selection
203206 dropdown . on ( "select" , function ( e , item , index ) {
204207 if ( index === 0 ) {
205- _toggleLivePreviewEditMode ( ) ;
208+ _LPPreviewMode ( ) ;
206209 } else if ( index === 1 ) {
207- _toggleHighlightMode ( ) ;
210+ _LPInspectMode ( ) ;
211+ } else if ( index === 2 ) {
212+ _LPEditMode ( ) ;
213+ }
214+
215+ // need to dismiss the previous highlighting and stuff
216+ LiveDevelopment . hideHighlight ( ) ;
217+ LiveDevelopment . dismissLivePreviewBoxes ( ) ;
218+ if ( $modeBtn ) {
219+ $modeBtn [ 0 ] . textContent = item ;
208220 }
209221 } ) ;
210222
@@ -214,10 +226,6 @@ define(function (require, exports, module) {
214226 } ) ;
215227 }
216228
217- function _isLiveHighlightEnabled ( ) {
218- return CommandManager . get ( Commands . FILE_LIVE_HIGHLIGHT ) . getChecked ( ) ;
219- }
220-
221229 function _getTrustProjectPage ( ) {
222230 const trustProjectMessage = StringUtils . format ( Strings . TRUST_PROJECT ,
223231 path . basename ( ProjectManager . getProjectRoot ( ) . fullPath ) ) ;
@@ -362,11 +370,6 @@ define(function (require, exports, module) {
362370 Metrics . countEvent ( Metrics . EVENT_TYPE . LIVE_PREVIEW , "pinURLBtn" , "click" ) ;
363371 }
364372
365- function _toggleLiveHighlights ( ) {
366- LiveDevelopment . togglePreviewHighlight ( ) ;
367- Metrics . countEvent ( Metrics . EVENT_TYPE . LIVE_PREVIEW , "HighlightBtn" , "click" ) ;
368- }
369-
370373 const ALLOWED_BROWSERS_NAMES = [ `chrome` , `firefox` , `safari` , `edge` , `browser` , `browserPrivate` ] ;
371374 function _popoutLivePreview ( browserName ) {
372375 // We cannot use $iframe.src here if panel is hidden
@@ -468,13 +471,6 @@ define(function (require, exports, module) {
468471 $settingsIcon = $panel . find ( "#livePreviewSettingsBtn" ) ;
469472 $modeBtn = $panel . find ( "#livePreviewModeBtn" ) ;
470473
471- // initialize the value
472- if ( isHighlightModeEnabled === null ) {
473- isHighlightModeEnabled = _isLiveHighlightEnabled ( ) ;
474- }
475-
476- $modeBtn . on ( "click" , _showModeSelectionDropdown ) ;
477-
478474 $panel . find ( ".live-preview-settings-banner-btn" ) . on ( "click" , ( ) => {
479475 CommandManager . execute ( Commands . FILE_LIVE_FILE_PREVIEW_SETTINGS ) ;
480476 Metrics . countEvent ( Metrics . EVENT_TYPE . LIVE_PREVIEW , "settingsBtnBanner" , "click" ) ;
@@ -506,6 +502,9 @@ define(function (require, exports, module) {
506502 $firefoxButton . on ( "click" , ( ) => {
507503 _popoutLivePreview ( "firefox" ) ;
508504 } ) ;
505+
506+ $modeBtn . on ( "click" , _showModeSelectionDropdown ) ;
507+
509508 _showOpenBrowserIcons ( ) ;
510509 $settingsIcon . click ( ( ) => {
511510 CommandManager . execute ( Commands . FILE_LIVE_FILE_PREVIEW_SETTINGS ) ;
0 commit comments