Add ability to jump to WI with ctrl click

This commit is contained in:
somebody
2022-09-26 18:37:24 -05:00
parent 26ba52e2fa
commit fa77267ae6

View File

@@ -57,6 +57,7 @@ var selected_game_chunk = null;
var log = []; var log = [];
var finder_mode = "ui"; var finder_mode = "ui";
var finder_waiting_id = null; var finder_waiting_id = null;
var control_held = false;
// name, desc, icon, func // name, desc, icon, func
const finder_actions = [ const finder_actions = [
@@ -3196,11 +3197,12 @@ function highlight_world_info_text_in_chunk(action, wi) {
action.insertBefore(before_span, span); action.insertBefore(before_span, span);
} }
//console.log("Highlight Text: '"+highlight_text+"'"); //console.log("Highlight Text: '"+highlight_text+"'");
var hightlight_span = document.createElement("span"); var highlight_span = document.createElement("span");
hightlight_span.classList.add("wi_match"); highlight_span.classList.add("wi_match");
hightlight_span.textContent = highlight_text; highlight_span.textContent = highlight_text;
hightlight_span.title = wi['content']; highlight_span.title = wi['content'];
action.insertBefore(hightlight_span, span); highlight_span.setAttribute("wi-uid", wi.uid);
action.insertBefore(highlight_span, span);
if (after_highlight_text != "") { if (after_highlight_text != "") {
//console.log("After Text: '"+after_highlight_text+"'"); //console.log("After Text: '"+after_highlight_text+"'");
var after_span = document.createElement("span"); var after_span = document.createElement("span");
@@ -4560,6 +4562,33 @@ $(document).ready(function(){
window.addEventListener("blur", function(event) { window.addEventListener("blur", function(event) {
contextMenu.classList.add("hidden"); contextMenu.classList.add("hidden");
}); });
// Change appearance of WI when holding control
document.addEventListener("keydown", function(event) {
if (event.key !== "Control") return;
control_held = true;
const style = ".wi_match { text-decoration: underline; cursor: pointer; }";
$e("style", document.head, {id: "wi-link-style", innerText: style})
});
// Remove on up
document.addEventListener("keyup", function(event) {
if (event.key !== "Control") return;
control_held = false;
document.querySelector("#wi-link-style").remove();
});
document.getElementById("Selected Text").addEventListener("click", function(event) {
// Control click on WI entry
if (!event.target.classList.contains("wi_match")) return;
if (!control_held) return;
let uid = event.target.getAttribute("wi-uid");
let wiCard = document.getElementById(`world_info_${uid}`);
highlightEl(wiCard);
});
}); });
document.addEventListener("keydown", function(event) { document.addEventListener("keydown", function(event) {