LoginSignup
4
1

More than 5 years have passed since last update.

CodeMirror Addon の hint/show-hint.js でスニペット実装

Last updated at Posted at 2018-01-18

CodeMirror AutoComplete で検索すると以下のコードがヒットするんですが、もう少し単純なサンプルが欲しかったので実装してみました。

CodePen

エディター上で Cmd-E もしくは Ctrl-E すると、コンテキストメニューみたいなものが出てきて入力出来ます。

See the Pen CodeMirror Addon hint/show-hint.js sample by kkeisuke (@_kkeisuke) on CodePen.

補足

候補を絞り込んでいるのは以下の行で仕組みは単純です。

// snippets は { text: string, displayText: string }[] みたいな感じです。
const list: any[] = snippets.filter(function (item): boolean {
  return item.text.indexOf(currentWord) >= 0
})

もう少し細かい制御をしようと思うと大変そうです。冒頭の記事をご参考ください。

CodeMirror は英語、日本語ともにサンプルが少ないですね :disappointed_relieved:

4
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
1