fix: context-menu position fixed while scrolling (#3340)
This commit is contained in:
@@ -311,12 +311,12 @@ 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) {
|
||||||
@@ -338,8 +338,9 @@ const initView = (el: any) => {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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,16 +216,6 @@ export function useCodemirror(
|
|||||||
? new HoppEnvironmentPlugin(subscribeToStream, view)
|
? new HoppEnvironmentPlugin(subscribeToStream, view)
|
||||||
: null
|
: null
|
||||||
|
|
||||||
const initView = (el: any) => {
|
|
||||||
if (el) platform.ui?.onCodemirrorInstanceMount?.(el)
|
|
||||||
|
|
||||||
const extensions = [
|
|
||||||
basicSetup,
|
|
||||||
baseTheme,
|
|
||||||
syntaxHighlighting(baseHighlightStyle, { fallback: true }),
|
|
||||||
ViewPlugin.fromClass(
|
|
||||||
class {
|
|
||||||
update(update: ViewUpdate) {
|
|
||||||
function handleTextSelection() {
|
function handleTextSelection() {
|
||||||
const selection = view.value?.state.selection.main
|
const selection = view.value?.state.selection.main
|
||||||
if (selection) {
|
if (selection) {
|
||||||
@@ -253,6 +243,16 @@ export function useCodemirror(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const initView = (el: any) => {
|
||||||
|
if (el) platform.ui?.onCodemirrorInstanceMount?.(el)
|
||||||
|
|
||||||
|
const extensions = [
|
||||||
|
basicSetup,
|
||||||
|
baseTheme,
|
||||||
|
syntaxHighlighting(baseHighlightStyle, { fallback: true }),
|
||||||
|
ViewPlugin.fromClass(
|
||||||
|
class {
|
||||||
|
update(update: ViewUpdate) {
|
||||||
// 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