Skip to content

Commit 978a828

Browse files
authored
fix(LinkEnhance): show creation widget when create link with whitespaces at end of selected text (#211)
1 parent cde768c commit 978a828

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

src/extensions/behavior/LinkEnhance/actions.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ export const addEmptyLink: Command = (state, dispatch) => {
3838
tr.setMeta(imageRendererKey, meta);
3939
}
4040
} else {
41-
tr.setSelection(TextSelection.create(tr.doc, $to.pos - 1));
41+
const selectedText = state.doc.textBetween($from.pos, $to.pos);
42+
const countOfWhitespacesAtEnd = selectedText.length - selectedText.trimEnd().length;
43+
tr.setSelection(TextSelection.create(tr.doc, $to.pos - countOfWhitespacesAtEnd - 1));
4244
}
4345
dispatch?.(tr);
4446
return true;

src/extensions/behavior/WidgetDecoration/plugin.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {Plugin, PluginKey} from 'prosemirror-state';
2-
import {DecorationSet} from 'prosemirror-view';
2+
import {Decoration, DecorationSet} from 'prosemirror-view';
33

44
import type {Meta, WidgetSpec} from './types';
55

@@ -30,11 +30,16 @@ export const WidgetDecorationPlugin = () => {
3030

3131
if (meta?.type === 'add') {
3232
const {descriptor} = meta;
33-
// @ts-expect-error // TODO
34-
const deco = Decoration.widget<WidgetSpec>(
33+
const spec: WidgetSpec = {
34+
id: descriptor.id,
35+
pos: descriptor.initPos,
36+
descriptor,
37+
};
38+
const deco = Decoration.widget(
3539
descriptor.initPos,
40+
// @ts-expect-error
3641
descriptor.render.bind(descriptor),
37-
{id: descriptor.id, pos: descriptor.initPos, descriptor},
42+
spec,
3843
);
3944

4045
set = set.add(tr.doc, [deco]);

0 commit comments

Comments
 (0)