import type { Editor , Menu , WorkspaceLeaf } from "obsidian" ; import t from "src/l10n/helpers" ; import type DictionaryPlugin from "src/main" ; import { VIEW_TYPE } from "src/_constants" ; export default function handleContextMenu ( menu , instance , plugin ) { if ( ! plugin . settings . shouldShowCustomContextMenu ) { return ; } const selection = instance . getSelection ( ) ; if ( selection && selection . trim ( ) . split ( " " ) . length === 1 ) { if ( ! plugin . settings . shouldShowSynonymPopover ) { menu . addItem ( ( item ) => { item . setTitle ( t ( 'Show Synonyms' ) ) . setIcon ( 'synonyms' ) . onClick ( async ( _ ) => { plugin . handlePointerUp ( ) ; } ) ; } ) ; } menu . addItem ( ( item ) => { item . setTitle ( t ( 'Look up' ) ) . setIcon ( 'quote-glyph' ) . onClick ( async ( _ ) => { let leaf = plugin . app . workspace . getLeavesOfType ( VIEW_TYPE ) . first ( ) ; if ( ! leaf ) { leaf = plugin . app . workspace . getRightLeaf ( false ) ; await leaf . setViewState ( { type : VIEW_TYPE , } ) ; } leaf . view . query ( selection . trim ( ) ) ; plugin . app . workspace . revealLeaf ( leaf ) ; } ) ; } ) ; } }