question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Keystrokes go to terminal even though modal has focus

See original GitHub issue

I’m using jquery.terminal 0.8.8 together with bootbox.js. If the terminal has focus when a bootbox prompt modal is shown, the focus is transferred to the text box in the modal as it should, but whatever I type still appears on the terminal instead until I click on the text box. I’ve tried calling disable() or focus(false) on the terminal instance before launching the dialog, but nothing seems to happen.

Here is a jsfiddle illustrating the issue: http://jsfiddle.net/0v4ttvfa/2/ (using jquery.terminal 0.7.8 because that’s only version I could find on a CDN). If you click on the “Click me” button, a modal pops up and its text box has focus (pink background), but if you type anything it shows up in the terminal instead. What am I doing wrong?

I looked through old issues and found #89 which seems similar, but I don’t think it’s the same.

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Reactions:2
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
jcubiccommented, Aug 26, 2014

There’re two problems. One is that right click don’t triger click event on document. The second is that click event on your context menu item don’t bubble up so terminal can disable itself, when you select menu item.

I can fix it in terminal by adding contextmenu event. Before I do this can run this code:

var term = $.terminal.active();
$(document).on('contextmenu', function(e) {
    if (!$(e.target).closest('.terminal').length && term.enabled()) {
        term.disable();
    } 
});

istead of $.terminal.active() you can use your terminal variable. I’ll add same code to terminal.

0reactions
isbadawicommented, Aug 26, 2014

That also works – but I use a few different context menus, so rather than repeat that I put the code in the binding handler so it’ll apply to all context menus.

Thanks again for looking into this!

Read more comments on GitHub >

github_iconTop Results From Across the Web

App loses focus after displaying modal dialog #5348 - GitHub
I expect focus to be returned to the application window that had it before the modal dialog appeared. In this case, that would...
Read more >
Switch focus between editor and integrated terminal
Now hit Alt+Shift+T to go to the terminal. Want to go back to the editor? Just Hit Ctrl+tab. Tested on Windows 10 machine...
Read more >
window focus change lags, some keystrokes go to the wrong ...
Run gnome-tweaks, set Windows->Window Focus to "Secondary Click" or "Sloppy"; Open two vertically-adjacent gnome-terminal windows; Put cursor in ...
Read more >
Focus modal with keyboard - gnome - Ask Ubuntu
There are at least 2 modal windows, Run a Command ( Alt + F2 ) and Authentication Required (launch an app requiring sudo...
Read more >
How to Detect a Sequence of Keystrokes in JavaScript
With JavaScript we can react when a user clicks on a specific part of the page, when a key is pressed, when mouse...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found