Skip to content

Commit 42f9552

Browse files
committed
feat: also add show ruler lines option in the more options dropdown
1 parent 37c1261 commit 42f9552

File tree

3 files changed

+81
-6
lines changed

3 files changed

+81
-6
lines changed

src/LiveDevelopment/BrowserScripts/RemoteFunctions.js

Lines changed: 73 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1448,6 +1448,12 @@ function RemoteFunctions(config = {}) {
14481448
</svg>
14491449
`,
14501450

1451+
ruler: `
1452+
<svg viewBox="0 0 24 24" fill="currentColor">
1453+
<path d="M8 3h1.5v18H8V3zm6.5 0H16v18h-1.5V3zM3 8v1.5h18V8H3zm0 6.5V16h18v-1.5H3z"/>
1454+
</svg>
1455+
`,
1456+
14511457
imageGallery: `
14521458
<svg viewBox="0 0 24 24" fill="currentColor">
14531459
<path d="M21 19V5c0-1.1-.9-2-2-2H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2zM8.5 13.5l2.5 3.01L14.5 12l4.5 6H5l3.5-4.5z"/>
@@ -1743,6 +1749,39 @@ function RemoteFunctions(config = {}) {
17431749
}
17441750
};
17451751

1752+
/**
1753+
* this is called when user clicks on the Show Ruler lines option in the more options dropdown
1754+
* @param {Event} event - click event
1755+
* @param {MoreOptionsDropdown} dropdown - the dropdown instance
1756+
*/
1757+
function _handleToggleRulerLines(event, dropdown) {
1758+
config.showRulerLines = !config.showRulerLines;
1759+
1760+
window._Brackets_MessageBroker.send({
1761+
livePreviewEditEnabled: true,
1762+
type: "toggleRulerLines",
1763+
enabled: config.showRulerLines
1764+
});
1765+
1766+
// add checkmark in the dropdown
1767+
const checkmark = dropdown._shadow.querySelector('[data-action="toggle-ruler-lines"] .item-checkmark');
1768+
if (checkmark) {
1769+
checkmark.textContent = config.showRulerLines ? '✓' : '';
1770+
}
1771+
1772+
// to apply the ruler lines or remove it when option is toggled
1773+
if (config.showRulerLines && previouslyClickedElement) {
1774+
if (!_currentRulerLines) {
1775+
_currentRulerLines = new RulerLines(previouslyClickedElement);
1776+
}
1777+
} else {
1778+
if (_currentRulerLines) {
1779+
_currentRulerLines.remove();
1780+
_currentRulerLines = null;
1781+
}
1782+
}
1783+
}
1784+
17461785
/**
17471786
* the more options dropdown which appears when user clicks on the ellipsis button in the options box
17481787
*/
@@ -1849,6 +1888,11 @@ function RemoteFunctions(config = {}) {
18491888
<span class="item-icon">${ICONS.paste}</span>
18501889
<span class="item-label">${config.strings.paste}</span>
18511890
</div>
1891+
<div class="dropdown-item" data-action="toggle-ruler-lines">
1892+
<span class="item-icon">${ICONS.ruler}</span>
1893+
<span class="item-label">${config.strings.showRulerLines}</span>
1894+
<span class="item-checkmark">${config.showRulerLines ? '✓' : ''}</span>
1895+
</div>
18521896
</div>
18531897
`;
18541898

@@ -1912,6 +1956,12 @@ function RemoteFunctions(config = {}) {
19121956
.item-label {
19131957
flex: 1 !important;
19141958
}
1959+
1960+
.item-checkmark {
1961+
margin-left: auto !important;
1962+
padding-left: 12px !important;
1963+
font-size: 14px !important;
1964+
}
19151965
`;
19161966

19171967
shadow.innerHTML = `<style>${styles}</style><div class="phoenix-dropdown">${content}</div>`;
@@ -1940,11 +1990,17 @@ function RemoteFunctions(config = {}) {
19401990
event.stopPropagation();
19411991
event.preventDefault();
19421992
const action = event.currentTarget.getAttribute('data-action');
1943-
handleOptionClick(event, action, this.targetElement);
1944-
// when an option is selected we close both the dropdown as well as the options box
1945-
this.remove();
1946-
if (_nodeMoreOptionsBox) {
1947-
_nodeMoreOptionsBox.remove();
1993+
1994+
if (action === 'toggle-ruler-lines') {
1995+
// when ruler lines option is clicked we need to keep the dropdown open
1996+
_handleToggleRulerLines(event, this);
1997+
} else {
1998+
// for other options, we close both the dropdown as well as the options box
1999+
handleOptionClick(event, action, this.targetElement);
2000+
this.remove();
2001+
if (_nodeMoreOptionsBox) {
2002+
_nodeMoreOptionsBox.remove();
2003+
}
19482004
}
19492005
});
19502006
});
@@ -1956,6 +2012,14 @@ function RemoteFunctions(config = {}) {
19562012
this.body = null;
19572013
_moreOptionsDropdown = null;
19582014
}
2015+
},
2016+
2017+
refresh: function() {
2018+
// update the checkmark state when config changes
2019+
const checkmark = this._shadow.querySelector('[data-action="toggle-ruler-lines"] .item-checkmark');
2020+
if (checkmark) {
2021+
checkmark.textContent = config.showRulerLines ? '✓' : '';
2022+
}
19592023
}
19602024
};
19612025

@@ -5068,8 +5132,11 @@ function RemoteFunctions(config = {}) {
50685132
imageGallerySelected = config.imageGalleryState;
50695133
}
50705134

5071-
// handle ruler lines visibility toggle
5135+
// handle ruler lines visibility toggle and refresh the more options dropdown if its open
50725136
_handleRulerLinesConfigChange(oldConfig);
5137+
if (_moreOptionsDropdown) {
5138+
_moreOptionsDropdown.refresh();
5139+
}
50735140

50745141
// Determine if configuration has changed significantly
50755142
const oldHighlightMode = oldConfig.elemHighlights ? oldConfig.elemHighlights.toLowerCase() : "hover";

src/LiveDevelopment/LivePreviewEdit.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ define(function (require, exports, module) {
3030
const LiveDevelopment = require("LiveDevelopment/main");
3131
const CodeMirror = require("thirdparty/CodeMirror/lib/codemirror");
3232
const ProjectManager = require("project/ProjectManager");
33+
const PreferencesManager = require("preferences/PreferencesManager");
3334
const CommandManager = require("command/CommandManager");
3435
const Commands = require("command/Commands");
3536
const FileSystem = require("filesystem/FileSystem");
@@ -1458,6 +1459,12 @@ define(function (require, exports, module) {
14581459
return;
14591460
}
14601461

1462+
// handle ruler lines toggle message
1463+
if (message.type === "toggleRulerLines") {
1464+
PreferencesManager.set("livePreviewShowRulerLines", message.enabled);
1465+
return;
1466+
}
1467+
14611468
// handle move(drag & drop)
14621469
if (message.move && message.sourceId && message.targetId) {
14631470
_moveElementInSource(message.sourceId, message.targetId, message.insertAfter, message.insertInside);

src/LiveDevelopment/main.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ define(function main(require, exports, module) {
114114
cut: Strings.LIVE_DEV_MORE_OPTIONS_CUT,
115115
copy: Strings.LIVE_DEV_MORE_OPTIONS_COPY,
116116
paste: Strings.LIVE_DEV_MORE_OPTIONS_PASTE,
117+
showRulerLines: Strings.LIVE_PREVIEW_SHOW_RULER_LINES,
117118
aiPromptPlaceholder: Strings.LIVE_DEV_AI_PROMPT_PLACEHOLDER,
118119
imageGalleryUseImage: Strings.LIVE_DEV_IMAGE_GALLERY_USE_IMAGE,
119120
imageGallerySelectDownloadFolder: Strings.LIVE_DEV_IMAGE_GALLERY_SELECT_DOWNLOAD_FOLDER,

0 commit comments

Comments
 (0)