Skip to content

Commit 7472f56

Browse files
authored
fix(Link): fixed addLink action behavior (#763)
1 parent 6b07717 commit 7472f56

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed
Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
1-
import type {Command} from 'prosemirror-state';
1+
import {toggleMark} from '#pm/commands';
2+
import type {Command} from '#pm/state';
23

34
import type {ExtensionDeps} from '../../../../core';
5+
import {linkType} from '../LinkSpecs';
46

57
import {addPlaceholder} from './descriptor';
68

79
export const addLinkPlaceholder =
810
(deps: ExtensionDeps): Command =>
911
(state, dispatch) => {
1012
if (!state.selection.empty) return false;
13+
14+
const markType = linkType(state.schema);
15+
if (markType.isInSet(state.selection.$from.marks())) return false;
16+
if (!toggleMark(markType)(state)) return false;
17+
1118
dispatch?.(addPlaceholder(state.tr, deps).scrollIntoView());
1219
return true;
1320
};

src/extensions/markdown/Link/actions/linkEnhanceActions.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,13 @@ export const addEmptyLink: Command = (state, dispatch) => {
2424
// text selection inside one text node
2525
if ($from.parent !== $to.parent) return false;
2626
let tr = state.tr;
27-
toggleMark(linkMarkType, {
27+
const toggleResult = toggleMark(linkMarkType, {
2828
[LinkAttr.Href]: '',
2929
[LinkAttr.IsPlaceholder]: true,
3030
})(state, (_tr) => {
3131
tr = _tr;
3232
});
33+
if (!toggleResult) return false;
3334
tr.scrollIntoView();
3435
if (selection instanceof NodeSelection) {
3536
tr.setSelection(NodeSelection.create(tr.doc, $to.pos - 1));

0 commit comments

Comments
 (0)