editable-text: Prevent dropping text into read-only field
This commit is contained in:
parent
489cee6b24
commit
f9e25675f0
1 changed files with 4 additions and 3 deletions
|
@ -260,24 +260,25 @@
|
|||
input.addEventListener('dragover', (event) => {
|
||||
// If the input is not focused, override the default drop behavior
|
||||
if ((document.activeElement !== this._input || Services.focus.activeWindow !== window)
|
||||
&& !this.readOnly
|
||||
&& event.dataTransfer.getData('text/plain')) {
|
||||
event.preventDefault();
|
||||
event.dataTransfer.dropEffect = 'copy';
|
||||
}
|
||||
});
|
||||
input.addEventListener('drop', (event) => {
|
||||
let text = event.dataTransfer.getData('text/plain');
|
||||
// If the input is not focused, replace its entire value with the dropped text
|
||||
// Otherwise, the normal drop effect takes place and the text is inserted at the cursor
|
||||
if ((document.activeElement !== this._input || Services.focus.activeWindow !== window)
|
||||
&& text) {
|
||||
&& !this.readOnly
|
||||
&& event.dataTransfer.getData('text/plain')) {
|
||||
event.preventDefault();
|
||||
document.activeElement?.blur();
|
||||
// Wait a tick to work around an apparent Firefox bug where the cursor stays inside the old
|
||||
// input even though the new input becomes visually focused
|
||||
setTimeout(() => {
|
||||
this.focus();
|
||||
this._input.value = text;
|
||||
this._input.value = event.dataTransfer.getData('text/plain');
|
||||
handleInput();
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue