Skip to content

Commit

Permalink
Fix event source when deleting a link with shortcuts (#4200)
Browse files Browse the repository at this point in the history
  • Loading branch information
luin committed May 13, 2024
1 parent 09ed45e commit 2391107
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
2 changes: 1 addition & 1 deletion packages/quill/src/core/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ abstract class Module<T extends {} = {}> {
static DEFAULTS = {};

constructor(
protected quill: Quill,
public quill: Quill,
protected options: Partial<T> = {},
) {}
}
Expand Down
7 changes: 5 additions & 2 deletions packages/quill/src/modules/toolbar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string | Record<string, unknown>>
Expand Down Expand Up @@ -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) {
Expand All @@ -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;
Expand All @@ -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') {
Expand Down
7 changes: 4 additions & 3 deletions packages/quill/src/themes/bubble.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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 };
7 changes: 4 additions & 3 deletions packages/quill/src/themes/snow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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;

0 comments on commit 2391107

Please sign in to comment.