add toggle functionality to ac
This commit is contained in:
parent
2617925cd8
commit
41a5a3a791
|
@ -63,4 +63,10 @@ export default new class EmoteAc extends BuiltinModule {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
toggle(sterm) {
|
||||||
|
if (sterm.length > 1) return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,6 +44,11 @@ export default new class AutoComplete {
|
||||||
return this.sets.hasOwnProperty(prefix);
|
return this.sets.hasOwnProperty(prefix);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
toggle(prefix, sterm) {
|
||||||
|
if (!this.sets[prefix].toggle) return false;
|
||||||
|
return this.sets[prefix].toggle(sterm);
|
||||||
|
}
|
||||||
|
|
||||||
items(prefix, sterm) {
|
items(prefix, sterm) {
|
||||||
if (!this.validPrefix(prefix)) return [];
|
if (!this.validPrefix(prefix)) return [];
|
||||||
return this.sets[prefix].acsearch(sterm);
|
return this.sets[prefix].acsearch(sterm);
|
||||||
|
|
|
@ -66,7 +66,9 @@
|
||||||
const { which, key } = e;
|
const { which, key } = e;
|
||||||
|
|
||||||
if (key === 'ArrowDown' || key === 'ArrowUp') this.traverse(key);
|
if (key === 'ArrowDown' || key === 'ArrowUp') this.traverse(key);
|
||||||
else if (key !== 'Tab' && key !== 'Enter') return;
|
else if (key === 'ArrowLeft' || key === 'ArrowRight') {
|
||||||
|
if (!this.toggle(e)) return;
|
||||||
|
} else if (key !== 'Tab' && key !== 'Enter') return;
|
||||||
|
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
@ -119,6 +121,12 @@
|
||||||
this.insertText(this.ta.selectionStart - this.fsterm.length, this.search.items[this.selectedIndex].value.replaceWith);
|
this.insertText(this.ta.selectionStart - this.fsterm.length, this.search.items[this.selectedIndex].value.replaceWith);
|
||||||
this.open = false;
|
this.open = false;
|
||||||
this.search = { type: null, items: [] };
|
this.search = { type: null, items: [] };
|
||||||
|
},
|
||||||
|
toggle(e) {
|
||||||
|
const { selectionEnd, value } = e.target;
|
||||||
|
const sterm = value.slice(0, selectionEnd).split(/\s+/g).pop();
|
||||||
|
const prefix = sterm.slice(0, 1);
|
||||||
|
return this.controller.toggle(prefix, sterm);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue