Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,16 @@ export default class App extends Component<{

selectNode = (node_id: NodeID) =>
{
this.setState({
chosenNode: node_id,
});
const root = this.state.ourTree.root
const node = this.state.ourTree._selectNodeById(node_id)
if (node !== root)
{
const parent = root.getParent(node, root)
parent.lastSelectedChild = node_id
this.setState({
chosenNode: node_id,
});
}
}

selectParentNode = () =>
Expand All @@ -99,7 +106,7 @@ export default class App extends Component<{
if (node !== root)
{
const parent = root.getParent(node, root)

parent.lastSelectedChild = node.id
this.setState({
chosenNode: parent.id
})
Expand All @@ -114,7 +121,7 @@ export default class App extends Component<{
const child = node.children[0]

this.setState({
chosenNode: child.id
chosenNode: node.lastSelectedChild || child.id
})
}
}
Expand All @@ -129,7 +136,9 @@ export default class App extends Component<{
const indexOfNode = parent.children.indexOf(node)
const indexOfNextChild = Math.min(indexOfNode+1, parent.children.length-1)
const nextChild = parent.children[indexOfNextChild]


parent.lastSelectedChild = nextChild.id

this.setState({
chosenNode: nextChild.id
})
Expand All @@ -147,6 +156,8 @@ export default class App extends Component<{
const indexOfPrevChild = Math.max(indexOfNode-1, 0)
const prevChild = parent.children[indexOfPrevChild]

parent.lastSelectedChild = prevChild.id

this.setState({
chosenNode: prevChild.id
})
Expand Down
2 changes: 2 additions & 0 deletions src/core/tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,12 +196,14 @@ export class TreeNode<T>
// TODO: how about children being Sets?
children: TreeNode<T>[];
data: T;
lastSelectedChild: NodeID | null;
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Aside for my hatred for nulls -> this most definitely does not belong in the core, since it's a UI matter => but the same logic injected into UI Node would de most definitely sensible.


constructor(id: NodeID, data: T, children: TreeNode<T>[] = [])
{
this.data = data;
this.id = id;
this.children = children;
this.lastSelectedChild = null
}

_append(node: TreeNode<T>)
Expand Down