Skip to content

Commit 53a3f0a

Browse files
committed
chore: paste should paste to end of current tag and refactor to pro plugin
1 parent 6c0e570 commit 53a3f0a

File tree

3 files changed

+40
-30
lines changed

3 files changed

+40
-30
lines changed

src/LiveDevelopment/BrowserScripts/RemoteFunctions.js

Lines changed: 0 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 paste button, this inserts the saved content from clipboard just above this element
365-
* @param {Event} event
366-
* @param {DOMElement} targetElement
367-
*/
368-
function _handlePasteOptionClick(event, targetElement) {
369-
if (LivePreviewView.isElementEditable(targetElement)) {
370-
const targetTagId = targetElement.getAttribute(GLOBALS.DATA_BRACKETS_ID_ATTR);
371-
372-
window._Brackets_MessageBroker.send({
373-
livePreviewEditEnabled: true,
374-
element: targetElement,
375-
event: event,
376-
tagId: Number(targetTagId),
377-
paste: 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 function will get triggered when from the multiple advance DOM buttons, one is clicked
386365
* this function just checks which exact button was clicked and call the required function
@@ -391,8 +370,6 @@ function RemoteFunctions(config = {}) {
391370
function handleOptionClick(e, action, element) {
392371
if (action === "edit-text") {
393372
startEditing(element);
394-
} else if (action === "paste") {
395-
_handlePasteOptionClick(e, element);
396373
} else if (action === "ai") {
397374
_handleAIOptionClick(e, element);
398375
} else if (action === "image-gallery") {
@@ -1008,10 +985,6 @@ function RemoteFunctions(config = {}) {
1008985

1009986
let content = `
1010987
<div class="more-options-dropdown">
1011-
<div class="dropdown-item" data-action="paste">
1012-
<span class="item-icon">${icons.paste}</span>
1013-
<span class="item-label">${strings.paste}</span>
1014-
</div>
1015988
${handlerItems}
1016989
</div>
1017990
`;

src/extensionsIntegrated/phoenix-pro/LivePreviewEdit.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -645,17 +645,18 @@ define(function (require, exports, module) {
645645
return;
646646
}
647647

648-
const { startPos } = range;
648+
const { startPos, endPos } = range;
649649

650650
Phoenix.app.clipboardReadText().then(text => {
651651
if (!text) {
652652
return;
653653
}
654654
// get the indentation in the target line and check if there is any real indentation
655655
let indent = editor.getTextBetween({ line: startPos.line, ch: 0 }, startPos);
656-
indent = indent.trim() === '' ? indent : '';
656+
indent = indent.trim() === '' ? `\n${indent}` : '';
657657

658-
editor.replaceRange(text + '\n' + indent, startPos);
658+
editor.replaceRange(indent + text, endPos);
659+
editor.setCursorPos(endPos.line + 1, indent.length);
659660
}).catch(err => {
660661
console.error("Failed to read from clipboard:", err);
661662
});

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

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,42 @@ LivePreviewView.registerNodeMoreOptionsHandler("copy", {
231231
handleDropdownClick: _handleCopyOptionClick
232232
});
233233

234+
function _renderPasteDropdown() {
235+
return {
236+
listOrder: proConstants.DROPDOWN_ORDERING.PASTE,
237+
htmlContent: `<div class="dropdown-item" data-action="paste">
238+
<span class="item-icon">${icons.paste}</span>
239+
<span class="item-label">${strings.paste}</span>
240+
</div>`
241+
};
242+
}
243+
244+
/**
245+
* this is for paste button, this inserts the saved content from clipboard just above this element
246+
* @param {Event} event
247+
* @param {DOMElement} targetElement
248+
*/
249+
function _handlePasteOptionClick(event, targetElement) {
250+
if (LivePreviewView.isElementEditable(targetElement)) {
251+
const targetTagId = targetElement.getAttribute(GLOBALS.DATA_BRACKETS_ID_ATTR);
252+
253+
window._Brackets_MessageBroker.send({
254+
livePreviewEditEnabled: true,
255+
element: targetElement,
256+
event: event,
257+
tagId: Number(targetTagId),
258+
paste: true
259+
});
260+
} else {
261+
console.error("The TagID might be unavailable or the element tag is directly body or html");
262+
}
263+
}
264+
265+
LivePreviewView.registerNodeMoreOptionsHandler("paste", {
266+
renderDropdownItems: _renderPasteDropdown,
267+
handleDropdownClick: _handlePasteOptionClick
268+
});
269+
234270

235271
LivePreviewView.registerNodeMoreOptionsHandler("cutPasteSeparator", {
236272
renderDropdownItems: ()=>{

0 commit comments

Comments
 (0)