Skip to content

Commit 3dadba0

Browse files
committed
clean up
1 parent cf2771f commit 3dadba0

2 files changed

Lines changed: 11 additions & 31 deletions

File tree

apps/obsidian/src/utils/wikilinkDragHandler.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,10 @@ import {
77
type DecorationSet,
88
EditorView,
99
} from "@codemirror/view";
10-
// @ts-expect-error - no types for @codemirror/state
11-
import type { Range } from "@codemirror/state";
1210
import { TFile } from "obsidian";
1311
import type DiscourseGraphPlugin from "~/index";
1412

1513
const DRAG_ATTR = "data-dg-draggable";
16-
const DRAG_HANDLE_CLASS = "dg-wikilink-drag-handle";
1714

1815
const buildObsidianUrl = (vaultName: string, filePath: string): string => {
1916
return `obsidian://open?vault=${encodeURIComponent(vaultName)}&file=${encodeURIComponent(filePath)}`;
@@ -127,11 +124,19 @@ class WikilinkDragHandleWidget extends WidgetType {
127124

128125
toDOM(): HTMLElement {
129126
const handle = document.createElement("span");
130-
handle.className = DRAG_HANDLE_CLASS;
127+
handle.className =
128+
"inline-block cursor-grab opacity-30 text-[10px] text-[var(--text-muted)] align-middle ml-0.5 transition-opacity duration-150 ease-in-out select-none";
131129
handle.draggable = true;
132130
handle.setAttribute("aria-label", "Drag to canvas");
133131
handle.textContent = "⠿";
134132

133+
handle.addEventListener("mouseenter", () => {
134+
handle.style.opacity = "1";
135+
});
136+
handle.addEventListener("mouseleave", () => {
137+
handle.style.opacity = "";
138+
});
139+
135140
handle.addEventListener("dragstart", (e) => {
136141
const file = resolveFileFromLinkText(this.linkPath, this.plugin);
137142
if (!file) {
@@ -153,7 +158,7 @@ const buildWidgetDecorations = (
153158
view: EditorView,
154159
plugin: DiscourseGraphPlugin,
155160
): DecorationSet => {
156-
const widgets: Range<Decoration>[] = [];
161+
const widgets = [];
157162

158163
for (const { from, to } of view.visibleRanges) {
159164
const text = view.state.doc.sliceString(from, to);
@@ -190,11 +195,7 @@ export const createWikilinkDragExtension = (
190195
}
191196

192197
update(update: ViewUpdate): void {
193-
if (
194-
update.docChanged ||
195-
update.viewportChanged ||
196-
update.selectionSet
197-
) {
198+
if (update.docChanged || update.viewportChanged) {
198199
this.decorations = buildWidgetDecorations(update.view, plugin);
199200
}
200201
}

apps/obsidian/styles.css

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -35,27 +35,6 @@
3535
background: var(--interactive-accent-hover);
3636
}
3737

38-
/* Drag handle next to wikilinks in Live Preview */
39-
.dg-wikilink-drag-handle {
40-
display: inline-block;
41-
cursor: grab;
42-
opacity: 0;
43-
font-size: 10px;
44-
vertical-align: middle;
45-
margin-left: 2px;
46-
color: var(--text-muted);
47-
transition: opacity 0.15s ease;
48-
user-select: none;
49-
}
50-
51-
.cm-line:hover .dg-wikilink-drag-handle {
52-
opacity: 0.6;
53-
}
54-
55-
.dg-wikilink-drag-handle:hover {
56-
opacity: 1 !important;
57-
}
58-
5938
/* Neutralize host button styling inside our editor */
6039
.tldraw__editor button {
6140
background: transparent !important;

0 commit comments

Comments
 (0)