Browse Source

tab autocomplete for popup emoticons

Andrew Dolgov 1 year ago
parent
commit
f1b9cd49c3
1 changed files with 24 additions and 1 deletions
  1. 24 1
      js/tt-irc.js

+ 24 - 1
js/tt-irc.js

@@ -6,6 +6,8 @@ var new_highlights = 0;
 var delay = 1500;
 var last_update = false;
 var input_cache = [];
+var input_autocomplete = [];
+var input_autocomplete_index = 0;
 var highlight_on = [];
 var notify_events = [];
 var update_delay_max = 0;
@@ -861,10 +863,27 @@ function init_second_stage(params) {
 				}
 			}
 
+			if (e.keyCode == 9 && input_autocomplete.length > 0) {
+
+				if (input_autocomplete_index > input_autocomplete.length - 1)
+					input_autocomplete_index = 0;
+
+				var v = elem.val();
+
+				var tmp = v.split(" ");
+				var query = tmp[tmp.length-1];
+
+				v = v.substring(0, v.lastIndexOf(query)) + input_autocomplete[input_autocomplete_index];
+				elem.val(v);
+
+				++input_autocomplete_index;
+			}
+
 			return hotkey_handler(e);
 		})
 		.on('keyup', function(e) {
-			update_emoticon_popup($(this).val());
+			if (e.keyCode != 9)
+				update_emoticon_popup($(this).val());
 		})
 		.on('keypress', function(e) {
 			return send(e);
@@ -2581,6 +2600,8 @@ function update_emoticon_popup(str) {
 	var tmp = str.split(" ");
 	var query = tmp[tmp.length-1];
 
+	input_autocomplete = [];
+
 	if (query && query.length > 2 && query[0] == ":") {
 		//$(".emoticons-popup").html(word).show();
 
@@ -2593,6 +2614,8 @@ function update_emoticon_popup(str) {
 			if (k.indexOf(query) == 0) {
 				++found;
 
+				input_autocomplete.push(k);
+
 				var li = $("<li>")
 					.on("click", function() {
 						var emot_name = $(this).find("span").html();