fix: remove Tab keydown interceptor, use tabIndex=-1 on buttons instead

The keydown interceptor was likely conflicting with xterm.js native
Tab handling. Instead, set tabIndex=-1 on toolbar buttons so Tab
can't escape the terminal to browser focus, and auto-refocus terminal
on any click outside the toolbar.
This commit is contained in:
Mortdecai
2026-03-26 20:04:43 -04:00
parent fef67c148e
commit 4818a04b0d
+6 -10
View File
@@ -111,18 +111,14 @@
if(btn.dataset.k) send(btn.dataset.k); if(btn.dataset.k) send(btn.dataset.k);
}); });
// Prevent browser from stealing Tab key — send it to the terminal instead // Ensure terminal keeps focus (prevents Tab from escaping to browser chrome)
document.addEventListener('keydown', function(e){ document.addEventListener('click', function(e){
if(e.key === 'Tab' && !e.altKey && !e.ctrlKey && !e.metaKey){ if(!e.target.closest('#mb') && window.term) window.term.focus();
var active = document.activeElement;
// Only intercept if focus is on the terminal or body (not on toolbar buttons)
if(!active || active === document.body || active.closest('.xterm')){
e.preventDefault();
send('\t');
}
}
}); });
// Remove tabindex from toolbar buttons so Tab can't escape to them
bar.querySelectorAll('button').forEach(function(b){ b.tabIndex = -1; });
// Shrink terminal for toolbar on mobile (2 rows) // Shrink terminal for toolbar on mobile (2 rows)
var obs=new MutationObserver(function(){ var obs=new MutationObserver(function(){
var el=document.querySelector('.xterm'); var el=document.querySelector('.xterm');