Allow global keyboard shortcuts to work in framed editor #6705
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I've been adding some keyboard navigation to my personal Wikis and I noticed one thing that annoyed the end of me - if I am in the middle of editing a tiddler I need to click away with the mouse for the shortcuts to work.
What changes:
$:/tags/KeyboardShortcut
will now work even if the focus is in the tiddler editor when using the toolbar (ie. framed editor is used).What changes (technically):
The reason is that the framed editor uses an iframe, and thus the keyboard events don't reach the host's
document
in the first place. I've distilled the solution to two changes:$tw.utils.addEventListeners()
now supports registering the event to listen in capture phase.framed.js
adds the listener that listens to the global shortcuts defined with$:/tags/KeyboardShortcuts
to the iframe document.Thus what happens is that if define a global keyboard shortcut for, say,
Ctrl+L
, if you have focus on the framed editor the capture phase listener will detect the keypress, run the shortcut and stop propagation, preventing Create wikitext link from running. On the other hand if there is no global keyboard shortcut it'll happily continue.Older solution:
At first I made two different changes:
framed.js
added a listener to global shortcuts directly inthis.domNode
keyboard.js
replacedstopPropagation()
withstopImmediatePropagation()
to prevent the framed editor's shortcuts to also triggerBut this introduced a potential problem, where if you had a situation where these callbacks were used but you also wanted the underlying events to trigger, they wouldn't. Or if you had multiple listeners in the document.
Possible problems:
I don't see any, but also I am not that knowledgable with TW.