Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix Tab while there's a selection not Tabbing away
By "Tabbing away" I mean that if something is focused, and you hit Tab, you expect focus to jump to the next thing in tab order. Normally that happens in MathQuill editable fields whenever the cursor is in the root block/at the top level. But, a bug was intro'd by mathquill#294 and reported in mathquill#413 that if there's a selection, then even if you're in the root block, when you hit Tab, focus wouldn't actually jump to the next thing. Instead, the math field would look blurred but the hidden textarea would "steal back" focus, and you could type in the seemingly- blurred MathQuill editable field, see GIF: https://git.io/v2UGL (The "Show Textareas" button in the top-right corner of test/visual.html was used to show the normally hidden textareas.) Note that this bug also affected API clients who in a handler like `upOutOf` that's called synchronously on `keydown`, blur the textarea (for example, by focusing something above the math field), which is exactly what mathquill#355 was supposed to fix. Turns out the test case in mathquill#355 isn't representative, the fix only seemed to work because for jQuery ≤1.8.3 (our tests use 1.7.2), when you call jQuery's `.blur()` method, the `blur` event handlers are called while the hidden textarea is still focused, so the `textarea[0].select()` doesn't "steal back" focus. However, when Tabbing away, or when the `upOutOf` or whatever handler focuses something else, or when you call jQuery ≥1.9.0's `.blur()` method, or (luckily for our tests) when you call the DOM's "native" `.blur()` method, the hidden textarea is already blurred, so the `textarea[0].select()` "steals back" focus, hence bug and fix. Isolated test case demonstrating this for jQuery 1.8.3 vs jQuery 1.9.0 vs the DOM's "native" `.blur()` method: http://jsbin.com/kepaxo/5/edit?console,output
- Loading branch information