Skip to content

Commit

Permalink
delete sibling / child nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
fohristiwhirl committed Jun 29, 2019
1 parent dcae41b commit fd79523
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 6 deletions.
5 changes: 2 additions & 3 deletions 50_tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,10 @@ const node_prototype = {
detach: function() {

// Returns the node that the renderer should point to,
// which is either the parent (if there is one) or
// this node itself (if there isn't).
// which is the parent unless the call is a bad one.

let parent = this.parent;
if (!parent) return this;
if (!parent) return this; // Fail

let new_list_for_parent = [];

Expand Down
24 changes: 23 additions & 1 deletion 95_renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ function NewRenderer() {
this.movelist_handler.draw(this.node);
};

renderer.delete_move = function() {
renderer.delete_node = function() {

if (!this.node.parent) {
return;
Expand All @@ -251,6 +251,28 @@ function NewRenderer() {
this.position_changed();
};

renderer.delete_children = function() {
for (let child of this.node.children) {
child.detach();
}
this.movelist_handler.draw(this.node);
};

renderer.delete_siblings = function() {

if (!this.node.parent) {
return;
}

for (let sibling of this.node.parent.children) {
if (sibling !== this.node) {
sibling.detach();
}
}

this.movelist_handler.draw(this.node);
};

renderer.load_fen = function(s) {

if (s.trim() === this.node.get_board().fen()) {
Expand Down
16 changes: 14 additions & 2 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -300,10 +300,22 @@ function menu_build() {
type: "separator"
},
{
label: "Delete move",
label: "Delete node",
accelerator: "CommandOrControl+Backspace",
click: () => {
win.webContents.send("call", "delete_move");
win.webContents.send("call", "delete_node");
}
},
{
label: "Delete children",
click: () => {
win.webContents.send("call", "delete_children");
}
},
{
label: "Delete siblings",
click: () => {
win.webContents.send("call", "delete_siblings");
}
},
{
Expand Down

0 comments on commit fd79523

Please sign in to comment.