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

Refactor cursor positioning #305

Merged
merged 1 commit into from
Jan 26, 2016
Merged

Refactor cursor positioning #305

merged 1 commit into from
Jan 26, 2016

Conversation

bantic
Copy link
Collaborator

@bantic bantic commented Jan 26, 2016

It was previously possible to create a position with a null section or
an invalid section (like a list section). A position must have a section
that the cursor can be rendered at; this PR adds an assertion to that
fact.

Before this change, if the window.getSelection() pointed at the editor's
element, Position#fromNode would naively assume that the post's first
section at offset 0 was the position, but this creates an invalid
position when the first section is a list section.

This tightens up some of the cursor positioning and adds a bunch of tests for Position#fromNode in various scenarios.

  • add Post#headPosition and #tailPosition
  • add Section#isSection property
  • Refactor Position#fromNode
  • tests for Position#fromNode for text nodes, element nodes, card-related nodes
  • Position constructor asserts it has a valid leaft section and offset

It was previously possible to create a position with a null section or
an invalid section (like a list section). A position must have a section
that the cursor can be rendered at; this PR adds an assertion to that
fact.

Before this change, if the window.getSelection() pointed at the editor's
element, Position#fromNode would naively assume that the post's first
section at offset 0 was the position, but this creates an invalid
position when the first section is a list section.

 * add Post#headPosition and #tailPosition
 * add Section#isSection property
 * Refactor Position#fromNode
 * tests for Position#fromNode for text nodes, element nodes, card-related nodes
 * Position constructor asserts it has a valid leaft section and offset
@mixonic
Copy link
Contributor

mixonic commented Jan 26, 2016

🎉 🎉 🎉

mixonic added a commit that referenced this pull request Jan 26, 2016
@mixonic mixonic merged commit 6f5033d into master Jan 26, 2016
@bantic bantic deleted the refactor-cursor-positioning branch April 5, 2016 22:06
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

Successfully merging this pull request may close these issues.

2 participants