Use recent speaker instead of alphabetical nick tab complete
Use _ for sorting. Fix jshint problems and naming things. Fix comments
This commit is contained in:
parent
253e2ffc60
commit
4e08a52f25
3 changed files with 84 additions and 20 deletions
|
@ -666,6 +666,18 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout',
|
||||||
$scope.bufferlines = ab.lines;
|
$scope.bufferlines = ab.lines;
|
||||||
$scope.nicklist = ab.nicklist;
|
$scope.nicklist = ab.nicklist;
|
||||||
|
|
||||||
|
// Send a request for the nicklist if it hasn't been loaded yet
|
||||||
|
if (!ab.nicklistRequested()) {
|
||||||
|
connection.requestNicklist(ab.fullName, function() {
|
||||||
|
$scope.showNicklist = $scope.updateShowNicklist();
|
||||||
|
// Scroll after nicklist has been loaded, as it may break long lines
|
||||||
|
$rootScope.scrollWithBuffer(true);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
// Check if we should show nicklist or not
|
||||||
|
$scope.showNicklist = $scope.updateShowNicklist();
|
||||||
|
}
|
||||||
|
|
||||||
if (ab.requestedLines < $scope.lines) {
|
if (ab.requestedLines < $scope.lines) {
|
||||||
// buffer has not been loaded, but some lines may already be present if they arrived after we connected
|
// buffer has not been loaded, but some lines may already be present if they arrived after we connected
|
||||||
// try to determine how many lines to fetch
|
// try to determine how many lines to fetch
|
||||||
|
@ -679,18 +691,6 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout',
|
||||||
}
|
}
|
||||||
$rootScope.updateTitle(ab);
|
$rootScope.updateTitle(ab);
|
||||||
|
|
||||||
// Send a request for the nicklist if it hasn't been loaded yet
|
|
||||||
if (!ab.nicklistRequested()) {
|
|
||||||
connection.requestNicklist(ab.fullName, function() {
|
|
||||||
$scope.showNicklist = $scope.updateShowNicklist();
|
|
||||||
// Scroll after nicklist has been loaded, as it may break long lines
|
|
||||||
$rootScope.scrollWithBuffer(true);
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
// Check if we should show nicklist or not
|
|
||||||
$scope.showNicklist = $scope.updateShowNicklist();
|
|
||||||
}
|
|
||||||
|
|
||||||
$rootScope.scrollWithBuffer(true);
|
$rootScope.scrollWithBuffer(true);
|
||||||
|
|
||||||
// If user wants to sync hotlist with weechat
|
// If user wants to sync hotlist with weechat
|
||||||
|
@ -1235,7 +1235,7 @@ weechat.directive('inputBar', function() {
|
||||||
|
|
||||||
// complete nick
|
// complete nick
|
||||||
var nickComp = IrcUtils.completeNick(inputText, caretPos,
|
var nickComp = IrcUtils.completeNick(inputText, caretPos,
|
||||||
$scope.iterCandidate, activeBuffer.flatNicklist(), ':');
|
$scope.iterCandidate, activeBuffer.getNicklistByTime(), ':');
|
||||||
|
|
||||||
// remember iteration candidate
|
// remember iteration candidate
|
||||||
$scope.iterCandidate = nickComp.iterCandidate;
|
$scope.iterCandidate = nickComp.iterCandidate;
|
||||||
|
|
|
@ -21,6 +21,21 @@ var IrcUtils = {
|
||||||
|
|
||||||
return newList;
|
return newList;
|
||||||
},
|
},
|
||||||
|
/**
|
||||||
|
* Get a new version of a nick list, sorted by last speaker
|
||||||
|
*
|
||||||
|
* @param nickList Original nick list
|
||||||
|
* @return Sorted nick list
|
||||||
|
*/
|
||||||
|
_ciNickList: function(nickList) {
|
||||||
|
|
||||||
|
var newList = _(nickList).sortBy(function(nickObj) {
|
||||||
|
return -nickObj.spokeAt;
|
||||||
|
});
|
||||||
|
newList = _(newList).pluck('name');
|
||||||
|
|
||||||
|
return newList;
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Completes a single nick.
|
* Completes a single nick.
|
||||||
|
@ -66,10 +81,13 @@ var IrcUtils = {
|
||||||
if (lcCurrentNick === lcNick) {
|
if (lcCurrentNick === lcNick) {
|
||||||
at = matchingNicks.length - 1;
|
at = matchingNicks.length - 1;
|
||||||
}
|
}
|
||||||
} else if (matchingNicks.length > 0) {
|
}
|
||||||
|
/* Since we aren't sorted any more torhve disabled this:
|
||||||
|
else if (matchingNicks.length > 0) {
|
||||||
// end of group, no need to check after this
|
// end of group, no need to check after this
|
||||||
break;
|
//break;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
if (at === null || matchingNicks.length === 0) {
|
if (at === null || matchingNicks.length === 0) {
|
||||||
|
@ -105,7 +123,7 @@ var IrcUtils = {
|
||||||
}
|
}
|
||||||
|
|
||||||
// new nick list to search in
|
// new nick list to search in
|
||||||
var searchNickList = IrcUtils._ciSearchNickList(nickList);
|
var searchNickList = IrcUtils._ciNickList(nickList);
|
||||||
|
|
||||||
// text before and after caret
|
// text before and after caret
|
||||||
var beforeCaret = text.substring(0, caretPos);
|
var beforeCaret = text.substring(0, caretPos);
|
||||||
|
|
54
js/models.js
54
js/models.js
|
@ -43,6 +43,7 @@ models.service('models', ['$rootScope', '$filter', function($rootScope, $filter)
|
||||||
*/
|
*/
|
||||||
var addLine = function(line) {
|
var addLine = function(line) {
|
||||||
lines.push(line);
|
lines.push(line);
|
||||||
|
updateNickSpeak(line);
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -50,6 +51,7 @@ models.service('models', ['$rootScope', '$filter', function($rootScope, $filter)
|
||||||
*/
|
*/
|
||||||
var addNick = function(group, nick) {
|
var addNick = function(group, nick) {
|
||||||
if (nicklistRequested()) {
|
if (nicklistRequested()) {
|
||||||
|
nick.spokeAt = Date.now();
|
||||||
nicklist[group].nicks.push(nick);
|
nicklist[group].nicks.push(nick);
|
||||||
flatnicklist = getFlatNicklist();
|
flatnicklist = getFlatNicklist();
|
||||||
}
|
}
|
||||||
|
@ -88,9 +90,55 @@ models.service('models', ['$rootScope', '$filter', function($rootScope, $filter)
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Maintain a cached version of a flat sorted nicklist
|
* Update a nick with a fresh timestamp so tab completion
|
||||||
|
* can use time to complete recent speakers
|
||||||
|
*/
|
||||||
|
var updateNickSpeak = function(line) {
|
||||||
|
// Try to find nick from prefix
|
||||||
|
var prefix = line.prefix;
|
||||||
|
var nick = prefix[prefix.length - 1].text;
|
||||||
|
// Action / me, find the nick as the first word of the message
|
||||||
|
if (nick === " *") {
|
||||||
|
var match = line.text.match(/^(.+)\s/);
|
||||||
|
if (match) {
|
||||||
|
nick = match[1];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (nick === "" || nick === "=!=") {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_.each(nicklist, function(nickGroup) {
|
||||||
|
_.each(nickGroup.nicks, function(nickObj) {
|
||||||
|
if (nickObj.name === nick) {
|
||||||
|
// Use the order the line arrive in for simplicity
|
||||||
|
// instead of using weechat's own timestamp
|
||||||
|
nickObj.spokeAt = Date.now();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
flatnicklist = getFlatNicklist();
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Get a flat nicklist sorted by speaker time. This function is
|
||||||
|
* called for every tab key press by the user.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
var getNicklistByTime = function() {
|
||||||
|
var newlist = [];
|
||||||
|
_.each(nicklist, function(nickGroup) {
|
||||||
|
_.each(nickGroup.nicks, function(nickObj) {
|
||||||
|
newlist.push(nickObj);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
newlist.sort(function(a, b) {
|
||||||
|
return a.spokeAt < b.spokeAt;
|
||||||
|
});
|
||||||
|
|
||||||
|
return newlist;
|
||||||
|
};
|
||||||
|
|
||||||
var getFlatNicklist = function() {
|
var getFlatNicklist = function() {
|
||||||
var newlist = [];
|
var newlist = [];
|
||||||
_.each(nicklist, function(nickGroup) {
|
_.each(nicklist, function(nickGroup) {
|
||||||
|
@ -98,9 +146,6 @@ models.service('models', ['$rootScope', '$filter', function($rootScope, $filter)
|
||||||
newlist.push(nickObj.name);
|
newlist.push(nickObj.name);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
newlist.sort(function(a, b) {
|
|
||||||
return a.toLowerCase() < b.toLowerCase() ? -1 : 1;
|
|
||||||
});
|
|
||||||
return newlist;
|
return newlist;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -190,6 +235,7 @@ models.service('models', ['$rootScope', '$filter', function($rootScope, $filter)
|
||||||
delNick: delNick,
|
delNick: delNick,
|
||||||
updateNick: updateNick,
|
updateNick: updateNick,
|
||||||
flatNicklist: flatNicklist,
|
flatNicklist: flatNicklist,
|
||||||
|
getNicklistByTime: getNicklistByTime,
|
||||||
serverSortKey: serverSortKey,
|
serverSortKey: serverSortKey,
|
||||||
indent: indent,
|
indent: indent,
|
||||||
history: history,
|
history: history,
|
||||||
|
|
Loading…
Reference in a new issue