Skip to content

Commit

Permalink
fix tooltips
Browse files Browse the repository at this point in the history
  • Loading branch information
pomdtr committed Dec 9, 2023
1 parent b5e1560 commit 784d459
Showing 1 changed file with 19 additions and 15 deletions.
34 changes: 19 additions & 15 deletions frontend/src/terminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,20 +52,22 @@ async function main() {

const webglAddon = new WebglAddon();
const fitAddon = new FitAddon();

let [mouseX, mouseY] = [0, 0];
document.addEventListener("mousemove", (e) => {
mouseX = e.clientX;
mouseY = e.clientY;
});



const webLinksAddon = new WebLinksAddon((event, uri) => {
// check if cmd key is pressed
if (event.metaKey || event.ctrlKey) {
window.open(uri, "_blank");
}
}, {
hover: (_, text, location) => {
const terminalElement = document.getElementById("terminal")!;
const terminalRowHeight = terminalElement.getBoundingClientRect().height / terminal.rows;
const terminalColumnWidth = terminalElement.getBoundingClientRect().width / terminal.cols;

const locationTop = (location.start.y - 1) * terminalRowHeight + 10;
const locationLeft = (location.start.x - 1) * terminalColumnWidth + 10;

hover: (event, text) => {
if (document.getElementById('tooltip')) {
document.getElementById('tooltip')!.remove();
}
Expand All @@ -78,20 +80,21 @@ async function main() {
tooltip.style.visibility = 'hidden';
document.body.appendChild(tooltip);

const tooltipHeight = tooltip.getBoundingClientRect().height;
if (locationTop - tooltipHeight > 0) {
tooltip.style.top = `${locationTop - tooltipHeight}px`;
} else {
tooltip.style.top = `${locationTop + terminalRowHeight}px`;
}
tooltip.style.left = `${locationLeft}px`;
const tootlipSize = tooltip.getBoundingClientRect();
tooltip.style.zIndex = '1000';

// Add a delay of 1 second before showing the tooltip
setTimeout(() => {
// check if the tooltip still exists
const tooltip = document.getElementById('tooltip');
if (tooltip) {
if (mouseX - tootlipSize.height > 0) {
tooltip.style.top = `${mouseY - tootlipSize.height}px`;
} else {
tooltip.style.top = `${mouseY}px`;
}

tooltip.style.left = `${mouseX - tootlipSize.width / 2}px`;
tooltip.style.visibility = 'visible';
}
}, 1500);
Expand Down Expand Up @@ -186,6 +189,7 @@ async function main() {
terminal.focus();
};


terminal.focus();
}

Expand Down

0 comments on commit 784d459

Please sign in to comment.