fix: disable multiline on EnvInput

This commit is contained in:
Andrew Bastin
2022-02-11 19:32:46 +05:30
parent 1264511113
commit 4254d108bf

View File

@@ -1,8 +1,3 @@
<!--
This code is a complete adaptation of the work done here
https://github.com/SyedWasiHaider/vue-highlightable-input
-->
<template> <template>
<div <div
class="flex flex-1 items-center flex-shrink-0 whitespace-nowrap overflow-auto hide-scrollbar" class="flex flex-1 items-center flex-shrink-0 whitespace-nowrap overflow-auto hide-scrollbar"
@@ -66,15 +61,17 @@ const editor = ref<any | null>(null)
watch( watch(
() => props.value, () => props.value,
(newVal) => { (newVal) => {
if (cachedValue.value !== newVal) { const singleLinedText = newVal.replaceAll("\n", "")
cachedValue.value = newVal
if (cachedValue.value !== singleLinedText) {
cachedValue.value = singleLinedText
view.value?.dispatch({ view.value?.dispatch({
filter: false, filter: false,
changes: { changes: {
from: 0, from: 0,
to: view.value.state.doc.length, to: view.value.state.doc.length,
insert: newVal, insert: singleLinedText,
}, },
}) })
} }
@@ -107,7 +104,10 @@ const initView = (el: any) => {
.toJSON() .toJSON()
.join(update.state.lineBreak) .join(update.state.lineBreak)
const value = clone(cachedValue.value) // We do not update the cache directly in this case (to trigger value watcher to dispatch)
// So, we desync cachedValue a bit so we can trigger updates
const value = clone(cachedValue.value).replaceAll("\n", "")
emit("input", value) emit("input", value)
emit("change", value) emit("change", value)
if (pasted) { if (pasted) {