Skip to content

Change the text of the Link #934

Answered by zgrybus
zgrybus asked this question in Q&A
Mar 14, 2023 · 1 comments · 1 reply
Discussion options

You must be logged in to vote

If someone is curious how do I manage to do that, here is my code:

useLinkActions hook

export const useLinkActions = () => {
  const { getSelectedMarkPosition } = useSelectedMarkPosition();

  const getLinkUpdateTransaction = useCallback(
    (view: EditorView, text: string, href: string) => {
      const { state } = view;

      const linkPosition = getSelectedMarkPosition(view, linkSchema.type());

      if (linkPosition) {
        const link = linkSchema.type().create({ href: href });
        const node = state.schema.text(text).mark([link]);

        return state.tr.replaceRangeWith(
          linkPosition.start,
          linkPosition.end,
          node
        );
      }
    },
    [

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@Saul-Mirone
Comment options

Answer selected by zgrybus
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants