[polari] tabCompletion: Support chaining of completions
- From: Florian Müllner <fmuellner src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [polari] tabCompletion: Support chaining of completions
- Date: Tue, 15 Oct 2013 20:49:47 +0000 (UTC)
commit cb770f2f4e3f254829109125dd0f47dccc232c2b
Author: Florian Müllner <fmuellner gnome org>
Date: Tue Oct 15 22:24:00 2013 +0200
tabCompletion: Support chaining of completions
We now insert a colon automatically when completing at the start of
a line. Extend this behavior to completions that follow immediately
on a previous completion, changing "old" colons to commata on the way.
src/tabCompletion.js | 23 ++++++++++++++++++++---
1 files changed, 20 insertions(+), 3 deletions(-)
---
diff --git a/src/tabCompletion.js b/src/tabCompletion.js
index 0b7af57..f568f77 100644
--- a/src/tabCompletion.js
+++ b/src/tabCompletion.js
@@ -114,8 +114,9 @@ const TabCompletion = new Lang.Class({
},
_getRowCompletion: function(row) {
- return this._startPos == 0 ? row._text + ': '
- : row._text;
+ if (this._startPos == 0 || this._previousCompletion)
+ return row._text + ': ';
+ return row._text;
},
_onRowSelected: function(w, row) {
@@ -131,9 +132,17 @@ const TabCompletion = new Lang.Class({
_insertCompletion: function(completion) {
let pos = this._entry.get_position();
+ this._endPos = this._startPos + completion.length;
this._entry.delete_text(this._startPos, pos);
this._entry.insert_text(completion, -1, this._startPos);
- this._entry.set_position(this._startPos + completion.length);
+ this._entry.set_position(this._endPos);
+ },
+
+ _setPreviousCompletionChained: function(chained) {
+ let repl = chained ? ',' : ':';
+ let start = this._startPos - 2;
+ this._entry.delete_text(start, start + 1);
+ this._entry.insert_text(repl, -1, start);
},
_start: function() {
@@ -144,6 +153,10 @@ const TabCompletion = new Lang.Class({
this._startPos = text.lastIndexOf(' ') + 1;
this._key = text.toLowerCase().substr(this._startPos);
+ if (this._startPos == 0)
+ this._endPos = -1;
+ this._previousCompletion = (this._endPos == this._startPos);
+
this._list.invalidate_filter();
let visibleRows = this._list.get_children().filter(function(c) {
@@ -154,6 +167,8 @@ const TabCompletion = new Lang.Class({
if (nVisibleRows == 0)
return;
+ if (this._previousCompletion)
+ this._setPreviousCompletionChained(true);
this._insertCompletion(this._getRowCompletion(visibleRows[0]));
if (visibleRows.length > 1) {
this._list.select_row(visibleRows[0]);
@@ -192,6 +207,8 @@ const TabCompletion = new Lang.Class({
_cancel: function() {
if (this._key.length == 0)
return;
+ if (this._previousCompletion)
+ this._setPreviousCompletionChained(false);
this._insertCompletion('');
this._stop();
},
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]