Composer: Properly update quill state on clipboard cut

This commit is contained in:
Scott Nonnenberg
2025-03-19 08:49:03 +10:00
committed by GitHub
parent ac5d0eba0b
commit 22e9e84c10

View File

@@ -3,8 +3,11 @@
import type Quill from '@signalapp/quill-cjs';
import { Delta } from '@signalapp/quill-cjs';
import { deleteRange } from '@signalapp/quill-cjs/modules/keyboard';
import { FormattingMenu, QuillFormattingStyle } from '../formatting/menu';
import { insertEmojiOps } from '../util';
import { createEventHandler } from './util';
type ClipboardOptions = Readonly<{
isDisabled: boolean;
@@ -19,12 +22,26 @@ export class SignalClipboard {
this.options = options;
this.quill.root.addEventListener('paste', e => this.onCapturePaste(e));
this.quill.root.addEventListener('cut', e => this.onCaptureCut(e));
}
updateOptions(options: Partial<ClipboardOptions>): void {
this.options = { ...this.options, ...options };
}
onCaptureCut(event: ClipboardEvent): void {
const [range] = this.quill.selection.getRange();
// This updates the clipboard with what we want
const handler = createEventHandler({ deleteSelection: true });
handler(event);
// And this updates quill's internal state to reflect the cut
if (range) {
deleteRange({ range, quill: this.quill });
}
}
onCapturePaste(event: ClipboardEvent): void {
if (this.options.isDisabled) {
return;