mirror of
				https://github.com/go-gitea/gitea
				synced 2025-11-03 21:08:25 +00:00 
			
		
		
		
	Improve emoji and mention matching (#24255)
Prioritize matches that start with the given text, then matches that contain the given text. I wanted to add a heart emoji on a pull request comment so I started writing `:`, `h`, `e`, `a`, `r` (at this point I still couldn't find the heart), `t`... The heart was not on the list, that's weird - it feels like I made a typo or a mistake. This fixes that. This also feels more like GitHub's emoji auto-complete. # Before  # After  --------- Signed-off-by: Yarden Shoham <git@yardenshoham.com> Co-authored-by: silverwind <me@silverwind.io>
This commit is contained in:
		@@ -5,11 +5,11 @@ import {attachTribute} from '../tribute.js';
 | 
			
		||||
import {hideElem, showElem, autosize} from '../../utils/dom.js';
 | 
			
		||||
import {initEasyMDEImagePaste, initTextareaImagePaste} from './ImagePaste.js';
 | 
			
		||||
import {handleGlobalEnterQuickSubmit} from './QuickSubmit.js';
 | 
			
		||||
import {emojiKeys, emojiString} from '../emoji.js';
 | 
			
		||||
import {emojiString} from '../emoji.js';
 | 
			
		||||
import {renderPreviewPanelContent} from '../repo-editor.js';
 | 
			
		||||
import {matchEmoji, matchMention} from '../../utils/match.js';
 | 
			
		||||
 | 
			
		||||
let elementIdCounter = 0;
 | 
			
		||||
const maxExpanderMatches = 6;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * validate if the given textarea is non-empty.
 | 
			
		||||
@@ -106,14 +106,7 @@ class ComboMarkdownEditor {
 | 
			
		||||
    const expander = this.container.querySelector('text-expander');
 | 
			
		||||
    expander?.addEventListener('text-expander-change', ({detail: {key, provide, text}}) => {
 | 
			
		||||
      if (key === ':') {
 | 
			
		||||
        const matches = [];
 | 
			
		||||
        const textLowerCase = text.toLowerCase();
 | 
			
		||||
        for (const name of emojiKeys) {
 | 
			
		||||
          if (name.toLowerCase().includes(textLowerCase)) {
 | 
			
		||||
            matches.push(name);
 | 
			
		||||
            if (matches.length >= maxExpanderMatches) break;
 | 
			
		||||
          }
 | 
			
		||||
        }
 | 
			
		||||
        const matches = matchEmoji(text);
 | 
			
		||||
        if (!matches.length) return provide({matched: false});
 | 
			
		||||
 | 
			
		||||
        const ul = document.createElement('ul');
 | 
			
		||||
@@ -129,14 +122,7 @@ class ComboMarkdownEditor {
 | 
			
		||||
 | 
			
		||||
        provide({matched: true, fragment: ul});
 | 
			
		||||
      } else if (key === '@') {
 | 
			
		||||
        const matches = [];
 | 
			
		||||
        const textLowerCase = text.toLowerCase();
 | 
			
		||||
        for (const obj of window.config.tributeValues) {
 | 
			
		||||
          if (obj.key.toLowerCase().includes(textLowerCase)) {
 | 
			
		||||
            matches.push(obj);
 | 
			
		||||
            if (matches.length >= maxExpanderMatches) break;
 | 
			
		||||
          }
 | 
			
		||||
        }
 | 
			
		||||
        const matches = matchMention(text);
 | 
			
		||||
        if (!matches.length) return provide({matched: false});
 | 
			
		||||
 | 
			
		||||
        const ul = document.createElement('ul');
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user