diff --git a/webclient/app.css b/webclient/app.css index b49ebef1b..324928c89 100644 --- a/webclient/app.css +++ b/webclient/app.css @@ -62,6 +62,11 @@ h1 { width: 100%; } +.blink { + display: none ! important; + background-color: #faa; +} + /*** Participant list ***/ #usersTableWrapper { @@ -90,6 +95,7 @@ h1 { .userAvatar .userAvatarImage { position: absolute; top: 0px; + object-fit: cover; } .userAvatar .userAvatarGradient { @@ -176,6 +182,10 @@ h1 { vertical-align: top; line-height: 0; } + +.avatarImage { + object-fit: cover; +} .text { background-color: #eee; diff --git a/webclient/room/room-controller.js b/webclient/room/room-controller.js index 86f1379f7..a2032cf57 100644 --- a/webclient/room/room-controller.js +++ b/webclient/room/room-controller.js @@ -16,6 +16,94 @@ limitations under the License. angular.module('RoomController', ['ngSanitize']) +.directive('ngAutoComplete', ['$timeout', function ($timeout) { + return function (scope, element, attrs) { + element.bind("keydown keypress", function (event) { + console.log("event: " + event.which); + if (event.which === 9) { + if (!scope.autoCompleting) { // cache our starting text + console.log("caching " + element[0].value); + scope.autoCompleteOriginal = element[0].value; + scope.autoCompleting = true; + } + + if (event.shiftKey) { + scope.autoCompleteIndex--; + if (scope.autoCompleteIndex < 0) { + scope.autoCompleteIndex = 0; + } + } + else { + scope.autoCompleteIndex++; + } + + var searchIndex = 0; + var targetIndex = scope.autoCompleteIndex; + var text = scope.autoCompleteOriginal; + + console.log("targetIndex: " + targetIndex + ", text=" + text); + + // FIXME: use the correct regexp to recognise userIDs + var search = /@?([a-zA-Z0-9_\-:\.]+)$/.exec(text); + if (targetIndex === 0) { + element[0].value = text; + } + else if (search && search[1]) { + console.log("search found: " + search); + var expansion; + + // FIXME: could do better than linear search here + angular.forEach(scope.members, function(item, name) { + if (item.displayname && searchIndex < targetIndex) { + if (item.displayname.toLowerCase().indexOf(search[1].toLowerCase()) == 0) { + expansion = item.displayname; + searchIndex++; + } + } + }); + if (searchIndex < targetIndex) { // then search raw mxids + angular.forEach(scope.members, function(item, name) { + if (searchIndex < targetIndex) { + if (name.toLowerCase().indexOf(search[1].toLowerCase()) == 1) { + expansion = name; + searchIndex++; + } + } + }); + } + + if (searchIndex === targetIndex) { + // xchat-style tab complete + if (search[0].length === text.length) + expansion += " : "; + else + expansion += " "; + element[0].value = text.replace(/@?([a-zA-Z0-9_\-:\.]+)$/, expansion); + // cancel blink + element[0].className = ""; + } + else { + console.log("wrapped!"); + element[0].className = "blink"; // XXX: slightly naughty to bypass angular + $timeout(function() { + element[0].className = ""; + }, 150); + element[0].value = text; + scope.autoCompleteIndex = 0; + } + } + else { + scope.autoCompleteIndex = 0; + } + event.preventDefault(); + } + else if (event.which != 16 && scope.autoCompleting) { + scope.autoCompleting = false; + scope.autoCompleteIndex = 0; + } + }); + }; +}]) .controller('RoomController', ['$scope', '$http', '$timeout', '$routeParams', '$location', 'matrixService', 'eventStreamService', 'eventHandlerService', function($scope, $http, $timeout, $routeParams, $location, matrixService, eventStreamService, eventHandlerService) { 'use strict'; @@ -31,6 +119,9 @@ angular.module('RoomController', ['ngSanitize']) stream_failure: undefined // the response when the stream fails }; $scope.members = {}; + $scope.autoCompleting = false; + $scope.autoCompleteIndex = 0; + $scope.autoCompleteOriginal = ""; $scope.imageURLToSend = ""; $scope.userIDToInvite = ""; diff --git a/webclient/room/room.html b/webclient/room/room.html index 2726188b4..f965d13c5 100644 --- a/webclient/room/room.html +++ b/webclient/room/room.html @@ -16,7 +16,7 @@