-
Notifications
You must be signed in to change notification settings - Fork 255
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace fuzzy matching with exact substring matching for finding matc…
…hing frames (#407) In #297, I re-used the fuzzy matching logic I implemented in #282 for profile selection. Based on feedback from several people in #352, this is surprising behavior. Upon reflection, this should have been obvious -- I hijacked the Ctrl/Cmd+F browser behaviour, so I should try to replicate the expected behaviour there as closely as possible. Given more patience, I also would've done some user research :) This PR updates this logic to try to more closely match browser behaviour. This means case-insensitive, exact-substring matching. I've left the fuzzy matching alone for profile selection since that doesn't attempt to mimic browser behaviour. The non-fuzzy matching feels slightly odd to me given the filtering behaviour on the sandwich view, but I think consistency across this find UI is important. Here are the before & after results when searching for the string "ca" in the example profile. |Before|After| |-|-| |<img width="1791" alt="image" src="https://user-images.githubusercontent.com/150329/197232741-6d1d7a8a-8b8c-4a4f-98e3-2c043fd7efd5.png">|<img width="1789" alt="image" src="https://user-images.githubusercontent.com/150329/197232694-82697b68-ca15-49e7-887b-2606646ee5e9.png">| Fixes #352 Supersedes #403
- Loading branch information
Showing
5 changed files
with
87 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import {exactMatchStrings} from './profile-search' | ||
|
||
function assertMatch(text: string, pattern: string, expected: string) { | ||
const match = exactMatchStrings(text, pattern) | ||
|
||
let highlighted = '' | ||
let last = 0 | ||
for (let range of match) { | ||
highlighted += `${text.slice(last, range[0])}[${text.slice(range[0], range[1])}]` | ||
last = range[1] | ||
} | ||
highlighted += text.slice(last) | ||
|
||
expect(highlighted).toEqual(expected) | ||
} | ||
|
||
function assertNoMatch(text: string, pattern: string) { | ||
assertMatch(text, pattern, text) | ||
} | ||
|
||
describe('exactMatchStrings', () => { | ||
test('no match', () => { | ||
assertNoMatch('a', 'b') | ||
assertNoMatch('aa', 'ab') | ||
assertNoMatch('a', 'aa') | ||
assertNoMatch('ca', 'ac') | ||
}) | ||
|
||
test('full text match', () => { | ||
assertMatch('hello', 'hello', '[hello]') | ||
assertMatch('multiple words', 'multiple words', '[multiple words]') | ||
}) | ||
|
||
test('case sensitivity', () => { | ||
assertMatch('HELLO', 'hello', '[HELLO]') | ||
assertMatch('Hello', 'hello', '[Hello]') | ||
assertMatch('hello', 'Hello', '[hello]') | ||
assertMatch('hello', 'HELLO', '[hello]') | ||
}) | ||
|
||
test('multiple occurrences', () => { | ||
assertMatch('hello hello', 'hello', '[hello] [hello]') | ||
assertMatch('hellohello', 'hello', '[hello][hello]') | ||
}) | ||
|
||
test('overlapping occurrences', () => { | ||
assertMatch('aaaaa', 'aa', '[aa][aa]a') | ||
assertMatch('abababa', 'aba', '[aba]b[aba]') | ||
}) | ||
}) |
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
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