-
Notifications
You must be signed in to change notification settings - Fork 286
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
209 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { helper } from '@ember/component/helper'; | ||
import { htmlSafe } from '@ember/template'; | ||
import searchMatch from 'ember-inspector/utils/search-match'; | ||
|
||
|
||
function replaceRange(s, start, end, substitute) { | ||
return s.substring(0, start) + substitute + s.substring(end); | ||
} | ||
/** | ||
* | ||
* @param str {string} | ||
* @param regex {RegExp} | ||
* @return {SafeString} | ||
*/ | ||
export function markMatch([str, regex]) { | ||
if (!regex) { | ||
return str; | ||
} | ||
const match = searchMatch(str, regex); | ||
if (!match) { | ||
return str; | ||
} | ||
const matchedText = str.slice(match.index, match.index + match[0].length); | ||
str = replaceRange( | ||
str, | ||
match.index, | ||
match.index + match[0].length, | ||
`<mark>${matchedText}</mark>` | ||
); | ||
return htmlSafe(str); | ||
} | ||
|
||
export default helper(markMatch); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ const KEYS = { | |
right: 39, | ||
down: 40, | ||
left: 37, | ||
backspace: 8, | ||
}; | ||
|
||
export { KEYS }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters