Unable to prevent codemirror's own default events
Wzixiao opened this issue · 1 comments
Wzixiao commented
For example, we enter "( ", codemirror will automatically add ")"。
Another example is entering a carriage return, which will trigger a codemirror event, causing the page to be refreshed (the code prompt will be erased)。
Wzixiao commented
Resolve through judgment and simulation:
const simulateUserPressingBackspace = (activeRequestTextarea) => {
if (activeRequestTextarea) {
let event = new KeyboardEvent("keydown", { key: "Backspace", keyCode: 8, which: 8, code: "Backspace" });
activeRequestTextarea.dispatchEvent(event);
}
}
const simulateUserPressingMoveMouseRight = (activeRequestTextarea) => {
if (activeRequestTextarea) {
let event = new KeyboardEvent("keydown", { key: "ArrowRight", keyCode: 39, which: 39, code: "ArrowRight" });
activeRequestTextarea.dispatchEvent(event);
}
}