Files
leadchat/app/javascript/dashboard/components/widgets/mentions/MentionBox.vue
Sivin Varghese 92422f979d chore: Replace plain editor with advanced editor (#13071)
# Pull Request Template

## Description

This PR reverts the plain text editor back to the **advanced editor**,
which was previously removed in
[https://github.com/chatwoot/chatwoot/pull/13058](https://github.com/chatwoot/chatwoot/pull/13058).
All channels now use the **ProseMirror editor**, with formatting applied
based on each channel’s configuration.

This PR also fixes issues where **new lines were not properly preserved
during Markdown serialization**, for both:

* `Enter or CMD/Ctrl+enter` (new paragraph)
* `Shift+Enter` (`hard_break`)

Additionally, it resolves related **[Sentry
issue](https://chatwoot-p3.sentry.io/issues/?environment=production&project=4507182691975168&query=is%3Aunresolved%20markdown&referrer=issue-list&statsPeriod=7d)**.

With these changes:

* Line breaks and spacing are now preserved correctly when saving canned
responses.
* When editing a canned response, the content retains the exact spacing
and formatting as saved in editor.
* Canned responses are now correctly converted to plain text where
required and displayed consistently in the canned response list.

### https://github.com/chatwoot/prosemirror-schema/pull/38

---

## Type of change

- [x] New feature (non-breaking change which adds functionality)

## How Has This Been Tested?



## Checklist:

- [x] My code follows the style guidelines of this project
- [x] I have performed a self-review of my code
- [x] I have commented on my code, particularly in hard-to-understand
areas
- [ ] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings
- [x] I have added tests that prove my fix is effective or that my
feature works
- [x] New and existing unit tests pass locally with my changes
- [ ] Any dependent changes have been merged and published in downstream
modules

---------

Co-authored-by: Muhsin Keloth <muhsinkeramam@gmail.com>
2026-01-08 15:17:54 +05:30

128 lines
3.4 KiB
Vue

<script setup>
import { ref, watch, computed, nextTick } from 'vue';
import { useKeyboardNavigableList } from 'dashboard/composables/useKeyboardNavigableList';
import { useMessageFormatter } from 'shared/composables/useMessageFormatter';
const props = defineProps({
items: {
type: Array,
default: () => [],
},
type: {
type: String,
default: 'canned',
},
});
const emit = defineEmits(['mentionSelect']);
const { getPlainText } = useMessageFormatter();
const mentionsListContainerRef = ref(null);
const selectedIndex = ref(0);
const adjustScroll = () => {
nextTick(() => {
const container = mentionsListContainerRef.value;
if (!container) return;
const selectedElement = container.querySelector(
`#mention-item-${selectedIndex.value}`
);
if (selectedElement) {
selectedElement.scrollIntoView({ block: 'nearest', behavior: 'auto' });
}
});
};
const onSelect = () => {
emit('mentionSelect', props.items[selectedIndex.value]);
};
useKeyboardNavigableList({
items: computed(() => props.items),
onSelect,
adjustScroll,
selectedIndex,
});
watch(
() => props.items,
newItems => {
if (newItems.length < selectedIndex.value + 1) {
selectedIndex.value = 0;
}
}
);
watch(selectedIndex, adjustScroll);
const onHover = index => {
selectedIndex.value = index;
};
const onListItemSelection = index => {
selectedIndex.value = index;
onSelect();
};
const variableKey = (item = {}) => {
return props.type === 'variable' ? `{{${item.label}}}` : `/${item.label}`;
};
</script>
<template>
<div
ref="mentionsListContainerRef"
class="bg-n-solid-1 p-1 rounded-xl overflow-auto absolute w-full z-20 shadow-md left-0 bottom-full max-h-[9.75rem] border border-solid border-n-strong mention--box"
>
<ul class="mb-0 vertical dropdown menu">
<woot-dropdown-item
v-for="(item, index) in items"
:id="`mention-item-${index}`"
:key="item.key"
class="!mb-1"
@mouseover="onHover(index)"
>
<button
class="flex rounded-lg group flex-col gap-0.5 overflow-hidden cursor-pointer items-start px-3 py-2 justify-center w-full h-full text-left hover:bg-n-alpha-black2"
:class="{
'bg-n-alpha-black2': index === selectedIndex,
}"
@click="onListItemSelection(index)"
>
<slot :item="item" :index="index" :selected="index === selectedIndex">
<p
class="max-w-full min-w-0 mb-0 overflow-hidden text-sm font-medium text-n-slate-11 group-hover:text-n-slate-12 text-ellipsis whitespace-nowrap"
:class="{
'text-n-slate-12': index === selectedIndex,
}"
>
{{ getPlainText(item.description) }}
</p>
<p
class="max-w-full min-w-0 mb-0 overflow-hidden text-xs text-n-slate-11 group-hover:text-n-slate-12 text-ellipsis whitespace-nowrap"
:class="{
'text-n-slate-12': index === selectedIndex,
}"
>
{{ variableKey(item) }}
</p>
</slot>
</button>
</woot-dropdown-item>
</ul>
</div>
</template>
<style scoped lang="scss">
.mention--box {
.dropdown-menu__item:last-child > button {
@apply border-0;
}
}
.canned-item__button::v-deep .button__content {
@apply overflow-hidden text-ellipsis whitespace-nowrap;
}
</style>