Merge pull request #229 from matrix-org/matthew/fix-zero-length-tab-complete
fix zero length tab complete so it doesn't fire automatically on empty MessageComposer
This commit is contained in:
commit
3caa8f19c1
1 changed files with 32 additions and 30 deletions
|
@ -83,10 +83,39 @@ class TabComplete {
|
||||||
this._notifyStateChange();
|
this._notifyStateChange();
|
||||||
}
|
}
|
||||||
|
|
||||||
startTabCompleting() {
|
startTabCompleting(passive) {
|
||||||
|
this.originalText = this.textArea.value; // cache starting text
|
||||||
|
|
||||||
|
// grab the partial word from the text which we'll be tab-completing
|
||||||
|
var res = MATCH_REGEX.exec(this.originalText);
|
||||||
|
if (!res) {
|
||||||
|
this.matchedList = [];
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// ES6 destructuring; ignore first element (the complete match)
|
||||||
|
var [ , boundaryGroup, partialGroup] = res;
|
||||||
|
|
||||||
|
if (partialGroup.length === 0 && passive) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.isFirstWord = partialGroup.length === this.originalText.length;
|
||||||
|
|
||||||
this.completing = true;
|
this.completing = true;
|
||||||
this.currentIndex = 0;
|
this.currentIndex = 0;
|
||||||
this._calculateCompletions();
|
|
||||||
|
this.matchedList = [
|
||||||
|
new Entry(partialGroup) // first entry is always the original partial
|
||||||
|
];
|
||||||
|
|
||||||
|
// find matching entries in the set of entries given to us
|
||||||
|
this.list.forEach((entry) => {
|
||||||
|
if (entry.text.toLowerCase().indexOf(partialGroup.toLowerCase()) === 0) {
|
||||||
|
this.matchedList.push(entry);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// console.log("calculated completions => %s", JSON.stringify(this.matchedList));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -137,7 +166,7 @@ class TabComplete {
|
||||||
this.inPassiveMode = passive;
|
this.inPassiveMode = passive;
|
||||||
|
|
||||||
if (!this.completing) {
|
if (!this.completing) {
|
||||||
this.startTabCompleting();
|
this.startTabCompleting(passive);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (shiftKey) {
|
if (shiftKey) {
|
||||||
|
@ -270,33 +299,6 @@ class TabComplete {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
_calculateCompletions() {
|
|
||||||
this.originalText = this.textArea.value; // cache starting text
|
|
||||||
|
|
||||||
// grab the partial word from the text which we'll be tab-completing
|
|
||||||
var res = MATCH_REGEX.exec(this.originalText);
|
|
||||||
if (!res) {
|
|
||||||
this.matchedList = [];
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// ES6 destructuring; ignore first element (the complete match)
|
|
||||||
var [ , boundaryGroup, partialGroup] = res;
|
|
||||||
this.isFirstWord = partialGroup.length === this.originalText.length;
|
|
||||||
|
|
||||||
this.matchedList = [
|
|
||||||
new Entry(partialGroup) // first entry is always the original partial
|
|
||||||
];
|
|
||||||
|
|
||||||
// find matching entries in the set of entries given to us
|
|
||||||
this.list.forEach((entry) => {
|
|
||||||
if (entry.text.toLowerCase().indexOf(partialGroup.toLowerCase()) === 0) {
|
|
||||||
this.matchedList.push(entry);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// console.log("_calculateCompletions => %s", JSON.stringify(this.matchedList));
|
|
||||||
}
|
|
||||||
|
|
||||||
_notifyStateChange() {
|
_notifyStateChange() {
|
||||||
if (this.opts.onStateChange) {
|
if (this.opts.onStateChange) {
|
||||||
this.opts.onStateChange(this.completing);
|
this.opts.onStateChange(this.completing);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue