y-prosemirror icon indicating copy to clipboard operation
y-prosemirror copied to clipboard

Feature: need absolutePositionToRelativePosition method support CellSelection of Prosemirror-tables

Open zlv-thisF opened this issue 4 years ago • 2 comments

Is your feature request related to a problem? absolutePositionToRelativePosition and relativePositionToAbsolutePosition calculate anchor and head inaccurately when selection is CellSelection of prosemirror-tables

Describe the solution you'd like when editor current selection is instance of CellSelection of table, getRelativeSelection and restoreRelativeSelection can restore the cellSelection correctly.

Additional context image the problem not comes from the source code : textSelection.create(xxx), cus I have changed that by telling the type of last selection, the code is as blow: image

I found that the anchor and head is not correct at all when selection is instance of CellSelection, seems absolutePositionToRelativePosition not get correct relativePosition.. however i do not have a clue how to modify the method of absolutePositionToRelativePosition..... : (

zlv-thisF avatar Oct 10 '20 12:10 zlv-thisF

Hi @zlv-thisF Can you please give me steps to reproduce the problem?

E.g.

  1. set cursor location at x
  2. remote cursor is not rendering as expected (if that is the case)

Better yet, show me a broken demo application.

I need specific input and the expected outcome. "It is inaccurate" doesn't help me to find the problem.

dmonad avatar Oct 10 '20 14:10 dmonad

@dmonad I have created a demo here: https://codesandbox.io/s/relaxed-herschel-el656?file=/src/App.js https://el656.csb.app/

The demo above , editor's table menu can create a table with 3 columns and 2 row, when user1 select all fist columns as CellSelection, any operation from user2 will break the user1's selection .

Here is another demo that modified the source code from "tr.setSelection(TextSelection.create)" to "CellSelection" in restorePosFromRelativeToAbsolute

https://codesandbox.io/s/sweet-northcutt-xvl51?file=/src/ySync.js:6913-6921 https://xvl51.csb.app/

This demo can reproduce the inaccurate restored head and anchor when origin selection is CellSelection.

I commented where i had modified with "// MODIFIED" in ySync.js

zlv-thisF avatar Oct 11 '20 16:10 zlv-thisF