import * as React from 'react'
import { IAutocompletionProvider } from './index'

/** Autocompletion provider for emoji. */
export default class EmojiAutocompletionProvider implements IAutocompletionProvider<string> {
  private emoji: Map<string, string>

  public constructor(emoji: Map<string, string>) {
    this.emoji = emoji
  }

  public getRegExp(): RegExp {
    return /(\\A|\\n| )(:)([a-z0-9\\+\\-][a-z0-9_]*)?/g
  }

  public getAutocompletionItems(text: string) {
    return Array.from(this.emoji.keys()).filter(e => e.startsWith(`:${text}`))
  }

  public renderItem(emoji: string) {
    return (
      <div key={emoji}>
        <img className='emoji' src={this.emoji.get(emoji)}/> {emoji}
      </div>
    )
  }
}

import * as React from 'react'
import { IAutocompletionProvider } from './index'

/** Autocompletion provider for emoji. */
export default class EmojiAutocompletionProvider implements IAutocompletionProvider<string> {
  private emoji: Map<string, string>

  public constructor(emoji: Map<string, string>) {
    this.emoji = emoji
  }

  public getRegExp(): RegExp {
    return /(^|\n| )(:)([a-z0-9\\+\\-][a-z0-9_]*)?/g
  }

  public getAutocompletionItems(text: string) {
    return Array.from(this.emoji.keys()).filter(e => e.startsWith(`:${text}`))
  }

  public renderItem(emoji: string) {
    return (
      <div key={emoji}>
        <img className='emoji' src={this.emoji.get(emoji)}/> {emoji}
      </div>
    )
  }
}

Stop double escaping and match the start of the line
Stop double escaping and match the start of the line
