diff options
author | portix <portix@gmx.net> | 2014-03-10 03:22:03 +0100 |
---|---|---|
committer | portix <portix@gmx.net> | 2014-03-10 03:22:03 +0100 |
commit | 17cfd4dcc35afee0b20ef632660bcfdc45ffec90 (patch) | |
tree | 96975cdb1249eb7b748f2036c74d958290724fce | |
parent | 8d4565114e66900f972e64f3a5131b125449b4fd (diff) | |
download | dwb-17cfd4dcc35afee0b20ef632660bcfdc45ffec90.zip |
completion: simplify updates
-rw-r--r-- | scripts/modules/completion | 59 |
1 files changed, 28 insertions, 31 deletions
diff --git a/scripts/modules/completion b/scripts/modules/completion index 344a27c6..527d57d6 100644 --- a/scripts/modules/completion +++ b/scripts/modules/completion @@ -188,6 +188,7 @@ Object.defineProperties(Completion.prototype, { mWidget.visible = false; this.onHide(); + this._height = 0; this._lastText = ""; this._data = null; util.normalMode(); @@ -205,6 +206,31 @@ Object.defineProperties(Completion.prototype, { } } }, + _doUpdate : { + value : function(data) { + this._data = data; + if (this._data && this._data.length > 0) { + mWidget.inject("update(" + JSON.stringify(this._data) + ")"); + } + else { + mWidget.inject("clear()"); + } + if (!this.height) { + var oldHeight = this._height; + this._height = Math.min(this._data.length, this.visibleItems) * (this.fontSize + this.lineSpacing); + if (this._height == 0) { + mWidget.visible = false; + return; + } + if (oldHeight != this._height) { + mWidget.heightRequest = this._height; + } + if (oldHeight == 0) { + mWidget.visible = true; + } + } + } + }, _onKeyPress : { value : function(w, e) { switch(e.name) { @@ -238,31 +264,7 @@ Object.defineProperties(Completion.prototype, { return; } this._lastText = text; - - this._data = this.onUpdate(text); - - this._updateHeight(); - if (this._data) { - mWidget.inject("update(" + JSON.stringify(this._data) + ")"); - } - } - }, - _updateHeight : { - value : function() { - if (!this.height) { - var oldHeight = this._height; - this._height = Math.min(this._data.length, this.visibleItems) * (this.fontSize + this.lineSpacing); - if (this._height == 0) { - mWidget.visible = false; - return; - } - if (oldHeight == 0) { - mWidget.visible = true; - } - if (oldHeight != this._height) { - mWidget.heightRequest = this._height; - } - } + this._doUpdate(this.onUpdate(text)); } }, _onUpdateLabel : { @@ -285,12 +287,7 @@ Object.defineProperties(Completion.prototype, { this._sigKeyPress.connect(); this._sigKeyRelease.connect(); - this._data = this.onShow(); - this._updateHeight(); - if (this._data) { - mWidget.inject("update(" + JSON.stringify(this._data) + ")"); - } - mWidget.visible = true; + this._doUpdate(this.onShow()); } }, _startup : { |