mirror of
https://github.com/embarklabs/neo-blessed.git
synced 2025-01-26 02:40:23 +00:00
only emit attach if the element was not previously attached.
This commit is contained in:
parent
48c2bae2a0
commit
f03f51267b
@ -57,7 +57,7 @@ Node.prototype.__proto__ = EventEmitter.prototype;
|
||||
Node.prototype.type = 'node';
|
||||
|
||||
Node.prototype.insert = function(element, i) {
|
||||
// var old = element.parent;
|
||||
var old = element.parent;
|
||||
|
||||
element.detach();
|
||||
element.parent = this;
|
||||
@ -79,16 +79,16 @@ Node.prototype.insert = function(element, i) {
|
||||
element.emit('reparent', this);
|
||||
this.emit('adopt', element);
|
||||
|
||||
// if (!old) {
|
||||
(function emit(el) {
|
||||
el._detached = false;
|
||||
el.emit('attach');
|
||||
if (el.children) el.children.forEach(emit);
|
||||
})(element);
|
||||
|
||||
// element.emitDescendants('attach', function(el) {
|
||||
// el._detached = false;
|
||||
// });
|
||||
if (!old) {
|
||||
// element.emitDescendants('attach', function(el) {
|
||||
// el._detached = false;
|
||||
// });
|
||||
(function emit(el) {
|
||||
el._detached = false;
|
||||
el.emit('attach');
|
||||
if (el.children) el.children.forEach(emit);
|
||||
})(element);
|
||||
}
|
||||
};
|
||||
|
||||
Node.prototype.prepend = function(element) {
|
||||
@ -110,6 +110,8 @@ Node.prototype.insertAfter = function(element, other) {
|
||||
};
|
||||
|
||||
Node.prototype.remove = function(element) {
|
||||
if (element.parent !== this) return;
|
||||
|
||||
element.parent = null;
|
||||
|
||||
var i = this.children.indexOf(element);
|
||||
@ -131,22 +133,20 @@ Node.prototype.remove = function(element) {
|
||||
element.emit('reparent', null);
|
||||
this.emit('remove', element);
|
||||
|
||||
// element.emitDescendants('detach', function(el) {
|
||||
// el._detached = true;
|
||||
// });
|
||||
(function emit(el) {
|
||||
el._detached = true;
|
||||
el.emit('detach');
|
||||
if (el.children) el.children.forEach(emit);
|
||||
})(element);
|
||||
|
||||
// element.emitDescendants('detach', function(el) {
|
||||
// el._detached = true;
|
||||
// });
|
||||
|
||||
// this.clearPos();
|
||||
};
|
||||
|
||||
Node.prototype.detach = function() {
|
||||
if (this.parent) this.parent.remove(this);
|
||||
// this.clearPos();
|
||||
return this.parent.remove(this);
|
||||
};
|
||||
|
||||
Node.prototype.emitDescendants = function() {
|
||||
@ -406,7 +406,6 @@ Screen.prototype._listenMouse = function(el) {
|
||||
// if (self.grabKeys && self.focused !== el
|
||||
// && !el.hasAncestor(self.focused)) continue;
|
||||
|
||||
// Get the true coordinates.
|
||||
ret = el.lpos;
|
||||
if (!ret) continue;
|
||||
left = ret.xi;
|
||||
|
Loading…
x
Reference in New Issue
Block a user