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

Toggling a mark stops when selection started at block's end #2830

Closed
FerrielMelarpis opened this issue May 24, 2019 · 5 comments
Closed

Toggling a mark stops when selection started at block's end #2830

FerrielMelarpis opened this issue May 24, 2019 · 5 comments

Comments

@FerrielMelarpis
Copy link

Do you want to request a feature or report a bug?

Report a bug

What's the current behavior?

When selecting a text from end to any point at its left except the start of the block,
and toggling a mark, it stops the toggling state and moves the cursor to the leftmost of the adjacent text node.
It can be seen in Slate examples as well: https://www.slatejs.org/#/rich-text

Here is a screen record:
slate

What's the expected behavior?

The expected behavior is to not lose focus and toggling state shouldn't stop.

@mkoskim
Copy link

mkoskim commented May 25, 2019

More experiences from Rich Text example: go at the end of any line or make one. Press Ctrl-B and write. Text is bold. Now, try to toggle bolding off by pressing Ctrl-B again. When you write something, it is "automatically" toggled bold again. If you select some text at the end of line and press Ctrl-B to toggle bolding off, cursor is taken to the beginning of line.

@FerrielMelarpis
Copy link
Author

@mkoskim I think this is a different issue but it is also a bug on toggling a mark.
toggleMark uses addMark and removeMark commands internally and those commands change marks of the current selection. I tried debugging what happens when I am toggling a mark and it seems like marks becomes null when you remove them. It's not consistent though as I see some text nodes that have marks: [] when the text doesn't have any mark.

{
  anchor: {
    object: "point",
    offset: 6,
    path: [0, 1]
  },
  focus: {
    object: "point",
    offset: 6,
    path: [0, 1]
  }
  isFocused: true,
  marks: null, // I think this is right since we removed the mark on toggling again
  object: "selection"
}

The problem I see is not in the selection but rather in the nature of Slate that it merges text nodes. My theory is that the bug lies in the failure of creating another text node. In an example text like this:

"a b c" =>

      { object: 'text', text: 'a', marks: [] },
      { object: 'text', text: 'b', marks: ['bold'] },
      { object: 'text', text: 'c', marks: [] },

but what happens is text: 'c' is concatenated to text: 'b' even if text: 'b' has marks and selection starting from text: 'c' has marks: null.

@ianstormtaylor sorry for tagging you but if you can point me to the right direction on fixing this, I am willing to submit a PR 😄
Kudos to this awesome framework btw.

@ellinokon
Copy link

Looks like there is work being done here @FerrielMelarpis #2818

@FerrielMelarpis
Copy link
Author

@ellinokon Thanks for referencing the PR. Looks like it will already solve this issue as well but I'll test it for this scenario as this might be a corner case that is not yet caught on the test cases.

@ianstormtaylor
Copy link
Owner

I believe that this may be fixed by #3093, which has changed a lot of the logic in Slate and slate-react especially. I'm going to close this out, but as always, feel free to open a new issue if it persists for you. Thanks for understanding.

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

4 participants