visual-space / visual-editor

Rich text editor for Flutter based on Delta format (Quill fork)
MIT License
290 stars 47 forks source link

Markers - Markers in non-scrollable editor return wrong coordinates #160

Closed adrian-moisa closed 2 years ago

adrian-moisa commented 2 years ago

Extracting markers on non-scrollable editor yields global position instead of document position for the text line

The current implementation for extracting rectangles for markers, highlights and headings is fundamentally broken. On non-scrollable docRelPosition editor yields global position instead of document position for the text line. Which means the selection menu example does not work properly on editors that are non scrollable because we are getting different values for the docRelPosition. Also the hovering feature does not work properly in the non scrollable editor, again because we get the wrong offset for text lines. The fix is to compute the relative position to document without subtracting the scroll value form the global position internally. When doing so in the non-scrollable editor the offset is always zero, therefore we are given with viewport relative coordinates instead of the doc relative coordinates.

image

As you can see, first the hovering is not working. Then tapping the text triggers editor to deliver the latest rectangles including the parent scroll offset. Once the markers are update, hovering works just fine, then the next issue is that the computation yields inverted motion effect for any attached widget.

https://user-images.githubusercontent.com/11160141/198390690-80981a1a-e890-4bf1-a8b0-7b124e976993.mov

The alternative would be to convert the docRelPosition property to viewportRelPosition. That means updating all demos and client code. And also it means we are forced to introduce an ugly workaround to trigger the extraction of markers each time the parent scrolls. For sure this is not preferred, therefore somehow we have to get the doc relative position, one way or the other.

Join on discord to get advice and help or follow us on YouTube Visual Coding to learn more about the architecture of Visual Editor and other Flutter apps.

adrian-moisa commented 2 years ago

Found the problem and the solution. We are now calculating the offset from node to editor parent without involving the scroll value.

image