-
-
Notifications
You must be signed in to change notification settings - Fork 280
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
fix: Don't rely on removeDiacritics
to highlight text
#4636
fix: Don't rely on removeDiacritics
to highlight text
#4636
Conversation
106cce3
to
bd40471
Compare
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## develop #4636 +/- ##
==========================================
+ Coverage 9.68% 9.69% +0.01%
==========================================
Files 318 318
Lines 16124 16146 +22
==========================================
+ Hits 1561 1565 +4
- Misses 14563 14581 +18 ☔ View full report in Codecov by Sentry. |
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.
Hi @g123k!
What happens then with œ
vs. oe
?
- it's detected as similar (with
removeDiacritics
) but not highlighted (with_removeAccents
)? - it's never considered similar (as not present in
_removeAccents
)? - should we still use
removeDiacritics
then, and couldn't we get rid of that package?
The initial string with
|
My question is: will the search match for |
…s`, as it replaces some letters of 1 word into 2 or +
bd40471
to
7af2c89
Compare
The algorithm was not fully working, by being tricked if the diacritic was in the text and/or in the filter. Screen.Recording.2023-12-09.at.02.44.52.movI've also added an |
@g123k Ready for review? |
Yes, that's OK now |
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.
Hi @g123k!
In the PR there are many myString.toLowerCase().removeDiacritics()
(and sometimes myString.removeDiacritics().toLowerCase()
, which is a bit confusing).
We may be better off with a simpler method like String getComparisonSafeString(String)
that would return a combo of removeDiacritics
and toLowerCase
always in the same order.
But my main question is: does your fix work for the initial issue with œ
and oe
, when filtering and when displaying? Probably worth a test
.
.removeDiacritics() | ||
.toLowerCase() | ||
.contains( | ||
query!.removeDiacritics().toLowerCase().trim(), | ||
), |
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.
Shouldn't that be first toLowerCase
and the removeDiacritics
, like on the rest of the code?
/// An extension on [String] | ||
extension StringExtension on String { | ||
/// Simple algorithm to only remove accents AND not diacritics. | ||
String removeAccents() { |
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.
That method is never used, right? We'd be better off without it, then.
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 hesitate on this, as removeDiactrictics
requires a lot of memory + CPU.
The idea of this method is to have a quicker way to remove accents, not all, but 90%
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.
Then please get rid of package:diacritic/diacritic.dart
instead.
We can't have two methods that do the same thing and one being never used ("your" removeAccents
).
If you're confident enough in your faster code, let's use it!
Ok for the suggestion, but for your question, my video answers it, isn't-it? |
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.
Hi @g123k!
Fair enough, the video is convincing!
Thank you for taking into account my comments.
Still, it's problematic to have two methods doing the same thing, one that you coded, that goes fast but is never called, and one from an external package that is more demanding and that is the only one called.
Please get rid of one of them: both methods look OK, but we can't have both.
.toLowerCase()) | ||
_languages | ||
.getNameInEnglish(item) | ||
.getComparisonSafeString() | ||
.contains(query!.toLowerCase()) || |
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.
.contains(query!.toLowerCase()) || | |
.contains(query!) || |
.toLowerCase()) | ||
_languages | ||
.getNameInLanguage(item) | ||
.getComparisonSafeString() | ||
.contains(query.toLowerCase()) || |
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.
.contains(query.toLowerCase()) || | |
.contains(query!) || |
/// An extension on [String] | ||
extension StringExtension on String { | ||
/// Simple algorithm to only remove accents AND not diacritics. | ||
String removeAccents() { |
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.
Then please get rid of package:diacritic/diacritic.dart
instead.
We can't have two methods that do the same thing and one being never used ("your" removeAccents
).
If you're confident enough in your faster code, let's use it!
Actually I use the |
Understood.
It is dead code. We don't need dead code, do we? |
Ok, I've removed the method + added a test for the new method. |
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.
Thank you @g123k for this PR!
Thanks @g123k and @monsieurtanuki for the review |
Hi everyone,
When we highlight suggestions, we use the
removeDiacritics
method.However, it replaces some characters (eg:
œ
) by 2 or more letters (eg:oe
)I use instead a simpler algorithm to only remove accents.