diff --git a/javascript/_utils.js b/javascript/_utils.js
index 863b4d3..0804f5e 100644
--- a/javascript/_utils.js
+++ b/javascript/_utils.js
@@ -89,6 +89,14 @@ function difference(a, b) {
)].reduce((acc, [v, count]) => acc.concat(Array(Math.abs(count)).fill(v)), []);
}
+// Sliding window function to get possible combination groups of an array
+function toWindows(inputArray, size) {
+ return Array.from(
+ {length: inputArray.length - (size - 1)}, //get the appropriate length
+ (_, index) => inputArray.slice(index, index+size) //create the windows
+ )
+ }
+
function escapeRegExp(string) {
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string
}
diff --git a/javascript/tagAutocomplete.js b/javascript/tagAutocomplete.js
index 158304a..9f3b545 100644
--- a/javascript/tagAutocomplete.js
+++ b/javascript/tagAutocomplete.js
@@ -611,8 +611,41 @@ async function updateRuby(textArea, prompt) {
}
escapedTag = escapeRegExp(escapedTag);
- if (translation)
- ruby.innerHTML = ruby.innerHTML.replaceAll(new RegExp(`${escapedTag}(?:\\)|\\b)`, "g"), `${translation}`);
+ if (translation) {
+ ruby.innerHTML = ruby.innerHTML.replaceAll(new RegExp(`(?)${escapedTag}(?:\\)|\\b)(?!