fix: close context menu when no text is selected (#4337)

This commit is contained in:
Nivedin
2024-09-11 11:40:21 +05:30
committed by GitHub
parent bb87206b58
commit 53839e1091

View File

@@ -242,11 +242,27 @@ export function useCodemirror(
? new HoppEnvironmentPlugin(subscribeToStream, view)
: null
const closeContextMenu = () => {
invokeAction("contextmenu.open", {
position: {
top: 0,
left: 0,
},
text: null,
})
}
function handleTextSelection() {
const selection = view.value?.state.selection.main
if (selection) {
const { from, to } = selection
if (from === to) return
// If the selection is empty, hide the context menu
if (from === to) {
closeContextMenu()
return
}
const text = view.value?.state.doc.sliceString(from, to)
const coords = view.value?.coordsAtPos(from)
const top = coords?.top ?? 0
@@ -260,13 +276,7 @@ export function useCodemirror(
text,
})
} else {
invokeAction("contextmenu.open", {
position: {
top,
left,
},
text: null,
})
closeContextMenu()
}
}
}