fix: paste syncing issues with EnvInput
This commit is contained in:
@@ -63,7 +63,11 @@ watch(
|
|||||||
(newVal) => {
|
(newVal) => {
|
||||||
const singleLinedText = newVal.replaceAll("\n", "")
|
const singleLinedText = newVal.replaceAll("\n", "")
|
||||||
|
|
||||||
if (cachedValue.value !== singleLinedText) {
|
const currDoc = view.value?.state.doc
|
||||||
|
.toJSON()
|
||||||
|
.join(view.value.state.lineBreak)
|
||||||
|
|
||||||
|
if (cachedValue.value !== singleLinedText || newVal !== currDoc) {
|
||||||
cachedValue.value = singleLinedText
|
cachedValue.value = singleLinedText
|
||||||
|
|
||||||
view.value?.dispatch({
|
view.value?.dispatch({
|
||||||
@@ -83,6 +87,8 @@ watch(
|
|||||||
|
|
||||||
const { subscribeToStream } = useStreamSubscriber()
|
const { subscribeToStream } = useStreamSubscriber()
|
||||||
|
|
||||||
|
let clipboardEv: ClipboardEvent | null = null
|
||||||
|
|
||||||
const envTooltipPlugin = new HoppEnvironmentPlugin(subscribeToStream, view)
|
const envTooltipPlugin = new HoppEnvironmentPlugin(subscribeToStream, view)
|
||||||
|
|
||||||
const initView = (el: any) => {
|
const initView = (el: any) => {
|
||||||
@@ -90,13 +96,14 @@ const initView = (el: any) => {
|
|||||||
inputTheme,
|
inputTheme,
|
||||||
envTooltipPlugin,
|
envTooltipPlugin,
|
||||||
placeholderExt(props.placeholder),
|
placeholderExt(props.placeholder),
|
||||||
|
EditorView.domEventHandlers({
|
||||||
|
paste(ev) {
|
||||||
|
clipboardEv = ev
|
||||||
|
},
|
||||||
|
}),
|
||||||
ViewPlugin.fromClass(
|
ViewPlugin.fromClass(
|
||||||
class {
|
class {
|
||||||
update(update: ViewUpdate) {
|
update(update: ViewUpdate) {
|
||||||
const pasted = !!update.transactions.find((txn) =>
|
|
||||||
txn.isUserEvent("input.paste")
|
|
||||||
)
|
|
||||||
|
|
||||||
if (update.docChanged) {
|
if (update.docChanged) {
|
||||||
const prevValue = clone(cachedValue.value)
|
const prevValue = clone(cachedValue.value)
|
||||||
|
|
||||||
@@ -110,13 +117,21 @@ const initView = (el: any) => {
|
|||||||
|
|
||||||
emit("input", value)
|
emit("input", value)
|
||||||
emit("change", value)
|
emit("change", value)
|
||||||
if (pasted) {
|
|
||||||
nextTick().then(() => {
|
const pasted = !!update.transactions.find((txn) =>
|
||||||
|
txn.isUserEvent("input.paste")
|
||||||
|
)
|
||||||
|
|
||||||
|
if (pasted && clipboardEv) {
|
||||||
|
const evHandle = clipboardEv
|
||||||
|
nextTick(() => {
|
||||||
emit("paste", {
|
emit("paste", {
|
||||||
pastedValue: value,
|
pastedValue: evHandle.clipboardData?.getData("text") ?? "",
|
||||||
prevValue,
|
prevValue,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
} else {
|
||||||
|
clipboardEv = null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user