There is 1 comment.
 
 
XWiki Platform / cid:jira-generated-image-avatar-17b20fc7-559f-4477-bc55-1cf089a3ae58 XWIKI-22612 Open

Can't use inline style without selecting the text first

 
View issue   ยท   Add comment
 

1 comment

 
cid:jira-generated-image-avatar-a56ea89b-698a-4ea7-a927-175ee02c9a02 Marius Dumitru Florea on 09/Nov/24 14:35
 

I fixed the problem locally for the case when the caret is in the middle of some text, and you want to start typing bold for instance, but while testing this I discovered another issue: if your caret is at the start / end of the line and the line starts / ends with styled text (e.g. bold text) and you want to get out of the style (e.g. by pressing Ctrl+B to "remove" the bold style from the start / end of the line) you can't as long as there are remote changes coming. The root problem is that the code that restores the selection after a remote patch is applied doesn't support placing the caret at the start / end of the line outside the style. Here's an example:

<p><em>italic</em> other</p>

The following happens:

  • the caret is initially inside the <em> tag, at the start of the "italic" text
  • you press Ctrl+I to move the caret before the <em>
  • a remove patch is received
  • the selection is saved
  • the patch is applied
  • the selection is restored => here the caret ends up again inside the <em> tag at the start of the "italic" text, because the code restoring the selection thinks it doesn't make sense to have the caret between <p> and <em> and so it moves to the first text node inside the <em>. Changing this code is not trivial...

To fix this problem, I'll try to implement the following:

  • whenever there is a local change, save the selection relative to the HyperJSON content that is being synchronized by ChainPad (i.e. convert the DOM selection to a text / character selection for the HyperJSON)
  • transform the saved text selection using the received remote patches (which are text level patches) => this will remove the need to perform a diff between the local and the remote content to restore the selection, since we know diffing is slow
  • after remote patches are applied on the edited content, convert the transformed text selection (HyperJSON) to a DOM selection and update the editor selection