(regex, flags, editorState)
| 93 | }; |
| 94 | |
| 95 | const checkRegex = (regex, flags, editorState) => { |
| 96 | let rowIndex = 0; |
| 97 | let matchCount = 0; |
| 98 | |
| 99 | if (!regex) { |
| 100 | const content = editorState.getCurrentContent(); |
| 101 | return EditorState.createWithContent(content); |
| 102 | } |
| 103 | |
| 104 | function findWithRegex(content: ContentBlock, callback: Function) { |
| 105 | const isMultiple = flags.includes('m'); |
| 106 | const isNeededMultiple = regex.startsWith('^') || regex.endsWith('$'); |
| 107 | |
| 108 | if (!isMultiple && isNeededMultiple && rowIndex > 0) return; |
| 109 | |
| 110 | const isGlobal = flags.includes('g'); |
| 111 | |
| 112 | if (!isGlobal && matchCount > 0) return; |
| 113 | |
| 114 | const text = content.getText(); |
| 115 | const currentRegex = new RegExp(regex, isGlobal ? flags : `g${flags}`); |
| 116 | |
| 117 | let matches = [...text.matchAll(currentRegex)]; |
| 118 | |
| 119 | if (!isGlobal) { |
| 120 | matches = matches.slice(0, 1); |
| 121 | } |
| 122 | |
| 123 | if (regex && matches.length) { |
| 124 | matches.forEach(match => callback(match.index, match.index + match[0].length)); |
| 125 | } |
| 126 | |
| 127 | if (matches.length) { |
| 128 | matchCount++; |
| 129 | } |
| 130 | |
| 131 | rowIndex++; |
| 132 | } |
| 133 | |
| 134 | function handleStrategy(content: ContentBlock, callback: Function) { |
| 135 | try { |
| 136 | findWithRegex(content, callback); |
| 137 | } catch (err) {} |
| 138 | } |
| 139 | |
| 140 | const HighlightDecorator = new CompositeDecorator([ |
| 141 | { |
| 142 | strategy: handleStrategy, |
| 143 | component: Highlight, |
| 144 | }, |
| 145 | ]); |
| 146 | |
| 147 | return EditorState.createWithContent(editorState.getCurrentContent(), HighlightDecorator); |
| 148 | }; |
| 149 | |
| 150 | const handleShare = () => { |
| 151 | axios |
no outgoing calls
no test coverage detected