Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve the ghosting of list items #13821

Merged
merged 4 commits into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions app/src/assets/scss/base.scss
Original file line number Diff line number Diff line change
Expand Up @@ -386,5 +386,12 @@ html {
}
}

.dragghost [data-node-id] {
&.protyle-wysiwyg--select::after,
&.protyle-wysiwyg--hl::after {
display: none;
}
}

// 需放置最后,否则 https://github.com/siyuan-note/siyuan/issues/7056
@import "util/responsive";
11 changes: 8 additions & 3 deletions app/src/protyle/gutter/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,10 @@ export class Gutter {
}

const ghostElement = document.createElement("div");
ghostElement.className = protyle.wysiwyg.element.className;
ghostElement.className = protyle.wysiwyg.element.className + " dragghost";
selectElements.forEach(item => {
const type = item.getAttribute("data-type");
if (item.querySelector("iframe")) {
const type = item.getAttribute("data-type");
const embedElement = genEmptyElement();
embedElement.classList.add("protyle-wysiwyg--select");
getContenteditableElement(embedElement).innerHTML = `<svg class="svg"><use xlink:href="${buttonElement.querySelector("use").getAttribute("xlink:href")}"></use></svg> ${getLangByType(type)}`;
Expand All @@ -141,7 +141,12 @@ export class Gutter {
});
ghostElement.setAttribute("style", `position:fixed;opacity:.1;width:${selectElements[0].clientWidth}px;padding:0;`);
document.body.append(ghostElement);
event.dataTransfer.setDragImage(ghostElement, 0, 0);
if (selectElements[0].classList.contains("li")) {
const actionElement = selectElements[0].querySelector(".protyle-action");
event.dataTransfer.setDragImage(ghostElement, actionElement.clientWidth / 2, actionElement.clientHeight / 2);
} else {
event.dataTransfer.setDragImage(ghostElement, 0, 0);
}
setTimeout(() => {
ghostElement.remove();
});
Expand Down
11 changes: 11 additions & 0 deletions app/src/protyle/util/editorCommonEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {zoomOut} from "../../menus/protyle";
import {webUtils} from "electron";
/// #endif
import {addDragFill} from "../render/av/cell";
import {processClonePHElement} from "../render/util";

const moveToNew = (protyle: IProtyle, sourceElements: Element[], targetElement: Element, newSourceElement: Element,
isSameDoc: boolean, isBottom: boolean, isCopy: boolean) => {
Expand Down Expand Up @@ -816,6 +817,16 @@ export const dropEvent = (protyle: IProtyle, editorElement: HTMLElement) => {
window.siyuan.dragElement = undefined;
event.preventDefault();
} else if (target.classList.contains("protyle-action")) {
const ghostElement = document.createElement("div");
ghostElement.className = protyle.wysiwyg.element.className + " dragghost";
ghostElement.append(processClonePHElement(target.parentElement.cloneNode(true) as Element));
ghostElement.setAttribute("style", `position:fixed;opacity:.1;width:${target.parentElement.clientWidth}px;padding:0;`);
document.body.append(ghostElement);
event.dataTransfer.setDragImage(ghostElement, target.clientWidth / 2, target.clientHeight / 2);
setTimeout(() => {
ghostElement.remove();
});

window.siyuan.dragElement = protyle.wysiwyg.element;
event.dataTransfer.setData(`${Constants.SIYUAN_DROP_GUTTER}NodeListItem${Constants.ZWSP}${target.parentElement.getAttribute("data-subtype")}${Constants.ZWSP}${[target.parentElement.getAttribute("data-node-id")]}`,
protyle.wysiwyg.element.innerHTML);
Expand Down
Loading