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 initView = (el: any) => {
|
||||
function handleTextSelection() {
|
||||
const selection = view.value?.state.selection.main
|
||||
if (selection) {
|
||||
const from = selection.from
|
||||
const to = selection.to
|
||||
if (from === to) return
|
||||
const text = view.value?.state.doc.sliceString(from, to)
|
||||
const { top, left } = view.value?.coordsAtPos(from)
|
||||
if (text) {
|
||||
@@ -340,6 +340,7 @@ const initView = (el: any) => {
|
||||
}
|
||||
}
|
||||
|
||||
const initView = (el: any) => {
|
||||
// Debounce to prevent double click from selecting the word
|
||||
const debounceFn = useDebounceFn(() => {
|
||||
handleTextSelection()
|
||||
@@ -381,6 +382,11 @@ const initView = (el: any) => {
|
||||
drop(ev) {
|
||||
ev.preventDefault()
|
||||
},
|
||||
scroll(event) {
|
||||
if (event.target) {
|
||||
handleTextSelection()
|
||||
}
|
||||
},
|
||||
}),
|
||||
ViewPlugin.fromClass(
|
||||
class {
|
||||
|
||||
@@ -216,16 +216,6 @@ export function useCodemirror(
|
||||
? new HoppEnvironmentPlugin(subscribeToStream, view)
|
||||
: 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() {
|
||||
const selection = view.value?.state.selection.main
|
||||
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
|
||||
const debounceFn = useDebounceFn(() => {
|
||||
handleTextSelection()
|
||||
@@ -296,6 +296,13 @@ export function useCodemirror(
|
||||
}
|
||||
}
|
||||
),
|
||||
EditorView.domEventHandlers({
|
||||
scroll(event) {
|
||||
if (event.target) {
|
||||
handleTextSelection()
|
||||
}
|
||||
},
|
||||
}),
|
||||
EditorView.updateListener.of((update) => {
|
||||
if (options.extendedEditorConfig.readOnly) {
|
||||
update.view.contentDOM.inputMode = "none"
|
||||
|
||||
Reference in New Issue
Block a user