Open GaurangTandon opened 7 years ago
Also related to #130
We can only hope to generate a keydown
event through programmatically pressing Ctrl key.
Hoping to support keypress
is useless since it requires insertion of a character which though will reflect on possibly more sites that depend on it, then that extra character cannot be removed from the markdown preview of textarea unless another keypress
is dispatched, which won't remove that character :(
So, use this http://stackoverflow.com/questions/596481/is-it-possible-to-simulate-key-press-events-programatically https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent
The fix is non-functional. It still does not work for sites like hipchat.
Reported by Salma Yusuf on uninstallation form
/**
* issues#106
* @param {Element} textarea in which keydown is simulated
*/
function simulateTextareaKeydown(textarea) {
textarea.focus();
document.execCommand("insertText", false, "a");
debugDir(textarea);
//textarea.triggerKeypress(8);
}
/**
* issues#106
* @param {Element} node in which keydown is simulated
*/
function simulateCEKeydown(node) {
node.focus();
document.execCommand("insertHTML", false, "a");
debugDir(node);
}
this is the snippet I used so far and doesn't work
Here are the relevant questions that I will investigate further tomorrow:
Also will probably self-answer or bounty my old question after cleaning it up and trying out things.
UPD: posted a new question, How to perform programmatic text input that supports both undo and redo?, hopefully this will go in some useful direction.
Apparently, document.execCommand("insertHTML/insertText")
supports undo/redo. However, custom editors may not like execCommand, and therefore may end up behaving weirdly (collapsing like the fb editor). So, I am delisting this from the milestone for now.
Last updated Sep 04 2017
Question posted on SO - http://stackoverflow.com/questions/42966805/actually-register-a-user-key-input-programmatically
Whatever expansion ProKeys does, is not registered in text editors. That means mashing Ctrl+Z/Y a few times after snippet expansion could ruin the text editor data entirely.
Also related: on some websites/forms => doing expansion, and pressing Tab to move to next field reverses the expansion back into a snippet key!
Consider SO question page - and the textbox where you type your question updates everytime there's a keystroke - however, it does not register any keystroke when snippets are expanded - either by hotkey or through ctx menu.
Also, when we execute the
testAll
snippet (very long multiline) in gmail compose box, the box's scroll bar does NOT appear unless we manually press some key.Hence the issue.
List of problematic sites:
Future plans: The SO question led to some good thoughts but now it's dead. The fixes suggested work for some sites and don't for others. There must be something common between SO, Hipchat, Zooniverse that they are defaulting back to the snippet name. I must work to find that common element in them.