fix: context-menu position fixed while scrolling (#3340)
This commit is contained in:
@@ -311,35 +311,36 @@ const envVars = computed(() =>
|
|||||||
|
|
||||||
const envTooltipPlugin = new HoppReactiveEnvPlugin(envVars, view)
|
const envTooltipPlugin = new HoppReactiveEnvPlugin(envVars, view)
|
||||||
|
|
||||||
const initView = (el: any) => {
|
function handleTextSelection() {
|
||||||
function handleTextSelection() {
|
const selection = view.value?.state.selection.main
|
||||||
const selection = view.value?.state.selection.main
|
if (selection) {
|
||||||
if (selection) {
|
const from = selection.from
|
||||||
const from = selection.from
|
const to = selection.to
|
||||||
const to = selection.to
|
if (from === to) return
|
||||||
const text = view.value?.state.doc.sliceString(from, to)
|
const text = view.value?.state.doc.sliceString(from, to)
|
||||||
const { top, left } = view.value?.coordsAtPos(from)
|
const { top, left } = view.value?.coordsAtPos(from)
|
||||||
if (text) {
|
if (text) {
|
||||||
invokeAction("contextmenu.open", {
|
invokeAction("contextmenu.open", {
|
||||||
position: {
|
position: {
|
||||||
top,
|
top,
|
||||||
left,
|
left,
|
||||||
},
|
},
|
||||||
text,
|
text,
|
||||||
})
|
})
|
||||||
showSuggestionPopover.value = false
|
showSuggestionPopover.value = false
|
||||||
} else {
|
} else {
|
||||||
invokeAction("contextmenu.open", {
|
invokeAction("contextmenu.open", {
|
||||||
position: {
|
position: {
|
||||||
top,
|
top,
|
||||||
left,
|
left,
|
||||||
},
|
},
|
||||||
text: null,
|
text: null,
|
||||||
})
|
})
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const initView = (el: any) => {
|
||||||
// Debounce to prevent double click from selecting the word
|
// Debounce to prevent double click from selecting the word
|
||||||
const debounceFn = useDebounceFn(() => {
|
const debounceFn = useDebounceFn(() => {
|
||||||
handleTextSelection()
|
handleTextSelection()
|
||||||
@@ -381,6 +382,11 @@ const initView = (el: any) => {
|
|||||||
drop(ev) {
|
drop(ev) {
|
||||||
ev.preventDefault()
|
ev.preventDefault()
|
||||||
},
|
},
|
||||||
|
scroll(event) {
|
||||||
|
if (event.target) {
|
||||||
|
handleTextSelection()
|
||||||
|
}
|
||||||
|
},
|
||||||
}),
|
}),
|
||||||
ViewPlugin.fromClass(
|
ViewPlugin.fromClass(
|
||||||
class {
|
class {
|
||||||
|
|||||||
@@ -216,6 +216,33 @@ export function useCodemirror(
|
|||||||
? new HoppEnvironmentPlugin(subscribeToStream, view)
|
? new HoppEnvironmentPlugin(subscribeToStream, view)
|
||||||
: null
|
: null
|
||||||
|
|
||||||
|
function handleTextSelection() {
|
||||||
|
const selection = view.value?.state.selection.main
|
||||||
|
if (selection) {
|
||||||
|
const from = selection.from
|
||||||
|
const to = selection.to
|
||||||
|
const text = view.value?.state.doc.sliceString(from, to)
|
||||||
|
const { top, left } = view.value?.coordsAtPos(from)
|
||||||
|
if (text) {
|
||||||
|
invokeAction("contextmenu.open", {
|
||||||
|
position: {
|
||||||
|
top,
|
||||||
|
left,
|
||||||
|
},
|
||||||
|
text,
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
invokeAction("contextmenu.open", {
|
||||||
|
position: {
|
||||||
|
top,
|
||||||
|
left,
|
||||||
|
},
|
||||||
|
text: null,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const initView = (el: any) => {
|
const initView = (el: any) => {
|
||||||
if (el) platform.ui?.onCodemirrorInstanceMount?.(el)
|
if (el) platform.ui?.onCodemirrorInstanceMount?.(el)
|
||||||
|
|
||||||
@@ -226,33 +253,6 @@ export function useCodemirror(
|
|||||||
ViewPlugin.fromClass(
|
ViewPlugin.fromClass(
|
||||||
class {
|
class {
|
||||||
update(update: ViewUpdate) {
|
update(update: ViewUpdate) {
|
||||||
function handleTextSelection() {
|
|
||||||
const selection = view.value?.state.selection.main
|
|
||||||
if (selection) {
|
|
||||||
const from = selection.from
|
|
||||||
const to = selection.to
|
|
||||||
const text = view.value?.state.doc.sliceString(from, to)
|
|
||||||
const { top, left } = view.value?.coordsAtPos(from)
|
|
||||||
if (text) {
|
|
||||||
invokeAction("contextmenu.open", {
|
|
||||||
position: {
|
|
||||||
top,
|
|
||||||
left,
|
|
||||||
},
|
|
||||||
text,
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
invokeAction("contextmenu.open", {
|
|
||||||
position: {
|
|
||||||
top,
|
|
||||||
left,
|
|
||||||
},
|
|
||||||
text: null,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Debounce to prevent double click from selecting the word
|
// Debounce to prevent double click from selecting the word
|
||||||
const debounceFn = useDebounceFn(() => {
|
const debounceFn = useDebounceFn(() => {
|
||||||
handleTextSelection()
|
handleTextSelection()
|
||||||
@@ -296,6 +296,13 @@ export function useCodemirror(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
|
EditorView.domEventHandlers({
|
||||||
|
scroll(event) {
|
||||||
|
if (event.target) {
|
||||||
|
handleTextSelection()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}),
|
||||||
EditorView.updateListener.of((update) => {
|
EditorView.updateListener.of((update) => {
|
||||||
if (options.extendedEditorConfig.readOnly) {
|
if (options.extendedEditorConfig.readOnly) {
|
||||||
update.view.contentDOM.inputMode = "none"
|
update.view.contentDOM.inputMode = "none"
|
||||||
|
|||||||
Reference in New Issue
Block a user