mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-03-04 11:57:44 +01:00
fix firefox and selectionchange issues
This commit is contained in:
parent
377f3892f7
commit
6ff1d6a9b0
@ -102,10 +102,15 @@ export class AutoComplete {
|
|||||||
this.updateDetailsPositionDebounced = debounce(this.updateDetailsPosition.bind(this), 10);
|
this.updateDetailsPositionDebounced = debounce(this.updateDetailsPosition.bind(this), 10);
|
||||||
this.updateFloatingPositionDebounced = debounce(this.updateFloatingPosition.bind(this), 10);
|
this.updateFloatingPositionDebounced = debounce(this.updateFloatingPosition.bind(this), 10);
|
||||||
|
|
||||||
textarea.addEventListener('input', ()=>this.text != this.textarea.value && this.show(true, this.wasForced));
|
textarea.addEventListener('input', ()=>{
|
||||||
|
this.selectionStart = this.textarea.selectionStart;
|
||||||
|
if (this.text != this.textarea.value) this.show(true, this.wasForced);
|
||||||
|
});
|
||||||
textarea.addEventListener('keydown', (evt)=>this.handleKeyDown(evt));
|
textarea.addEventListener('keydown', (evt)=>this.handleKeyDown(evt));
|
||||||
textarea.addEventListener('click', ()=>this.isActive ? this.show() : null);
|
textarea.addEventListener('click', ()=>{
|
||||||
textarea.addEventListener('selectionchange', ()=>this.show());
|
this.selectionStart = this.textarea.selectionStart;
|
||||||
|
if (this.isActive) this.show();
|
||||||
|
});
|
||||||
textarea.addEventListener('blur', ()=>this.hide());
|
textarea.addEventListener('blur', ()=>this.hide());
|
||||||
if (isFloating) {
|
if (isFloating) {
|
||||||
textarea.addEventListener('scroll', ()=>this.updateFloatingPositionDebounced());
|
textarea.addEventListener('scroll', ()=>this.updateFloatingPositionDebounced());
|
||||||
@ -768,30 +773,16 @@ export class AutoComplete {
|
|||||||
// ignore keydown on modifier keys
|
// ignore keydown on modifier keys
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
switch (evt.key) {
|
// await keyup to see if cursor position or text has changed
|
||||||
case 'ArrowUp':
|
const oldText = this.textarea.value;
|
||||||
case 'ArrowDown':
|
await new Promise(resolve=>{
|
||||||
case 'ArrowRight':
|
window.addEventListener('keyup', resolve, { once:true });
|
||||||
case 'ArrowLeft': {
|
});
|
||||||
if (this.isActive) {
|
if (this.selectionStart != this.textarea.selectionStart) {
|
||||||
// keyboard navigation, wait for keyup to complete cursor move
|
this.selectionStart = this.textarea.selectionStart;
|
||||||
const oldText = this.textarea.value;
|
this.show(this.isReplaceable || oldText != this.textarea.value);
|
||||||
await new Promise(resolve=>{
|
} else if (this.isActive) {
|
||||||
window.addEventListener('keyup', resolve, { once:true });
|
this.text != this.textarea.value && this.show(this.isReplaceable);
|
||||||
});
|
|
||||||
if (this.selectionStart != this.textarea.selectionStart) {
|
|
||||||
this.selectionStart = this.textarea.selectionStart;
|
|
||||||
this.show(this.isReplaceable || oldText != this.textarea.value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default: {
|
|
||||||
if (this.isActive) {
|
|
||||||
this.text != this.textarea.value && this.show(this.isReplaceable);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user