Skip to content
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

Positions referencing text runs may lead to confusion #26

Open
travisleithead opened this issue Aug 19, 2021 · 4 comments
Open

Positions referencing text runs may lead to confusion #26

travisleithead opened this issue Aug 19, 2021 · 4 comments

Comments

@travisleithead
Copy link
Member

FormattedTextPosition - the source reference a FormattedTextRun which is a mutable object (or does it reference a read only copy?). This means it might point to a run which is not the run used to format the paragraph. I think it might lead to confusion and potential bugs. Is it possible to consider a design which follows immutability principle? I assume the reason it is done like that is to reduce potential GC load but is it really such a concern compared to the risk?

@nhelfman

@travisleithead
Copy link
Member Author

I had ulterior motives for this relationship; that is to be unambiguous about the character data's container. In our case that's a FormattedTextRun in all cases, but if this feature gets integrated into DOM, it could be a Text node. It might be a LayoutChild object in Houdini, so a reference seemed ideal. However, I'm not sure I understand a way to do this using the immutability principle--would that be to reference an immutable copy of the text container? Or are you suggesting using a index or some other way of not directly referencing the character data container? Would love more clarity or suggestions.

@nhelfman
Copy link
Contributor

However, I'm not sure I understand a way to do this using the immutability principle--would that be to reference an immutable copy of the text container?

I believe so. And to be more explicit - an immutable copy of the text container which was used for the formatting referenced by this paragraph.

In case the concern is increased memory usage / GC risk then potentially copy-on-write techniques can be applied by implementers to mitigate.

@travisleithead
Copy link
Member Author

Ah. So very similar to issue #23

@travisleithead
Copy link
Member Author

Open question on this issue is whether the metrics will provide an immutable reference to the input text, or whether the Position will need to have a looser coupling with the input than previously described (array-indexes vs object references) which may exacerbate the concerns leading to this issue in the first place.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants