Skip to content

Commit

Permalink
chore: remove useless code
Browse files Browse the repository at this point in the history
  • Loading branch information
17px committed Nov 17, 2023
1 parent 92dcca6 commit 6b1e8ab
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,37 +14,3 @@ export const items = [
value: "写点想法",
},
];

export const calculateHorizontalOffset = (
parentElement: EffectiveElements,
childNode: Node,
offset: number
) => {
let totalOffset = 0;

// 遍历父元素的所有子节点
for (let node of parentElement.childNodes) {
if (node === childNode) {
// 当到达目标节点时
if (node.nodeType === Node.TEXT_NODE) {
// 如果是文本节点,创建范围并计算偏移
let range = document.createRange();
range.setStart(node, 0);
range.setEnd(node, offset);
totalOffset += range.getBoundingClientRect().width;
}
break;
} else {
// 如果是其他节点,累加其偏移
if (node.nodeType === Node.TEXT_NODE) {
let range = document.createRange();
range.selectNode(node);
totalOffset += range.getBoundingClientRect().width;
} else if (node.nodeType === Node.ELEMENT_NODE) {
totalOffset += node.offsetWidth;
}
}
}

return totalOffset;
};
7 changes: 1 addition & 6 deletions apps/dockyard/src/modules/post/selection.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
import "./selection.less";
import {
EffectiveElements,
calculateHorizontalOffset,
items,
effectiveHtmlTags,
} from "./selection.util";
import { items } from "./selection.config";

const container = document.querySelector(".article-container article")!;

Expand Down

0 comments on commit 6b1e8ab

Please sign in to comment.