-
Notifications
You must be signed in to change notification settings - Fork 63
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
Allow to link page to next element independently of hierarchy level #6255
Allow to link page to next element independently of hierarchy level #6255
Conversation
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.
Works as expected and code looks very solid to me! Thanks a lot.
As suggested in #5457 (comment), we can inspect the effects of dragging linked nodes around at a later point in time.
private TreeNode findNextLogicalNodeForViewAssignmentRecursive(TreeNode node) { | ||
TreeNode current = node; | ||
|
||
while (Objects.nonNull(current)) { | ||
if (Objects.isNull(getTreeNodeStructuralElement(current))) { | ||
// node is not a logical node | ||
return null; | ||
} | ||
|
||
// check whether next sibling is a logical node as well | ||
List<TreeNode> currentSiblings = current.getParent().getChildren(); | ||
int currentIndex = currentSiblings.indexOf(current); | ||
|
||
if (currentSiblings.size() > currentIndex + 1) { | ||
TreeNode nextSibling = currentSiblings.get(currentIndex + 1); | ||
if (Objects.isNull(getTreeNodeStructuralElement(nextSibling))) { | ||
// next sibling is not a logical node | ||
return null; | ||
} | ||
|
||
// next sibling is a logical node and potential valid result, unless there are children | ||
TreeNode nextLogical = nextSibling; | ||
|
||
// check sibling has children (with first child being another logical node) | ||
while (!nextLogical.getChildren().isEmpty()) { | ||
TreeNode firstChild = nextLogical.getChildren().get(0); | ||
if (Objects.isNull(getTreeNodeStructuralElement(firstChild))) { | ||
// first child is not a logical node | ||
return nextLogical; | ||
} | ||
// iterate to child node | ||
nextLogical = firstChild; | ||
} | ||
return nextLogical; | ||
} | ||
|
||
// node is last amongst siblings | ||
// iterate to parent node | ||
current = current.getParent(); | ||
} | ||
return null; | ||
} |
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.
Method is very long and could probably be refactored in smaller methods, but as the logic is quite complex it is also good to have it in one place. So i think this is all good to go!
Fixes #5457
This pull request allows to add a new link (context menu entry "Assign to next element") for the currently selected page to the following folder independently of its hierarchy level. The selection logic works as follows:
This pull request also checks if a link has already been added before such that users cannot accidentally add the same link twice (the menu entry "Assign to next element" disappears).
Demo
2024-10-08.14-56-08.mp4