Support custom suffix for nick completion

This commit is contained in:
Philippe Proulx 2013-10-27 03:01:19 -04:00
parent ca47fba200
commit 5f2a4386f7
2 changed files with 9 additions and 5 deletions

View file

@ -70,14 +70,18 @@ var IrcUtils = {
* @param caretPos Current caret position (0 means before the first character) * @param caretPos Current caret position (0 means before the first character)
* @param iterCandidate Current iteration candidate (null if not iterating) * @param iterCandidate Current iteration candidate (null if not iterating)
* @param nickList Array of current nicks sorted alphabetically * @param nickList Array of current nicks sorted alphabetically
* @param suf Custom suffix (at least one character, escaped for regex)
* @return Object with following properties: * @return Object with following properties:
* text: new complete replacement text * text: new complete replacement text
* caretPos: new caret position within new text * caretPos: new caret position within new text
* foundNick: completed nick (or null if not possible) * foundNick: completed nick (or null if not possible)
* iterCandidate: current iterating candidate * iterCandidate: current iterating candidate
*/ */
completeNick: function(text, caretPos, iterCandidate, nickList) { completeNick: function(text, caretPos, iterCandidate, nickList, suf) {
var doIterate = (iterCandidate !== null); var doIterate = (iterCandidate !== null);
if (suf === null) {
suf = ':';
}
// text before and after caret // text before and after caret
var beforeCaret = text.substring(0, caretPos); var beforeCaret = text.substring(0, caretPos);
@ -92,12 +96,12 @@ var IrcUtils = {
}; };
// iterating nicks at the beginning? // iterating nicks at the beginning?
var m = beforeCaret.match(/^([a-zA-Z0-9_\\\[\]{}^`|-]+): $/); var m = beforeCaret.match(new RegExp('^([a-zA-Z0-9_\\\\\\[\\]{}^`|-]+)' + suf + ' $'));
if (m) { if (m) {
if (doIterate) { if (doIterate) {
// try iterating // try iterating
var newNick = IrcUtils._nextNick(iterCandidate, m[1], nickList); var newNick = IrcUtils._nextNick(iterCandidate, m[1], nickList);
beforeCaret = newNick + ': '; beforeCaret = newNick + suf + ' ';
return { return {
text: beforeCaret + afterCaret, text: beforeCaret + afterCaret,
caretPos: beforeCaret.length, caretPos: beforeCaret.length,
@ -119,7 +123,7 @@ var IrcUtils = {
// no match // no match
return ret; return ret;
} }
beforeCaret = newNick + ': '; beforeCaret = newNick + suf + ' ';
if (afterCaret[0] == ' ') { if (afterCaret[0] == ' ') {
// swallow first space after caret if any // swallow first space after caret if any
afterCaret = afterCaret.substring(1); afterCaret = afterCaret.substring(1);

View file

@ -595,7 +595,7 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout',
// complete nick // complete nick
var nickComp = IrcUtils.completeNick(inputText, caretPos, var nickComp = IrcUtils.completeNick(inputText, caretPos,
$rootScope.iterCandidate, flatNickList); $rootScope.iterCandidate, flatNickList, ':');
// remember iteration candidate // remember iteration candidate
$rootScope.iterCandidate = nickComp.iterCandidate; $rootScope.iterCandidate = nickComp.iterCandidate;