-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
move_node tests and code clean up #2555
Conversation
@@ -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) |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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.
moveNodeByPath
tests and code clean up966c36a
to
8e37ec3
Compare
8e37ec3
to
26a4fd0
Compare
@jtadmor this is absolutely beautiful, thank you very much! My favorite type of pull request 😄 |
* tests * refactor moveNodeByPath * refactor element.move_node * refactor invert.move_node
* tests * refactor moveNodeByPath * refactor element.move_node * refactor invert.move_node
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 usingPathUtils
, bringing the code more in line withelement.moveNode
Commands.moveNodeByPath
function arguments were renamed (internal) to clarify their purpose.Have you checked that...?
yarn test
.yarn lint
. (Fix errors withyarn prettier
.)yarn watch
.)Does this fix any issues or need any specific reviewers?
Fixes: #2192, #2328
Reviewers: @