Parse some of WeeChat's completion settings

weechat.completion.nick_completer and 'weechat.completion.nick_add_space

Fixes #963
This commit is contained in:
Lorenz Hübschle-Schneider 2017-08-20 09:51:48 +02:00
parent d87a2cdfff
commit d4d7a977e1
3 changed files with 16 additions and 6 deletions

View file

@ -214,6 +214,10 @@ weechat.factory('connection',
_parseWeechatTimeFormat(); _parseWeechatTimeFormat();
}); });
// Fetch nick completion config
fetchConfValue('weechat.completion.nick_completer');
fetchConfValue('weechat.completion.nick_add_space');
_requestSync(); _requestSync();
$log.info("Connected to relay"); $log.info("Connected to relay");
$rootScope.connected = true; $rootScope.connected = true;

View file

@ -89,8 +89,11 @@ weechat.directive('inputBar', function() {
var input = $scope.command || ''; var input = $scope.command || '';
// complete nick // complete nick
var completion_suffix = models.wconfig['weechat.completion.nick_completer'];
var add_space = models.wconfig['weechat.completion.nick_add_space'];
var nickComp = IrcUtils.completeNick(input, caretPos, $scope.iterCandidate, var nickComp = IrcUtils.completeNick(input, caretPos, $scope.iterCandidate,
activeBuffer.getNicklistByTime(), ':'); activeBuffer.getNicklistByTime(),
completion_suffix, add_space);
// remember iteration candidate // remember iteration candidate
$scope.iterCandidate = nickComp.iterCandidate; $scope.iterCandidate = nickComp.iterCandidate;

View file

@ -106,17 +106,20 @@ IrcUtils.service('IrcUtils', [function() {
* @param iterCandidate Current iteration candidate (null if not iterating) * @param iterCandidate Current iteration candidate (null if not iterating)
* @param nickList Array of current nicks * @param nickList Array of current nicks
* @param suf Custom suffix (at least one character, escaped for regex) * @param suf Custom suffix (at least one character, escaped for regex)
* @param addSpace Whether to add a space after nick completion in the middle
* @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
*/ */
var completeNick = function(text, caretPos, iterCandidate, nickList, suf) { var completeNick = function(text, caretPos, iterCandidate, nickList, suf, addSpace) {
var doIterate = (iterCandidate !== null); var doIterate = (iterCandidate !== null);
if (suf === null) { if (suf === undefined) {
suf = ':'; suf = ':';
} }
// addSpace defaults to true
var addSpaceChar = (addSpace === undefined || addSpace === true) ? ' ' : '';
// new nick list to search in // new nick list to search in
var searchNickList = _ciNickList(nickList); var searchNickList = _ciNickList(nickList);
@ -182,7 +185,7 @@ IrcUtils.service('IrcUtils', [function() {
if (doIterate) { if (doIterate) {
// try iterating // try iterating
newNick = _nextNick(iterCandidate, m[2], searchNickList); newNick = _nextNick(iterCandidate, m[2], searchNickList);
beforeCaret = m[1] + newNick + ' '; beforeCaret = m[1] + newNick + addSpaceChar;
return { return {
text: beforeCaret + afterCaret, text: beforeCaret + afterCaret,
caretPos: beforeCaret.length, caretPos: beforeCaret.length,
@ -204,7 +207,7 @@ IrcUtils.service('IrcUtils', [function() {
// no match // no match
return ret; return ret;
} }
beforeCaret = m[1] + newNick + ' '; beforeCaret = m[1] + newNick + addSpaceChar;
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);