Skip to content

Commit 6c0e570

Browse files
committed
refactor: copy element into lp plugin
1 parent c8d7382 commit 6c0e570

File tree

2 files changed

+43
-28
lines changed

2 files changed

+43
-28
lines changed

src/LiveDevelopment/BrowserScripts/RemoteFunctions.js

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -360,27 +360,6 @@ function RemoteFunctions(config = {}) {
360360
});
361361
}
362362

363-
/**
364-
* this is for copy button, similar to cut just we don't remove the elements source code
365-
* @param {Event} event
366-
* @param {DOMElement} element
367-
*/
368-
function _handleCopyOptionClick(event, element) {
369-
if (LivePreviewView.isElementEditable(element)) {
370-
const tagId = element.getAttribute(GLOBALS.DATA_BRACKETS_ID_ATTR);
371-
372-
window._Brackets_MessageBroker.send({
373-
livePreviewEditEnabled: true,
374-
element: element,
375-
event: event,
376-
tagId: Number(tagId),
377-
copy: true
378-
});
379-
} else {
380-
console.error("The TagID might be unavailable or the element tag is directly body or html");
381-
}
382-
}
383-
384363
/**
385364
* this is for paste button, this inserts the saved content from clipboard just above this element
386365
* @param {Event} event
@@ -412,8 +391,6 @@ function RemoteFunctions(config = {}) {
412391
function handleOptionClick(e, action, element) {
413392
if (action === "edit-text") {
414393
startEditing(element);
415-
} else if (action === "copy") {
416-
_handleCopyOptionClick(e, element);
417394
} else if (action === "paste") {
418395
_handlePasteOptionClick(e, element);
419396
} else if (action === "ai") {
@@ -1031,10 +1008,6 @@ function RemoteFunctions(config = {}) {
10311008

10321009
let content = `
10331010
<div class="more-options-dropdown">
1034-
<div class="dropdown-item" data-action="copy">
1035-
<span class="item-icon">${icons.copy}</span>
1036-
<span class="item-label">${strings.copy}</span>
1037-
</div>
10381011
<div class="dropdown-item" data-action="paste">
10391012
<span class="item-icon">${icons.paste}</span>
10401013
<span class="item-label">${strings.paste}</span>
@@ -1076,6 +1049,9 @@ function RemoteFunctions(config = {}) {
10761049
const handler = LivePreviewView.getNodeMoreOptionsHandler(action);
10771050
if (handler && handler.handleDropdownClick) {
10781051
handlerHandledIt = handler.handleDropdownClick(event, this.targetElement, this);
1052+
if(handlerHandledIt) {
1053+
this.remove();
1054+
}
10791055
}
10801056

10811057
if (!handlerHandledIt) {

src/extensionsIntegrated/phoenix-pro/browser-context/generic-tools.js

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ LivePreviewView.registerNodeMoreOptionsHandler("selectParent", {
155155

156156
function _renderCutDropdown() {
157157
return {
158-
listOrder: proConstants.DROPDOWN_ORDERING.CUT_PASTE_SEPARATOR,
158+
listOrder: proConstants.DROPDOWN_ORDERING.CUT,
159159
htmlContent: `<div class="dropdown-item" data-action="cut">
160160
<span class="item-icon">${icons.cut}</span>
161161
<span class="item-label">${strings.cut}</span>
@@ -193,6 +193,45 @@ LivePreviewView.registerNodeMoreOptionsHandler("cut", {
193193
});
194194

195195

196+
function _renderCopyDropdown() {
197+
return {
198+
listOrder: proConstants.DROPDOWN_ORDERING.COPY,
199+
htmlContent: `<div class="dropdown-item" data-action="copy">
200+
<span class="item-icon">${icons.copy}</span>
201+
<span class="item-label">${strings.copy}</span>
202+
</div>`
203+
};
204+
}
205+
206+
/**
207+
* this is for copy button, similar to cut just we don't remove the elements source code
208+
* @param {Event} event
209+
* @param {DOMElement} element
210+
* @param {DOMElement} _dropdown
211+
*/
212+
function _handleCopyOptionClick(event, element, _dropdown) {
213+
if (LivePreviewView.isElementEditable(element)) {
214+
const tagId = element.getAttribute(GLOBALS.DATA_BRACKETS_ID_ATTR);
215+
216+
window._Brackets_MessageBroker.send({
217+
livePreviewEditEnabled: true,
218+
element: element,
219+
event: event,
220+
tagId: Number(tagId),
221+
copy: true
222+
});
223+
} else {
224+
console.error("The TagID might be unavailable or the element tag is directly body or html");
225+
}
226+
return true;
227+
}
228+
229+
LivePreviewView.registerNodeMoreOptionsHandler("copy", {
230+
renderDropdownItems: _renderCopyDropdown,
231+
handleDropdownClick: _handleCopyOptionClick
232+
});
233+
234+
196235
LivePreviewView.registerNodeMoreOptionsHandler("cutPasteSeparator", {
197236
renderDropdownItems: ()=>{
198237
return {

0 commit comments

Comments
 (0)