keyHandler for buffer searching

This commit is contained in:
Tor Hveem 2013-10-17 13:13:01 +02:00
parent 2bd438f6a7
commit f4b5cdfbc9
2 changed files with 16 additions and 2 deletions

View file

@ -170,10 +170,10 @@
<ul class="nav nav-pills nav-stacked">
<li class="bufferfilter">
<form role="form">
<input class="form-control" type="text" id="bufferFilter" ng-model="search" placeholder="Search">
<input class="form-control" type="text" id="bufferFilter" ng-model="search" ng-keydown="handleSearchBoxKey($event)" placeholder="Search">
</form>
</li>
<li class="" ng-class="{'active': content.active }" ng-repeat="(key, content) in buffers | toArray | filter:{fullName:search} | filter:hasUnread | orderBy:'content.number':true">
<li class="buffer" ng-class="{'active': content.active }" ng-repeat="(key, content) in buffers | toArray | filter:{fullName:search} | filter:hasUnread | orderBy:'content.number':true">
<a href="#" ng-click="setActiveBuffer(content.id)" title="{{ content.fullName }}">
<span class="badge pull-right" ng-hide="content.notification" ng-if="content.unread" ng-bind="content.unread"></span>
<span class="badge pull-right danger" ng-show="content.notification" ng-bind="content.notification"></span>

View file

@ -449,6 +449,20 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout',
return true;
}
};
$scope.handleSearchBoxKey = function($event) {
// Support different browser quirks
var code = $event.keyCode ? $event.keyCode : $event.charCode;
// Handle escape
if(code == 27) {
$event.preventDefault();
$scope.search = '';
} // Handle enter
else if (code == 13) {
$event.preventDefault();
// TODO Switch to first matching buffer and reset query
$scope.search = '';
}
}
}]
);