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

move_node tests and code clean up #2555

Merged
merged 4 commits into from
Jan 30, 2019

Conversation

jtadmor
Copy link
Contributor

@jtadmor jtadmor commented Jan 22, 2019

Is this adding or improving a feature or fixing a bug?

Improvement (mostly adding tests, some refactoring).

Mostly, this work / investigation was done to satisfy: #2192 (which appears to no longer be necessary, unless I misunderstood)

That issue was cited as a blocker for: #2225

This should also clear up: #2328

What's the new behavior?

n/a

How does this change work?

  • invert.move_node was substantially simplified using PathUtils, bringing the code more in line with element.moveNode
  • Commands.moveNodeByPath function arguments were renamed (internal) to clarify their purpose.
  • tests added

Have you checked that...?

  • The new code matches the existing patterns and styles.
  • The tests pass with yarn test.
  • The linter passes with yarn lint. (Fix errors with yarn prettier.)
  • The relevant examples still work. (Run examples with yarn watch.)

Does this fix any issues or need any specific reviewers?

Fixes: #2192, #2328
Reviewers: @

@jtadmor jtadmor mentioned this pull request Jan 22, 2019
@@ -1763,13 +1763,12 @@ class ElementInterface {
const newParentPath = PathUtils.lift(newPath)
this.assertNode(newParentPath)

const [p, np] = PathUtils.crop(path, newPath)
const position = PathUtils.compare(p, np)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor issue, but we don't really need p and np since compare only checks the smaller size anyway. This avoids the two calls to .slice that crop makes. We just use path.size in the conditional below because we know it is smaller than newPath in order to hit that line

.slice(0, newPathLast)
.concat(inverseNewPath.get(newPathLast) + 1)
.concat(inverseNewPath.slice(newPathLast + 1, inverseNewPath.size))
if (path.size < newPath.size && position === -1) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the same style as the check in element. Some new tests were added to make sure this all still works.

@jtadmor jtadmor changed the title moveNodeByPath tests and code clean up move_node tests and code clean up Jan 22, 2019
@ianstormtaylor
Copy link
Owner

@jtadmor this is absolutely beautiful, thank you very much! My favorite type of pull request 😄

@ianstormtaylor ianstormtaylor merged commit 91d46b3 into ianstormtaylor:master Jan 30, 2019
@jtadmor jtadmor deleted the improvement/2192 branch January 30, 2019 20:18
davidnus pushed a commit to davidnus/slate that referenced this pull request Feb 11, 2019
* tests

* refactor moveNodeByPath

* refactor element.move_node

* refactor invert.move_node
z2devil pushed a commit to z2devil/slate that referenced this pull request Dec 6, 2024
* tests

* refactor moveNodeByPath

* refactor element.move_node

* refactor invert.move_node
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

make operation.newPath consistent
2 participants