-
Notifications
You must be signed in to change notification settings - Fork 65
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 text selection on Web doesn't work when passing markdownStyle without useMemo #547
base: main
Are you sure you want to change the base?
Conversation
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.
Also, does the selection work correctly when changing markdownStyle
?
function deepEqualMarkdownStyles(markdownStyle1: MarkdownStyle, markdownStyle2: PartialMarkdownStyle) { | ||
const keys1 = Object.keys(markdownStyle1) as Array<keyof MarkdownStyle>; | ||
const keys2 = Object.keys(markdownStyle2) as Array<keyof MarkdownStyle>; | ||
|
||
if (keys1.length !== keys2.length) { | ||
return false; | ||
} |
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.
Since all values of markdownStyle
are serializable, why can't we just compare JSON.stringify(markdownStyle1) === JSON.stringify(markdownStyle2)
?
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.
Don't we want to treat objects like {color: '#FF0000', backgroundColor: '#FF0000'}
and {backgroundColor: '#FF0000', color: '#FF0000'}
as equal? That's the only reason I didn't use JSON.stringify
, because it maintains order. We could use JSON.stringify
, but then some logically equal objects(but with changed order of props) would come out as not equal. WDYT?
src/styleUtils.ts
Outdated
function parseStringWithUnitToNumber(value: string | null): number { | ||
return value ? parseInt(value.replace('px', ''), 10) : 0; | ||
} | ||
|
||
export type {PartialMarkdownStyle}; | ||
|
||
export {mergeMarkdownStyleWithDefault, parseStringWithUnitToNumber}; | ||
export {mergeMarkdownStyleWithDefault, parseStringWithUnitToNumber, deepEqualMarkdownStyles as deepCompareMarkdownStyles}; |
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.
Why do we export deepEqualMarkdownStyles
with a different name deepCompareMarkdownStyles
?
Maybe we should write some tests that would cover this case? @tomekzaw |
Definitely yes |
1302bf2
to
c89eeea
Compare
Details
markdownStyle
object was compared by reference and was causing extra useMemo rerenders, which removed text selection. This PR makesMarkdownTextInput.web
component comparesmarkdownStyle
object deeply and fixes this bug.Related Issues
GH_LINK
#544
Manual Tests
On web example, try selecting text and verify it works.
Linked PRs