Skip to content

Commit bdb8476

Browse files
committed
refactor: remove highlight flag as we use mode now for preview, edit and hilight
1 parent f1d0acb commit bdb8476

File tree

13 files changed

+82
-131
lines changed

13 files changed

+82
-131
lines changed

src/LiveDevelopment/BrowserScripts/RemoteFunctions.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4442,7 +4442,7 @@ function RemoteFunctions(config = {}) {
44424442
}
44434443

44444444
function enableHoverListeners() {
4445-
if (config.mode === 'edit' && (config.highlight || shouldShowHighlightOnHover())) {
4445+
if (config.mode === 'edit' && shouldShowHighlightOnHover()) {
44464446
window.document.removeEventListener("mouseover", onElementHover);
44474447
window.document.removeEventListener("mouseout", onElementHoverOut);
44484448

@@ -5106,7 +5106,6 @@ function RemoteFunctions(config = {}) {
51065106
const newHighlightMode = getHighlightMode();
51075107
const highlightModeChanged = oldHighlightMode !== newHighlightMode;
51085108
const isModeChanged = oldConfig.mode !== config.mode;
5109-
const highlightSettingChanged = oldConfig.highlight !== config.highlight;
51105109

51115110
// Update hot corner state when mode changes
51125111
// Show animation when mode changes to help users discover the feature
@@ -5115,7 +5114,7 @@ function RemoteFunctions(config = {}) {
51155114
}
51165115

51175116
// Handle configuration changes
5118-
if (highlightModeChanged || isModeChanged || highlightSettingChanged) {
5117+
if (highlightModeChanged || isModeChanged) {
51195118
_handleConfigurationChange();
51205119
}
51215120

@@ -5147,7 +5146,7 @@ function RemoteFunctions(config = {}) {
51475146
function _updateEventListeners() {
51485147
window.document.removeEventListener("mouseover", onElementHover);
51495148
window.document.removeEventListener("mouseout", onElementHoverOut);
5150-
if (config.highlight || (config.mode === 'edit' && shouldShowHighlightOnHover())) {
5149+
if (config.mode === 'edit' && shouldShowHighlightOnHover()) {
51515150
window.document.addEventListener("mouseover", onElementHover);
51525151
window.document.addEventListener("mouseout", onElementHoverOut);
51535152
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* GNU AGPL-3.0 License
3+
*
4+
* Copyright (c) 2021 - present core.ai . All rights reserved.
5+
* Original work Copyright (c) 2012 - 2021 Adobe Systems Incorporated. All rights reserved.
6+
*
7+
* This program is free software: you can redistribute it and/or modify it
8+
* under the terms of the GNU Affero General Public License as published by
9+
* the Free Software Foundation, either version 3 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful, but WITHOUT
13+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License
15+
* for more details.
16+
*
17+
* You should have received a copy of the GNU Affero General Public License
18+
* along with this program. If not, see https://opensource.org/licenses/AGPL-3.0.
19+
*
20+
*/
21+
22+
/*global less, Phoenix */
23+
24+
/**
25+
* main integrates LiveDevelopment into Brackets
26+
*
27+
* This module creates two menu items:
28+
*
29+
* "Go Live": open or close a Live Development session and visualize the status
30+
* "Highlight": toggle source highlighting
31+
*/
32+
define(function main(require, exports, module) {
33+
exports.LIVE_PREVIEW_MODE = "preview";
34+
exports.LIVE_HIGHLIGHT_MODE = "highlight";
35+
exports.LIVE_EDIT_MODE = "edit";
36+
37+
exports.PREFERENCE_LIVE_PREVIEW_MODE = "livePreviewMode";
38+
});

src/LiveDevelopment/MultiBrowserImpl/documents/LiveDocument.js

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
define(function (require, exports, module) {
2323

2424

25-
var EditorManager = require("editor/EditorManager"),
25+
const CONSTANTS = require("LiveDevelopment/LivePreviewConstants"),
26+
EditorManager = require("editor/EditorManager"),
2627
EventDispatcher = require("utils/EventDispatcher"),
2728
PreferencesManager = require("preferences/PreferencesManager"),
2829
_ = require("thirdparty/lodash");
@@ -62,17 +63,9 @@ define(function (require, exports, module) {
6263

6364
this._onActiveEditorChange = this._onActiveEditorChange.bind(this);
6465
this._onCursorActivity = this._onCursorActivity.bind(this);
65-
this._onHighlightPrefChange = this._onHighlightPrefChange.bind(this);
6666

6767
EditorManager.on(`activeEditorChange.LiveDocument-${this.doc.file.fullPath}`, this._onActiveEditorChange);
6868

69-
PreferencesManager.stateManager.getPreference("livedevHighlight")
70-
.on(`change.LiveDocument-${this.doc.file.fullPath}`, this._onHighlightPrefChange);
71-
72-
// Redraw highlights when window gets focus. This ensures that the highlights
73-
// will be in sync with any DOM changes that may have occurred.
74-
$(window).on(`focus.LiveDocument-${this.doc.file.fullPath}`, this._onHighlightPrefChange);
75-
7669
if (editor) {
7770
// Attach now
7871
this._attachToEditor(editor);
@@ -88,9 +81,6 @@ define(function (require, exports, module) {
8881

8982
this._clearErrorDisplay();
9083
this._detachFromEditor();
91-
EditorManager.off(`activeEditorChange.LiveDocument-${this.doc.file.fullPath}`);
92-
PreferencesManager.stateManager.getPreference("livedevHighlight")
93-
.off(`change.LiveDocument-${this.doc.file.fullPath}`);
9484

9585
$(window).off(`focus.LiveDocument-${this.doc.file.fullPath}`);
9686
};
@@ -128,18 +118,6 @@ define(function (require, exports, module) {
128118
};
129119
};
130120

131-
/**
132-
* @private
133-
* Handles changes to the "Live Highlight" preference, switching it on/off in the browser as appropriate.
134-
*/
135-
LiveDocument.prototype._onHighlightPrefChange = function () {
136-
if (this.isHighlightEnabled()) {
137-
this.updateHighlight();
138-
} else {
139-
this.hideHighlight();
140-
}
141-
};
142-
143121
/**
144122
* @private
145123
* Handles when the active editor changes, attaching to the new editor if it's for the current document.
@@ -264,7 +242,7 @@ define(function (require, exports, module) {
264242
* @return {boolean}
265243
*/
266244
LiveDocument.prototype.isHighlightEnabled = function () {
267-
return PreferencesManager.getViewState("livedevHighlight");
245+
return PreferencesManager.get(CONSTANTS.PREFERENCE_LIVE_PREVIEW_MODE) !== CONSTANTS.LIVE_PREVIEW_MODE;
268246
};
269247

270248
/**

src/LiveDevelopment/MultiBrowserImpl/protocol/LiveDevProtocol.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ define(function (require, exports, module) {
4242
const EventDispatcher = require("utils/EventDispatcher");
4343

4444
// Text of the script we'll inject into the browser that handles protocol requests.
45-
const LiveDevProtocolRemote = require("text!LiveDevelopment/BrowserScripts/LiveDevProtocolRemote.js"),
45+
const CONSTANTS = require("LiveDevelopment/LivePreviewConstants"),
46+
LiveDevProtocolRemote = require("text!LiveDevelopment/BrowserScripts/LiveDevProtocolRemote.js"),
4647
DocumentObserver = require("text!LiveDevelopment/BrowserScripts/DocumentObserver.js"),
4748
LanguageManager = require("language/LanguageManager"),
4849
RemoteFunctions = require("text!LiveDevelopment/BrowserScripts/RemoteFunctions.js"),
@@ -148,9 +149,9 @@ define(function (require, exports, module) {
148149
}
149150

150151
function _tagSelectedInLivePreview(tagId, nodeName, contentEditable, allSelectors) {
151-
const highlightPref = PreferencesManager.getViewState("livedevHighlight");
152-
if(!highlightPref){
153-
// live preview highlight and reverse highlight feature is disabled
152+
const livePreviewMode = PreferencesManager.get(CONSTANTS.PREFERENCE_LIVE_PREVIEW_MODE);
153+
if(livePreviewMode === CONSTANTS.LIVE_PREVIEW_MODE){
154+
// hilights are enabled only in edit and highlight mode
154155
return;
155156
}
156157
const liveDoc = LiveDevMultiBrowser.getCurrentLiveDoc(),

src/LiveDevelopment/main.js

Lines changed: 22 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@
3232
define(function main(require, exports, module) {
3333

3434

35-
const Commands = require("command/Commands"),
35+
const CONSTANTS = require("LiveDevelopment/LivePreviewConstants"),
36+
Commands = require("command/Commands"),
3637
AppInit = require("utils/AppInit"),
3738
MultiBrowserLiveDev = require("LiveDevelopment/LiveDevMultiBrowser"),
3839
LivePreviewTransport = require("LiveDevelopment/MultiBrowserImpl/transports/LivePreviewTransport"),
@@ -48,13 +49,15 @@ define(function main(require, exports, module) {
4849

4950

5051
const KernalModeTrust = window.KernalModeTrust;
52+
const LIVE_PREVIEW_MODE = CONSTANTS.LIVE_PREVIEW_MODE,
53+
LIVE_HIGHLIGHT_MODE = CONSTANTS.LIVE_HIGHLIGHT_MODE,
54+
LIVE_EDIT_MODE = CONSTANTS.LIVE_EDIT_MODE;
5155

5256
// this will later be assigned its correct values once entitlementsManager loads
5357
let isProUser = false;
5458
let isFreeTrialUser = false;
5559

56-
const EVENT_LIVE_HIGHLIGHT_PREF_CHANGED = "liveHighlightPrefChange";
57-
const PREFERENCE_LIVE_PREVIEW_MODE = "livePreviewMode";
60+
const PREFERENCE_LIVE_PREVIEW_MODE = CONSTANTS.PREFERENCE_LIVE_PREVIEW_MODE;
5861

5962
// state manager key to track image gallery selected state, by default we keep this as selected
6063
// if this is true we show the image gallery when an image element is clicked
@@ -85,7 +88,6 @@ define(function main(require, exports, module) {
8588

8689
var params = new UrlParams();
8790
var config = {
88-
highlight: true, // enable highlighting?
8991
mode: _getDefaultMode(), // 'edit', 'highlight', or 'preview' - will be updated when preference loads
9092
elemHighlights: "hover", // default value, this will get updated when the extension loads
9193
showRulerLines: false, // default value, this will get updated when the extension loads
@@ -101,7 +103,7 @@ define(function main(require, exports, module) {
101103
var prefs = PreferencesManager.getExtensionPrefs("livedev");
102104

103105
// "livedev.remoteHighlight" preference
104-
var PREF_REMOTEHIGHLIGHT = "remoteHighlight";
106+
var PREF_REMOTEHIGHLIGHT = "remoteHighlight"; // todo remove this and put it inside remotefn itself
105107
var remoteHighlightPref = prefs.definePreference(PREF_REMOTEHIGHLIGHT, "object", {
106108
animateStartValue: {
107109
"background-color": "rgba(0, 162, 255, 0.5)",
@@ -237,27 +239,9 @@ define(function main(require, exports, module) {
237239
// Add checkmark when status is STATUS_ACTIVE; otherwise remove it
238240
CommandManager.get(Commands.FILE_LIVE_FILE_PREVIEW)
239241
.setChecked(status === MultiBrowserLiveDev.STATUS_ACTIVE);
240-
CommandManager.get(Commands.FILE_LIVE_HIGHLIGHT)
241-
.setEnabled(status === MultiBrowserLiveDev.STATUS_ACTIVE);
242242
});
243243
}
244244

245-
function _updateHighlightCheckmark() {
246-
CommandManager.get(Commands.FILE_LIVE_HIGHLIGHT).setChecked(config.highlight);
247-
exports.trigger(EVENT_LIVE_HIGHLIGHT_PREF_CHANGED, config.highlight);
248-
}
249-
250-
function togglePreviewHighlight() {
251-
config.highlight = !config.highlight;
252-
_updateHighlightCheckmark();
253-
if (config.highlight) {
254-
MultiBrowserLiveDev.showHighlight();
255-
} else {
256-
MultiBrowserLiveDev.hideHighlight();
257-
}
258-
PreferencesManager.setViewState("livedevHighlight", config.highlight);
259-
}
260-
261245
/** force reload the live preview currently only with shortcut ctrl-shift-R */
262246
function _handleReloadLivePreviewCommand() {
263247
if (MultiBrowserLiveDev.status >= MultiBrowserLiveDev.STATUS_ACTIVE) {
@@ -281,22 +265,22 @@ define(function main(require, exports, module) {
281265
// default mode means on first load for pro user we have edit mode
282266
// for free user we have highlight mode
283267
function _getDefaultMode() {
284-
return isProUser ? "edit" : "highlight";
268+
return isProUser ? LIVE_EDIT_MODE : LIVE_HIGHLIGHT_MODE;
285269
}
286270

287271
// to set that mode in the preferences
288272
function _initializeMode() {
289273
if (isFreeTrialUser) {
290-
PreferencesManager.set(PREFERENCE_LIVE_PREVIEW_MODE, "edit");
274+
PreferencesManager.set(PREFERENCE_LIVE_PREVIEW_MODE, LIVE_EDIT_MODE);
291275
return;
292276
}
293277

294278
const savedMode = PreferencesManager.get(PREFERENCE_LIVE_PREVIEW_MODE) || _getDefaultMode();
295279

296-
if (savedMode === "highlight" && isProUser) {
297-
PreferencesManager.set(PREFERENCE_LIVE_PREVIEW_MODE, "edit");
298-
} else if (savedMode === "edit" && !isProUser) {
299-
PreferencesManager.set(PREFERENCE_LIVE_PREVIEW_MODE, "highlight");
280+
if (savedMode === LIVE_HIGHLIGHT_MODE && isProUser) {
281+
PreferencesManager.set(PREFERENCE_LIVE_PREVIEW_MODE, LIVE_EDIT_MODE);
282+
} else if (savedMode === LIVE_EDIT_MODE && !isProUser) {
283+
PreferencesManager.set(PREFERENCE_LIVE_PREVIEW_MODE, LIVE_HIGHLIGHT_MODE);
300284
}
301285
}
302286

@@ -329,7 +313,7 @@ define(function main(require, exports, module) {
329313
}
330314

331315
function setMode(mode) {
332-
if (mode === "edit" && !exports.isProUser) {
316+
if (mode === LIVE_EDIT_MODE && !exports.isProUser) {
333317
return false;
334318
}
335319
PreferencesManager.set(PREFERENCE_LIVE_PREVIEW_MODE, mode);
@@ -340,6 +324,10 @@ define(function main(require, exports, module) {
340324
return PreferencesManager.get(PREFERENCE_LIVE_PREVIEW_MODE) || _getDefaultMode();
341325
}
342326

327+
function isInPreviewMode() {
328+
return getCurrentMode() === LIVE_PREVIEW_MODE;
329+
}
330+
343331
/** Initialize LiveDevelopment */
344332
AppInit.appReady(function () {
345333
params.parse();
@@ -353,7 +341,6 @@ define(function main(require, exports, module) {
353341
MultiBrowserLiveDev.init(config);
354342

355343
_loadStyles();
356-
_updateHighlightCheckmark();
357344

358345
// init pro user status and listen for changes
359346
if (KernalModeTrust) {
@@ -405,16 +392,6 @@ define(function main(require, exports, module) {
405392
WorkspaceManager.addEscapeKeyEventHandler("livePreview", _handleLivePreviewEscapeKey);
406393
});
407394

408-
// init prefs
409-
PreferencesManager.stateManager.definePreference("livedevHighlight", "boolean", true)
410-
.on("change", function () {
411-
config.highlight = PreferencesManager.getViewState("livedevHighlight");
412-
_updateHighlightCheckmark();
413-
if (MultiBrowserLiveDev && MultiBrowserLiveDev.status >= MultiBrowserLiveDev.STATUS_ACTIVE) {
414-
MultiBrowserLiveDev.updateConfig(JSON.stringify(config));
415-
}
416-
});
417-
418395
function _updateConfigMode() {
419396
const currentMode = getCurrentMode();
420397
config.mode = currentMode;
@@ -425,15 +402,14 @@ define(function main(require, exports, module) {
425402
}
426403

427404
PreferencesManager.definePreference(PREFERENCE_LIVE_PREVIEW_MODE, "string", _getDefaultMode(), {
428-
description: StringUtils.format(Strings.LIVE_PREVIEW_MODE_PREFERENCE, "'preview'", "'highlight'", "'edit'"),
429-
values: ["preview", "highlight", "edit"]
405+
description: StringUtils.format(
406+
Strings.LIVE_PREVIEW_MODE_PREFERENCE, LIVE_PREVIEW_MODE, LIVE_HIGHLIGHT_MODE, LIVE_EDIT_MODE),
407+
values: [LIVE_PREVIEW_MODE, LIVE_HIGHLIGHT_MODE, LIVE_EDIT_MODE]
430408
}).on("change", function () {
431409
// when mode changes we update the config mode and notify remoteFunctions so that it can get updated
432410
_updateConfigMode();
433411
});
434412

435-
config.highlight = PreferencesManager.getViewState("livedevHighlight");
436-
437413
// this function is responsible to update element highlight config
438414
// called from live preview extension when preference changes
439415
function updateElementHighlightConfig() {
@@ -453,11 +429,8 @@ define(function main(require, exports, module) {
453429
}
454430

455431
// init commands
456-
CommandManager.register(Strings.CMD_LIVE_HIGHLIGHT, Commands.FILE_LIVE_HIGHLIGHT, togglePreviewHighlight);
457432
CommandManager.register(Strings.CMD_RELOAD_LIVE_PREVIEW, Commands.CMD_RELOAD_LIVE_PREVIEW, _handleReloadLivePreviewCommand);
458433

459-
CommandManager.get(Commands.FILE_LIVE_HIGHLIGHT).setEnabled(false);
460-
461434
EventDispatcher.makeEventDispatcher(exports);
462435

463436
exports.isProUser = isProUser;
@@ -468,7 +441,6 @@ define(function main(require, exports, module) {
468441
exports.EVENT_CONNECTION_CLOSE = MultiBrowserLiveDev.EVENT_CONNECTION_CLOSE;
469442
exports.EVENT_LIVE_PREVIEW_CLICKED = MultiBrowserLiveDev.EVENT_LIVE_PREVIEW_CLICKED;
470443
exports.EVENT_LIVE_PREVIEW_RELOAD = MultiBrowserLiveDev.EVENT_LIVE_PREVIEW_RELOAD;
471-
exports.EVENT_LIVE_HIGHLIGHT_PREF_CHANGED = EVENT_LIVE_HIGHLIGHT_PREF_CHANGED;
472444

473445
// Export public functions
474446
exports.openLivePreview = openLivePreview;
@@ -477,7 +449,6 @@ define(function main(require, exports, module) {
477449
exports.isActive = isActive;
478450
exports.setLivePreviewPinned = setLivePreviewPinned;
479451
exports.setLivePreviewTransportBridge = setLivePreviewTransportBridge;
480-
exports.togglePreviewHighlight = togglePreviewHighlight;
481452
exports.setImageGalleryState = setImageGalleryState;
482453
exports.updateElementHighlightConfig = updateElementHighlightConfig;
483454
exports.updateRulerLinesConfig = updateRulerLinesConfig;
@@ -487,4 +458,5 @@ define(function main(require, exports, module) {
487458
exports.dismissLivePreviewBoxes = MultiBrowserLiveDev.dismissLivePreviewBoxes;
488459
exports.setMode = setMode;
489460
exports.getCurrentMode = getCurrentMode;
461+
exports.isInPreviewMode = isInPreviewMode;
490462
});

src/command/Commands.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,6 @@ define(function (require, exports, module) {
103103
/** Reloads live preview */
104104
exports.CMD_RELOAD_LIVE_PREVIEW = "file.reloadLivePreview"; // LiveDevelopment/main.js _handleReloadLivePreviewCommand()
105105

106-
/** Toggles live highlight */
107-
exports.FILE_LIVE_HIGHLIGHT = "file.previewHighlight"; // LiveDevelopment/main.js _handlePreviewHighlightCommand()
108-
109106
/** Opens project settings */
110107
exports.FILE_PROJECT_SETTINGS = "file.projectSettings"; // ProjectManager.js _projectSettings()
111108

src/extensionsIntegrated/Phoenix-live-preview/BrowserStaticServer.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@ define(function (require, exports, module) {
3434
Mustache = require("thirdparty/mustache/mustache"),
3535
FileSystem = require("filesystem/FileSystem"),
3636
EventDispatcher = require("utils/EventDispatcher"),
37-
CommandManager = require("command/CommandManager"),
38-
Commands = require("command/Commands"),
3937
StringUtils = require("utils/StringUtils"),
4038
EventManager = require("utils/EventManager"),
4139
LivePreviewSettings = require("./LivePreviewSettings"),
@@ -730,11 +728,8 @@ define(function (require, exports, module) {
730728
});
731729
});
732730

733-
function _isLiveHighlightEnabled() {
734-
return CommandManager.get(Commands.FILE_LIVE_HIGHLIGHT).getChecked();
735-
}
736731
exports.on(EVENT_EMBEDDED_IFRAME_ESCAPE_PRESS, function () {
737-
if(!_isLiveHighlightEnabled()){
732+
if(LiveDevelopment.isInPreviewMode()){
738733
return;
739734
}
740735
utils.focusActiveEditorIfFocusInLivePreview();

0 commit comments

Comments
 (0)