Merge pull request #178 from cormier/fix-74

Fix nick completion issues
This commit is contained in:
David Cormier 2014-02-24 12:20:05 -05:00
commit f3f5330aed
2 changed files with 21 additions and 8 deletions

View file

@ -1,6 +1,6 @@
<form class="form form-horizontal" ng-submit="sendMessage()"> <form class="form form-horizontal" ng-submit="sendMessage()">
<div class="input-group"> <div class="input-group">
<input id="sendMessage" type="text" class="form-control monospace" autocomplete="off" ng-model="command"> <input type="text" class="form-control monospace" autocomplete="off" >
<span class="input-group-btn"> <span class="input-group-btn">
<button class="btn btn-default btn-primary">Send</button> <button class="btn btn-default btn-primary">Send</button>
</span> </span>

View file

@ -1009,6 +1009,7 @@ weechat.directive('inputBar', function() {
templateUrl: 'directives/input.html', templateUrl: 'directives/input.html',
controller: function($rootScope, controller: function($rootScope,
$scope, $scope,
$element,
connection, connection,
models) { models) {
@ -1019,9 +1020,17 @@ weechat.directive('inputBar', function() {
} }
}); });
/*
* Returns the input element
*/
$scope.getInputNode = function() {
return $element.find('input')[0];
};
$scope.completeNick = function() { $scope.completeNick = function() {
// input DOM node // input DOM node
var inputNode = document.getElementById('sendMessage'); var inputNode = $scope.getInputNode();
// get current input // get current input
var inputText = inputNode.value; var inputText = inputNode.value;
@ -1040,7 +1049,7 @@ weechat.directive('inputBar', function() {
$scope.iterCandidate = nickComp.iterCandidate; $scope.iterCandidate = nickComp.iterCandidate;
// update current input // update current input
$scope.command = nickComp.text; inputNode.value = nickComp.text;
// update current caret position // update current caret position
inputNode.focus(); inputNode.focus();
@ -1050,8 +1059,11 @@ weechat.directive('inputBar', function() {
// Send the message to the websocket // Send the message to the websocket
$scope.sendMessage = function() { $scope.sendMessage = function() {
connection.sendMessage($scope.command);
$scope.command = models.getActiveBuffer().addToHistory($scope.command); // log to buffer history var input = $scope.getInputNode();
connection.sendMessage(input.value);
models.getActiveBuffer().addToHistory(input.value); // log to buffer history
input.value = '';
}; };
// Handle key presses in the input bar // Handle key presses in the input bar
@ -1061,6 +1073,8 @@ weechat.directive('inputBar', function() {
return true; return true;
} }
var inputNode = $scope.getInputNode();
// Support different browser quirks // Support different browser quirks
var code = $event.keyCode ? $event.keyCode : $event.charCode; var code = $event.keyCode ? $event.keyCode : $event.charCode;
@ -1107,7 +1121,6 @@ weechat.directive('inputBar', function() {
// Alt+L -> focus on input bar // Alt+L -> focus on input bar
if ($event.altKey && (code === 76 || code === 108)) { if ($event.altKey && (code === 76 || code === 108)) {
$event.preventDefault(); $event.preventDefault();
var inputNode = document.getElementById('sendMessage');
inputNode.focus(); inputNode.focus();
inputNode.setSelectionRange(inputNode.value.length, inputNode.value.length); inputNode.setSelectionRange(inputNode.value.length, inputNode.value.length);
return true; return true;
@ -1139,13 +1152,13 @@ weechat.directive('inputBar', function() {
// Arrow up -> go up in history // Arrow up -> go up in history
if (code === 38) { if (code === 38) {
$scope.command = models.getActiveBuffer().getHistoryUp($scope.command); inputNode.value = models.getActiveBuffer().getHistoryUp(inputNode.value);
return true; return true;
} }
// Arrow down -> go down in history // Arrow down -> go down in history
if (code === 40) { if (code === 40) {
$scope.command = models.getActiveBuffer().getHistoryDown($scope.command); inputNode.value = models.getActiveBuffer().getHistoryDown(inputNode.value);
return true; return true;
} }
}; };