Skip to content

Commit ce99ee4

Browse files
committed
firebase finishing touches
1 parent e322e2a commit ce99ee4

File tree

3 files changed

+58
-2
lines changed

3 files changed

+58
-2
lines changed

my-mind.js

+29-1
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,6 @@ MM.Item.prototype.mergeWith = function(data) {
428428
var s = (this._autoShape ? null : this._shape.id);
429429
if (s != data.shape) { this.setShape(MM.Shape.getById(data.shape)); }
430430

431-
/* FIXME children - co kdyz je nekdo z nas zrovna aktivni, nerkuli editovatelny? */
432431
(data.children || []).forEach(function(child, index) {
433432
if (index >= this._children.length) { /* new child */
434433
this.insertChild(MM.Item.fromJSON(child));
@@ -890,7 +889,36 @@ MM.Map.prototype.fromJSON = function(data) {
890889
}
891890

892891
MM.Map.prototype.mergeWith = function(data) {
892+
/* store a sequence of nodes to be selected when merge is over */
893+
var ids = [];
894+
var current = MM.App.current;
895+
while (current != this) {
896+
ids.push(current.getId());
897+
current = current.getParent();
898+
}
899+
893900
this._root.mergeWith(data.root);
901+
902+
if (MM.App.current.getMap()) { return; } /* selected node still in tree, cool */
903+
904+
/* FIXME what if the current node was being edited? */
905+
906+
/* get all items by their id */
907+
var idMap = {};
908+
var scan = function(item) {
909+
idMap[item.getId()] = item;
910+
item.getChildren().forEach(scan);
911+
}
912+
scan(this._root);
913+
914+
/* select the nearest existing parent */
915+
while (ids.length) {
916+
var id = ids.shift();
917+
if (id in idMap) {
918+
MM.App.select(idMap[id]);
919+
return;
920+
}
921+
}
894922
}
895923

896924
MM.Map.prototype.isVisible = function() {

src/item.js

-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,6 @@ MM.Item.prototype.mergeWith = function(data) {
139139
var s = (this._autoShape ? null : this._shape.id);
140140
if (s != data.shape) { this.setShape(MM.Shape.getById(data.shape)); }
141141

142-
/* FIXME children - co kdyz je nekdo z nas zrovna aktivni, nerkuli editovatelny? */
143142
(data.children || []).forEach(function(child, index) {
144143
if (index >= this._children.length) { /* new child */
145144
this.insertChild(MM.Item.fromJSON(child));

src/map.js

+29
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,36 @@ MM.Map.prototype.fromJSON = function(data) {
2828
}
2929

3030
MM.Map.prototype.mergeWith = function(data) {
31+
/* store a sequence of nodes to be selected when merge is over */
32+
var ids = [];
33+
var current = MM.App.current;
34+
while (current != this) {
35+
ids.push(current.getId());
36+
current = current.getParent();
37+
}
38+
3139
this._root.mergeWith(data.root);
40+
41+
if (MM.App.current.getMap()) { return; } /* selected node still in tree, cool */
42+
43+
/* FIXME what if the current node was being edited? */
44+
45+
/* get all items by their id */
46+
var idMap = {};
47+
var scan = function(item) {
48+
idMap[item.getId()] = item;
49+
item.getChildren().forEach(scan);
50+
}
51+
scan(this._root);
52+
53+
/* select the nearest existing parent */
54+
while (ids.length) {
55+
var id = ids.shift();
56+
if (id in idMap) {
57+
MM.App.select(idMap[id]);
58+
return;
59+
}
60+
}
3261
}
3362

3463
MM.Map.prototype.isVisible = function() {

0 commit comments

Comments
 (0)