Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: how to move the cursor to be the end of newly inserted tag? #235

Closed
zhaoyao91 opened this issue Mar 4, 2020 · 6 comments
Closed

Comments

@zhaoyao91
Copy link
Contributor

zhaoyao91 commented Mar 4, 2020

I've made some function to insert a special tag, but the cursor after inserting is before the tag. How to move it to the end of the new tag?

Kapture 2020-03-04 at 16 52 18

  pickup: function(e: any) {
    e.preventDefault();
    e.stopPropagation();

    const [variableKey, target] = extractAttrValue(
      e.target,
      "data-variable-key",
      (target: any) => /UL/i.test(target.tagName)
    );

    if (variableKey) {
      const variablePlaceholder = target.textContent;

      // @ts-ignore
      const node = this.util.createElement("var");
      node.setAttribute("data-node-type", "variable");
      node.setAttribute("data-variable-key", variableKey);
      node.setAttribute("contenteditable", false);
      node.textContent = variablePlaceholder;

      // @ts-ignore
      this.insertNode(node);
      // todo move cursor to the end ?

      // @ts-ignore
      this.history.push(false);
    }

    // @ts-ignore
    this.submenuOff();

    // @ts-ignore
    this.focus();
  }
};
@zhaoyao91 zhaoyao91 changed the title Question: how to move the cursor to be after the inserted tag? Question: how to move the cursor to be the end of newly inserted tag? Mar 4, 2020
@JiHong88
Copy link
Owner

JiHong88 commented Mar 4, 2020

Hi, @zhaoyao91

In the next version, the cursor moves after the tag inserted by core.insertNode.

In the current version, you can core.setRange method.

// @ts-ignore
this.insertNode(node);
// set range---------
this.setRange(node, 1, node, 1);

@zhaoyao91
Copy link
Contributor Author

I tried this snippet, it didn't work. the cursor just dispeared after inserted.

Not hurry for now. There are bunch of features I am expecting for the next version. Do you have a schedule? Just curious, not push~

@JiHong88
Copy link
Owner

JiHong88 commented Mar 4, 2020

Maybe it didn't work becouse I did test it in the develop brunch.
I registered a milestone :)

@zhaoyao91
Copy link
Contributor Author

:) BTW, I found the user functions are useful, such as uploadImage and insertHTML. but we can't use them in core when writing plugin :(

@JiHong88
Copy link
Owner

JiHong88 commented Mar 6, 2020

I'll be fix to access user functions from the core as functions object.
It would be better if could access user function right away.

@JiHong88 JiHong88 added this to the 2.26.0 milestone Mar 6, 2020
JiHong88 added a commit that referenced this issue Mar 6, 2020
@JiHong88 JiHong88 closed this as completed Mar 6, 2020
@JiHong88
Copy link
Owner

The 2.26.0 version has been updated.
If there is an issue, please register as a new issue.
Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants