@@ -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" ;
1210import { TFile } from "obsidian" ;
1311import type DiscourseGraphPlugin from "~/index" ;
1412
1513const DRAG_ATTR = "data-dg-draggable" ;
16- const DRAG_HANDLE_CLASS = "dg-wikilink-drag-handle" ;
1714
1815const 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 }
0 commit comments