mirror of
https://github.com/directus/directus.git
synced 2026-04-25 03:00:53 -04:00
Prevent duplicate emit from codemirror editors (#18194)
Co-authored-by: Rijk van Zanten <rijkvanzanten@me.com>
This commit is contained in:
@@ -40,6 +40,7 @@ const { width } = useWindowSize();
|
||||
|
||||
const codemirrorEl = ref<HTMLTextAreaElement | null>();
|
||||
let codemirror: CodeMirror.Editor | null;
|
||||
let previousContent: string | null = null;
|
||||
|
||||
const isMultiLine = computed(() => ['text', 'json'].includes(props.type));
|
||||
|
||||
@@ -84,8 +85,14 @@ onMounted(async () => {
|
||||
}
|
||||
|
||||
codemirror.on('change', (doc, { origin }) => {
|
||||
if (origin === 'setValue') return;
|
||||
const content = doc.getValue();
|
||||
|
||||
// prevent duplicate emits with same content
|
||||
if (content === previousContent) return;
|
||||
previousContent = content;
|
||||
|
||||
if (origin === 'setValue') return;
|
||||
|
||||
if (typeof props.value === 'object') {
|
||||
try {
|
||||
emit('input', content !== '' ? parseJSON(content) : null);
|
||||
|
||||
@@ -77,6 +77,7 @@ export default defineComponent({
|
||||
|
||||
const codemirrorEl = ref<HTMLTextAreaElement | null>(null);
|
||||
let codemirror: CodeMirror.Editor | null;
|
||||
let previousContent: string | null = null;
|
||||
|
||||
onMounted(async () => {
|
||||
if (codemirrorEl.value) {
|
||||
@@ -94,10 +95,14 @@ export default defineComponent({
|
||||
await setLanguage();
|
||||
|
||||
codemirror.on('change', (cm, { origin }) => {
|
||||
if (origin === 'setValue') return;
|
||||
|
||||
const content = cm.getValue();
|
||||
|
||||
// prevent duplicate emits with same content
|
||||
if (content === previousContent) return;
|
||||
previousContent = content;
|
||||
|
||||
if (origin === 'setValue') return;
|
||||
|
||||
if (props.type === 'json') {
|
||||
if (content.length === 0) {
|
||||
return emit('input', null);
|
||||
|
||||
@@ -289,6 +289,7 @@ export default defineComponent({
|
||||
const markdownInterface = ref<HTMLElement>();
|
||||
const codemirrorEl = ref<HTMLTextAreaElement>();
|
||||
let codemirror: CodeMirror.Editor | null = null;
|
||||
let previousContent: string | null = null;
|
||||
|
||||
const view = ref(['editor']);
|
||||
|
||||
@@ -321,10 +322,14 @@ export default defineComponent({
|
||||
});
|
||||
|
||||
codemirror.on('change', (cm, { origin }) => {
|
||||
if (origin === 'setValue') return;
|
||||
|
||||
const content = cm.getValue();
|
||||
|
||||
// prevent duplicate emits with same content
|
||||
if (content === previousContent) return;
|
||||
previousContent = content;
|
||||
|
||||
if (origin === 'setValue') return;
|
||||
|
||||
emit('input', content);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user