mirror of
https://github.com/hexastack/hexabot
synced 2025-02-16 17:52:34 +00:00
fix: restrict paste content to have text format+don't lose old text
This commit is contained in:
parent
81a507d091
commit
453f6a7f05
@ -181,10 +181,20 @@ const UserInput: React.FC = () => {
|
||||
onBlur={() => setInputActive(false)}
|
||||
onKeyDown={handleKey}
|
||||
onInput={handleInput}
|
||||
onPaste={(e) => {
|
||||
onPaste={async (e) => {
|
||||
e.preventDefault();
|
||||
(e.target as HTMLInputElement).innerText =
|
||||
e.clipboardData.getData('text/plain');
|
||||
|
||||
const text = await navigator.clipboard.readText();
|
||||
const range = window.getSelection()?.getRangeAt(0);
|
||||
|
||||
if (range && text) {
|
||||
const node = document.createTextNode(text);
|
||||
|
||||
range.deleteContents();
|
||||
range.insertNode(node);
|
||||
range.collapse(false);
|
||||
}
|
||||
|
||||
handleInput();
|
||||
}}
|
||||
contentEditable
|
||||
|
Loading…
Reference in New Issue
Block a user