# Emoji is inserted at the wrong place

**URL:** https://meta.discourse.org/t/emoji-is-inserted-at-the-wrong-place/302931
**Category:** Bug
**Tags:** emoji
**Created:** [April 8, 2024, 8:40pm UTC](https://meta.discourse.org/t/emoji-is-inserted-at-the-wrong-place/302931 "2024-04-08T20:40:25Z")
**Posts on this page:** 1
**Showing post:** 10

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [November 2, 2025, 11:57pm UTC](https://meta.discourse.org/t/emoji-is-inserted-at-the-wrong-place/302931/10 "2025-11-02T23:57:50Z")

</div>

Oh I get it, this fixes it:

```plaintext
diff --git a/frontend/discourse/app/modifiers/d-autocomplete.js b/frontend/discourse/app/modifiers/d-autocomplete.js
index e49fc0ec53..33fb51a1f4 100644
--- a/frontend/discourse/app/modifiers/d-autocomplete.js
+++ b/frontend/discourse/app/modifiers/d-autocomplete.js
@@ -599,10 +599,19 @@ export default class DAutocompleteModifier extends Modifier {
         prev = this.getValue()[caretPos - 1];
         const shouldTrigger = await this.shouldTrigger({ backSpace });
 
- if (
- shouldTrigger &&
- (prev === undefined || this.ALLOWED_LETTERS_REGEXP.test(prev))
- ) {
+ // For emoji autocomplete (key === ':'), use a more permissive check that includes
+ // common punctuation like comma, period, etc. that can appear before emoji
+ let isAllowed;
+ if (this.options.key === ":") {
+ // Match the same characters allowed in emoji autocomplete's onKeyUp regex
+ isAllowed =
+ prev === undefined || /[\s.?,@/#!%&*;:\[\]{}=\-_()+]/.test(prev);
+ } else {
+ isAllowed =
+ prev === undefined || this.ALLOWED_LETTERS_REGEXP.test(prev);
+ }
+
+ if (shouldTrigger && isAllowed) {
           start = caretPos;
           term = this.getValue().substring(caretPos + 1, initialCaretPos);
           end = caretPos + term.length;

```

@kelv I am not super familiar with how this code evolved, perhaps some of this rings a bell with some of the porting you did recently?

---

_[View the full topic](https://meta.discourse.org/t/emoji-is-inserted-at-the-wrong-place/302931)._
