-
Notifications
You must be signed in to change notification settings - Fork 734
Feat/Text highlight #1514
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Feat/Text highlight #1514
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
|
@@ -6,53 +6,53 @@ describe('Text', () => { | |
it('should return the whole string as a single part when highlight string is empty', () => { | ||
const uut = new Text({}); | ||
const result = uut.getTextPartsByHighlight('Playground Screen', ''); | ||
expect(result).toEqual(['Playground Screen']); | ||
expect(result).toEqual([{string: 'Playground Screen', shouldHighlight: false}]); | ||
}); | ||
it('should return the whole string as a single part when highlight string dont match', () => { | ||
const uut = new Text({}); | ||
const result = uut.getTextPartsByHighlight('Playground Screen', 'aaa'); | ||
expect(result).toEqual(['Playground Screen']); | ||
expect(result).toEqual([{string: 'Playground Screen', shouldHighlight: false}]); | ||
}); | ||
it('should break text to parts according to highlight string', () => { | ||
const uut = new Text({}); | ||
const result = uut.getTextPartsByHighlight('Playground Screen', 'Scr'); | ||
expect(result).toEqual(['Playground ', 'Scr', 'een']); | ||
expect(result).toEqual([{string: 'Playground ', shouldHighlight: false}, {string: 'Scr', shouldHighlight: true}, {string: 'een', shouldHighlight: false}]); | ||
}); | ||
|
||
it('should handle case when highlight repeats more than once', () => { | ||
const uut = new Text({}); | ||
const result = uut.getTextPartsByHighlight('Dancing in the Dark', 'Da'); | ||
expect(result).toEqual(['Da', 'ncing in the ', 'Da', 'rk']); | ||
expect(result).toEqual([{string: 'Da', shouldHighlight: true}, {string: 'ncing in the ', shouldHighlight: false}, {string: 'Da', shouldHighlight: true}, {string: 'rk', shouldHighlight: false}]); | ||
}); | ||
|
||
it('should handle ignore case-sensetive', () => { | ||
const uut = new Text({}); | ||
const result = uut.getTextPartsByHighlight('Dancing in the Dark', 'da'); | ||
expect(result).toEqual(['Da', 'ncing in the ', 'Da', 'rk']); | ||
expect(result).toEqual([{string: 'Da', shouldHighlight: true}, {string: 'ncing in the ', shouldHighlight: false}, {string: 'Da', shouldHighlight: true}, {string: 'rk', shouldHighlight: false}]); | ||
}); | ||
|
||
it('Should handle special characters @', () => { | ||
const uut = new Text({}); | ||
const result = uut.getTextPartsByHighlight('@ancing in the @ark', '@a'); | ||
expect(result).toEqual(['@a', 'ncing in the ', '@a', 'rk']); | ||
expect(result).toEqual([{string: '@a', shouldHighlight: true}, {string: 'ncing in the ', shouldHighlight: false}, {string: '@a', shouldHighlight: true}, {string: 'rk', shouldHighlight: false}]); | ||
}); | ||
|
||
it('Should handle special characters !', () => { | ||
const uut = new Text({}); | ||
const result = uut.getTextPartsByHighlight('!ancing in the !ark', '!a'); | ||
expect(result).toEqual(['!a', 'ncing in the ', '!a', 'rk']); | ||
expect(result).toEqual([{string: '!a', shouldHighlight: true}, {string: 'ncing in the ', shouldHighlight: false}, {string: '!a', shouldHighlight: true}, {string: 'rk', shouldHighlight: false}]); | ||
}); | ||
|
||
it('Should handle special characters starts with @', () => { | ||
const uut = new Text({}); | ||
const result = uut.getTextPartsByHighlight('[email protected]', '@wix'); | ||
expect(result).toEqual(['uilib', '@wix', '.com']); | ||
expect(result).toEqual([{string: 'uilib', shouldHighlight: false}, {string: '@wix', shouldHighlight: true}, {string: '.com', shouldHighlight: false}]); | ||
}); | ||
|
||
it('Should handle empty string .', () => { | ||
const uut = new Text({}); | ||
const result = uut.getTextPartsByHighlight('@ancing in the @ark', ''); | ||
expect(result).toEqual(['@ancing in the @ark']); | ||
expect(result).toEqual([{string: '@ancing in the @ark', shouldHighlight: false}]); | ||
}); | ||
}); | ||
}); |
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about using a forEach or even a map in this case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I can't use map or forEach here since in every iteration I use the current index and the next one (k and k+1) which is not possible with those methods..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, map and forEach that comes with javascript don't retrieve the Index..
But using lodash's
_.forEach
or_.map
, you also have access to the indexThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, but I need the
item
and the nextitem
..I can use it that way:
_.forEach(array, (item, index) => console.log(item, array[index + 1]))
but I don't think it makes that more clear..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I have one last suggestion, let me know what you think (:
What if instead of keeping the indices as couples (which I personally find confusing) you'll keep them as objects of {start, end}, so indices looks like this
I think it'll make a easier to understand (:
WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool, done :)