Stop link typing #1114
-
can we stop the link by pressing the space? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 3 replies
-
It's easy to implement: const stopLinkCommand = $command('stopLink', (ctx) => (options) => {
return (state, dispatch) => {
const marks = state.tr.storedMarks;
const markType = linkSchema.type(ctx);
const idx = marks.findIndex(mark => mark.type === markType);
if (idx < 0) {
return false;
}
dispatch(state.tr.removeStoredMark(markType))
return true;
}
});
const linkCustomKeymap = $useKeymap('linkCustomKeymap', {
StopLink: {
shortcuts: ['Space'],
command: (ctx) => {
const commands = ctx.get(commandsCtx)
return () => commands.call(stopLinkCommand.key)
},
},
})
editor.use([stopLinkCommand, linkCustomKeymap].flat()) It's a rough implementation and you may need to polish it. |
Beta Was this translation helpful? Give feedback.
-
There's no way to check if storedMarks is a link, so I just need to remove the mark type every time the spacebar is pressed, but does that cause other problems?
iShot_2023-09-12_10.39.11.mp4 |
Beta Was this translation helpful? Give feedback.
-
@Saul-Mirone I have a quick question, what is the difference between return true | false in $command const hasMark = (state, type) => {
if (!type) return false;
const { from, $from, to, empty } = state.selection;
if (empty) return !!type.isInSet(state.storedMarks || $from.marks());
return state.doc.rangeHasMark(from, to, type);
};
export const stopLinkCommand = $command('StopLink', (ctx) => () => {
return (state, dispatch) => {
const markType = linkSchema.type(ctx);
const checkMark = hasMark(state, markType);
if(checkMark){
dispatch(state.tr.removeStoredMark(markType));
}
return false;
}
}); |
Beta Was this translation helpful? Give feedback.
Maybe you can use something like this to check the mark: