# 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:** 19
**Page:** 1

<div class="post-metadata">

### Author: ![Moin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/moin/32/554653_2.png) [@Moin](https://meta.discourse.org/u/Moin)
#### Post date: [April 8, 2024, 8:40pm UTC](https://meta.discourse.org/t/emoji-is-inserted-at-the-wrong-place/302931/1 "2024-04-08T20:40:25Z")

</div>

While the emoji autocomplete does not work when you add a colon behind a letter, it offers emojis when you do the same after a punctuation mark (like \_ - : ; . , ). But when you use the autocomplete, the emoji is inserted at the beginning, replacing the first letter, and not at the position you were typing.

I first noticed it in chat, but the topic composer behaves the same.

---

<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: [October 30, 2025, 1:51am UTC](https://meta.discourse.org/t/emoji-is-inserted-at-the-wrong-place/302931/2 "2025-10-30T01:51:31Z")

</div>

I can no longer repro this, I believe @kelv fixed it.

---

<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: [October 30, 2025, 1:51am UTC](https://meta.discourse.org/t/emoji-is-inserted-at-the-wrong-place/302931/3 "2025-10-30T01:51:34Z")

</div>



---

<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: [October 30, 2025, 3:30am UTC](https://meta.discourse.org/t/emoji-is-inserted-at-the-wrong-place/302931/4 "2025-10-30T03:30:37Z")

</div>



---

<div class="post-metadata">

### Author: ![Moin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/moin/32/554653_2.png) [@Moin](https://meta.discourse.org/u/Moin)
#### Post date: [October 30, 2025, 3:33am UTC](https://meta.discourse.org/t/emoji-is-inserted-at-the-wrong-place/302931/5 "2025-10-30T03:33:26Z")

</div>

I can still reproduce this.

I typed:

> Let’s write some text, and add an emoji

And then I tried to add an emoji behind the comma.

---

<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: [October 30, 2025, 5:06am UTC](https://meta.discourse.org/t/emoji-is-inserted-at-the-wrong-place/302931/6 "2025-10-30T05:06:36Z")

</div>

Is this only an iOS thing? Are other browsers impacted?

---

<div class="post-metadata">

### Author: ![Moin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/moin/32/554653_2.png) [@Moin](https://meta.discourse.org/u/Moin)
#### Post date: [October 30, 2025, 7:25am UTC](https://meta.discourse.org/t/emoji-is-inserted-at-the-wrong-place/302931/7 "2025-10-30T07:25:23Z")

</div>

I don’t know if it’s an iOS thing. It’s definitely not limited to iOS because I don’t own an iOS device.  
The latest repro is on my Android tablet using Firefox. (I just checked it’s the same in Chrome)

Based on the filename, time of the report, and the fact that there is no onscreen keyboard in the OP, that was probably Edge on Windows 10.

---

<div class="post-metadata">

### Author: ![Richie](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/richie/32/115110_2.png) [@Richie](https://meta.discourse.org/u/Richie)
#### Post date: [November 1, 2025, 6:41pm UTC](https://meta.discourse.org/t/emoji-is-inserted-at-the-wrong-place/302931/8 "2025-11-01T18:41:18Z")

</div>

I just came here to report this issue @Moin 🙂

iPadOS 18.7.1 with Safari here if it helps @sam

Also seeing another issue when highlighting text to quote it on iPad, the Discourse “quote” popup is now hidden behind the iOS “copy paste” so you can never click on it. I’ll try and work out the steps to replicate and report it separately later in the week (unless anyone beats me to it). Mentioning it here as possibly related because both issues only appeared this week.

---

<div class="post-metadata">

### Author: ![Moin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/moin/32/554653_2.png) [@Moin](https://meta.discourse.org/u/Moin)
#### Post date: [November 2, 2025, 8:02am UTC](https://meta.discourse.org/t/emoji-is-inserted-at-the-wrong-place/302931/9 "2025-11-02T08:02:25Z")

</div>

> [@Richie](#):
>
> Mentioning it here as possibly related because both issues only appeared this week.

Then I am not sure your issue is the same as mine. The misplacement of the emoji after a punctuation mark is something that has happened for 1.5 years now.

---

<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?

---

<div class="post-metadata">

### Author: ![kelv](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/kelv/32/524739_2.png) [@kelv](https://meta.discourse.org/u/kelv)
#### Post date: [November 4, 2025, 7:28am UTC](https://meta.discourse.org/t/emoji-is-inserted-at-the-wrong-place/302931/11 "2025-11-04T07:28:24Z")

</div>

It’s not related to the porting, I just repro’d it on an older instance (`3.5.0.beta8-dev`) with the new floatkit-based autocomplete toggled off. Seems to be a caret positioning bug that’s been there for some time. I’ll still look into a proper fix, but shouldn’t be a blocker for the full removal of the old autocomplete library.

---

<div class="post-metadata">

### Author: ![Moin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/moin/32/554653_2.png) [@Moin](https://meta.discourse.org/u/Moin)
#### Post date: [November 5, 2025, 10:08pm UTC](https://meta.discourse.org/t/emoji-is-inserted-at-the-wrong-place/302931/12 "2025-11-05T22:08:59Z")

</div>

I just lost a whole chat message after I added an emoji.

I typed the message, typed the colon and two letters to get suggestions, clicked more and an emoji, and then the whole message was gone. Is this a different bug or related? So far, I couldn’t reproduce it in the composer, only in chat. And only on my laptop, not on my tablet.

---

<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 6, 2025, 12:07am UTC](https://meta.discourse.org/t/emoji-is-inserted-at-the-wrong-place/302931/13 "2025-11-06T00:07:31Z")

</div>

Yeah its the boundary detection bug, we are getting confused about where emojis can start and end.

The tricky thing here is that maybe the whole logic is wrong, I wonder why it even needs to make this kind of decision given it knows exactly where the cursor is and how many letters we passed on to emoji autocomplete. Maybe just work back N chars and then replace that… not sure.

---

<div class="post-metadata">

### Author: ![kelv](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/kelv/32/524739_2.png) [@kelv](https://meta.discourse.org/u/kelv)
#### Post date: [November 6, 2025, 3:15am UTC](https://meta.discourse.org/t/emoji-is-inserted-at-the-wrong-place/302931/14 "2025-11-06T03:15:46Z")

</div>

Oof, that’s a different bug, because I just patched the earlier type of issue with an emoji insert right after punctuation ([FIX: emojis should insert right after punctuation correctly by tyb-talks · Pull Request #35830 · discourse/discourse · GitHub](https://github.com/discourse/discourse/pull/35830)) which is not yet deployed here to Meta.

Similarly, this has been there for a while, and I can confirm it’s only happening in chat. Will park some time for this too.

---

<div class="post-metadata">

### Author: ![Moin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/moin/32/554653_2.png) [@Moin](https://meta.discourse.org/u/Moin)
#### Post date: [November 6, 2025, 8:09am UTC](https://meta.discourse.org/t/emoji-is-inserted-at-the-wrong-place/302931/15 "2025-11-06T08:09:32Z")

</div>

> [@kelv](#):
>
> just patched the earlier type of issue with an emoji insert right after punctuation ([FIX: emojis should insert right after punctuation correctly by tyb-talks · Pull Request #35830 · discourse/discourse · GitHub](https://github.com/discourse/discourse/pull/35830))

Thank you. It works fabulously.

---

<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 10, 2025, 5:08am UTC](https://meta.discourse.org/t/emoji-is-inserted-at-the-wrong-place/302931/16 "2025-11-10T05:08:29Z")

</div>



---

<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 10, 2025, 8:42am UTC](https://meta.discourse.org/t/emoji-is-inserted-at-the-wrong-place/302931/17 "2025-11-10T08:42:51Z")

</div>



---

<div class="post-metadata">

### Author: ![kelv](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/kelv/32/524739_2.png) [@kelv](https://meta.discourse.org/u/kelv)
#### Post date: [November 15, 2025, 12:27am UTC](https://meta.discourse.org/t/emoji-is-inserted-at-the-wrong-place/302931/19 "2025-11-15T00:27:19Z")

</div>

This is now fixed as of [FIX: emoji picker autocomplete in chat replaces entire draft by tyb-talks · Pull Request #36017 · discourse/discourse · GitHub](https://github.com/discourse/discourse/pull/36017) . Thanks for the report 🙂

---

<div class="post-metadata">

### Author: ![kelv](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/kelv/32/524739_2.png) [@kelv](https://meta.discourse.org/u/kelv)
#### Post date: [November 18, 2025, 1:28am UTC](https://meta.discourse.org/t/emoji-is-inserted-at-the-wrong-place/302931/21 "2025-11-18T01:28:21Z")

</div>

This topic was automatically closed after 3 days. New replies are no longer allowed.
