Fix autocompleting multiple times not working

This commit is contained in:
Pavel Djundik 2018-07-17 11:21:08 +03:00 committed by Pavel Djundik
parent 1bfaef1985
commit 0e7880a049
2 changed files with 13 additions and 6 deletions

View File

@ -174,19 +174,24 @@ const backgroundColorStrategy = {
function enableAutocomplete(inputRef) { function enableAutocomplete(inputRef) {
enabled = true; enabled = true;
let autocompleting = false;
let tabCount = 0; let tabCount = 0;
let lastMatch = ""; let lastMatch = "";
let currentMatches = []; let currentMatches = [];
input = $(inputRef); input = $(inputRef);
input.on("input.tabcomplete", () => { input.on("input.tabcomplete", (e) => {
if (e.detail === "autocomplete") {
return;
}
tabCount = 0; tabCount = 0;
currentMatches = []; currentMatches = [];
lastMatch = ""; lastMatch = "";
}); });
Mousetrap(input.get(0)).bind("tab", (e) => { Mousetrap(input.get(0)).bind("tab", (e) => {
if (input.data("autocompleting")) { if (autocompleting) {
return; return;
} }
@ -218,7 +223,9 @@ function enableAutocomplete(inputRef) {
input.val(text.substr(0, position) + newMatch); input.val(text.substr(0, position) + newMatch);
// Propagate change to Vue model // Propagate change to Vue model
input.get(0).dispatchEvent(new Event("input")); input.get(0).dispatchEvent(new CustomEvent("input", {
detail: "autocomplete",
}));
lastMatch = newMatch; lastMatch = newMatch;
tabCount++; tabCount++;
@ -250,11 +257,11 @@ function enableAutocomplete(inputRef) {
}); });
textcomplete.on("show", () => { textcomplete.on("show", () => {
input.data("autocompleting", true); autocompleting = true;
}); });
textcomplete.on("hidden", () => { textcomplete.on("hidden", () => {
input.data("autocompleting", false); autocompleting = false;
}); });
} }

View File

@ -13,7 +13,7 @@ const {vueApp} = require("../vue");
socket.on("init", function(data) { socket.on("init", function(data) {
$("#loading-page-message, #connection-error").text("Rendering…"); $("#loading-page-message, #connection-error").text("Rendering…");
let previousActive = vueApp.activeChannel && vueApp.activeChannel.channel.id; const previousActive = vueApp.activeChannel && vueApp.activeChannel.channel.id;
const networks = new Set(JSON.parse(storage.get("thelounge.networks.collapsed"))); const networks = new Set(JSON.parse(storage.get("thelounge.networks.collapsed")));