From 6fbbc13a7c839289d130fbdbc06b9305cefea0ce Mon Sep 17 00:00:00 2001 From: Zihua Li Date: Mon, 13 May 2024 13:34:30 +0800 Subject: [PATCH] Fix event source when deleting a link with shortcuts Closes #4177 --- packages/quill/src/core/module.ts | 2 +- packages/quill/src/modules/toolbar.ts | 7 +++++-- packages/quill/src/themes/bubble.ts | 7 ++++--- packages/quill/src/themes/snow.ts | 7 ++++--- 4 files changed, 14 insertions(+), 9 deletions(-) diff --git a/packages/quill/src/core/module.ts b/packages/quill/src/core/module.ts index fca5b385df..feeac58ad7 100644 --- a/packages/quill/src/core/module.ts +++ b/packages/quill/src/core/module.ts @@ -4,7 +4,7 @@ abstract class Module { static DEFAULTS = {}; constructor( - protected quill: Quill, + public quill: Quill, protected options: Partial = {}, ) {} } diff --git a/packages/quill/src/modules/toolbar.ts b/packages/quill/src/modules/toolbar.ts index 411438e7c7..a178d25936 100644 --- a/packages/quill/src/modules/toolbar.ts +++ b/packages/quill/src/modules/toolbar.ts @@ -7,7 +7,7 @@ import type { Range } from '../core/selection.js'; const debug = logger('quill:toolbar'); -type Handler = (value: any) => void; +type Handler = (this: Toolbar, value: any) => void; export type ToolbarConfig = Array< string[] | Array> @@ -262,7 +262,7 @@ Toolbar.DEFAULTS = { } }); } else { - this.quill.removeFormat(range, Quill.sources.USER); + this.quill.removeFormat(range.index, range.length, Quill.sources.USER); } }, direction(value) { @@ -276,7 +276,9 @@ Toolbar.DEFAULTS = { }, indent(value) { const range = this.quill.getSelection(); + // @ts-expect-error const formats = this.quill.getFormat(range); + // @ts-expect-error const indent = parseInt(formats.indent || 0, 10); if (value === '+1' || value === '-1') { let modifier = value === '+1' ? 1 : -1; @@ -292,6 +294,7 @@ Toolbar.DEFAULTS = { }, list(value) { const range = this.quill.getSelection(); + // @ts-expect-error const formats = this.quill.getFormat(range); if (value === 'check') { if (formats.list === 'checked' || formats.list === 'unchecked') { diff --git a/packages/quill/src/themes/bubble.ts b/packages/quill/src/themes/bubble.ts index 63bf9ff8e3..5bb8519141 100644 --- a/packages/quill/src/themes/bubble.ts +++ b/packages/quill/src/themes/bubble.ts @@ -4,7 +4,7 @@ import BaseTheme, { BaseTooltip } from './base.js'; import { Range } from '../core/selection.js'; import type { Bounds } from '../core/selection.js'; import icons from '../ui/icons.js'; -import type Quill from '../core.js'; +import Quill from '../core/quill.js'; import type { ThemeOptions } from '../core/theme.js'; import type Toolbar from '../modules/toolbar.js'; import type { ToolbarConfig } from '../modules/toolbar.js'; @@ -135,14 +135,15 @@ BubbleTheme.DEFAULTS = merge({}, BaseTheme.DEFAULTS, { handlers: { link(value: string) { if (!value) { - this.quill.format('link', false); + this.quill.format('link', false, Quill.sources.USER); } else { + // @ts-expect-error this.quill.theme.tooltip.edit(); } }, }, }, }, -}); +} satisfies ThemeOptions); export { BubbleTooltip, BubbleTheme as default }; diff --git a/packages/quill/src/themes/snow.ts b/packages/quill/src/themes/snow.ts index e99daebd0a..153a834c26 100644 --- a/packages/quill/src/themes/snow.ts +++ b/packages/quill/src/themes/snow.ts @@ -4,7 +4,7 @@ import BaseTheme, { BaseTooltip } from './base.js'; import LinkBlot from '../formats/link.js'; import { Range } from '../core/selection.js'; import icons from '../ui/icons.js'; -import type Quill from '../core.js'; +import Quill from '../core/quill.js'; import type { Context } from '../modules/keyboard.js'; import type Toolbar from '../modules/toolbar.js'; import type { ToolbarConfig } from '../modules/toolbar.js'; @@ -136,15 +136,16 @@ SnowTheme.DEFAULTS = merge({}, BaseTheme.DEFAULTS, { ) { preview = `mailto:${preview}`; } + // @ts-expect-error const { tooltip } = this.quill.theme; tooltip.edit('link', preview); } else { - this.quill.format('link', false); + this.quill.format('link', false, Quill.sources.USER); } }, }, }, }, -}); +} satisfies ThemeOptions); export default SnowTheme;