-
Notifications
You must be signed in to change notification settings - Fork 47
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
feat(highlight): Promote and show staged highlight annotation #563
Conversation
mxiao6
commented
Aug 27, 2020
•
edited
Loading
edited
- Tests
// empty list, push current | ||
if (!prev) { | ||
dedupedRects.push(curr); | ||
return; |
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.
We generally try to avoid multiple returns (outside of guard clauses) because it can make the function more difficult to step through.
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.
The pop()
may return undefined
, so this is a guard clause. I removed an unnecessary return
below.
603dc0b
to
d8741a2
Compare
src/store/promoter/actions.ts
Outdated
import { SelectionItem } from './types'; | ||
import { Shape } from '../../@types'; | ||
|
||
export type SelectionArg = { | ||
location: number; | ||
pageRect: DOMRect; |
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.
Does this need to be stored?
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.
Yeah, it's needed. If we get page rect on rendering, and if user selects text then scrolls page before clicks promotion button, the page x/y will not match with selection x/y. Have to get them and store them at the same moment.
d8741a2
to
6197ae0
Compare
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 the selection is more than the promoter since explicit highlight mode will make use of it as well. Should we move this promoter
store to be highlight
store or something else instead?
groups[roundedY] = groups[roundedY] || []; | ||
groups[roundedY].push(rect); | ||
return groups; | ||
}, {} as Record<number, Shape[]>); |
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.
Would we be able to get rid of this cast if we defined rows
as Record<number, Shape[]>
?
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.
Tried, doesn't work. It seems like TS is not able to infer accumulator's type from result's type, unfortunately.
Renaming will change a lot of files, which makes harder to review this PR. I'm thinking to do it in a separate PR. |
f43f7ff
to
36c7ec9
Compare
const xThreshold = getThreshold(prevWidth, width, threshold); | ||
const yThreshold = getThreshold(prevHeight, height, threshold); | ||
|
||
if (Math.abs(prevX - x) <= xThreshold && Math.abs(prevY - y) <= yThreshold) { |
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.
Should width and height still be taken into account in determining duplication?
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.
If two rects have the same x and y, one must be the duplicate of the other, right? So I think only comparing x and y is enough for determining duplications.
584391b
to
1766326
Compare
1766326
to
44c8e45
Compare
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.
LGTM, probably want to update the description to remove the link to the box-content-preview PR