| Conditions | 4 |
| Total Lines | 19 |
| Code Lines | 12 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | import { inputRules, InputRule } from 'prosemirror-inputrules'; |
||
| 10 | export function smileyRule() { |
||
| 11 | return new InputRule(SmileyConf.getRegex(), ((state, match) => { |
||
| 12 | const { tr } = state; |
||
| 13 | const syntax = match[0]; |
||
| 14 | |||
| 15 | // get icon corresponding to the captured group |
||
| 16 | let group = 0; |
||
| 17 | for (let i = 0; i < match.length; i += 1) { |
||
| 18 | if (i > 0 && match[i] === syntax) { |
||
| 19 | group = i; |
||
| 20 | break; |
||
| 21 | } |
||
| 22 | } |
||
| 23 | const { icon } = SmileyConf.getSmileys()[group - 1]; |
||
| 24 | |||
| 25 | tr.setSelection(TextSelection.create(tr.doc, tr.selection.from, tr.selection.from - syntax.length + 1)); |
||
| 26 | return tr.replaceSelectionWith(state.schema.nodes.smiley.create({ icon, syntax })); |
||
| 27 | })); |
||
| 28 | } |
||
| 29 | |||
| 43 |