fix: context-menu position fixed while scrolling (#3340)

This commit is contained in:
Nivedin
2023-09-12 12:43:10 +05:30
committed by GitHub
parent dd143c95a9
commit 7201147b55
2 changed files with 66 additions and 53 deletions

View File

@@ -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 {

View File

@@ -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"