How to position the cursor/caret after inserted inline ContentControl

I have written a custom visual plugin which allows a user to click a link to insert an inline content control into docx documents.

In order to do this I insert an empty inline content control:
window.Asc.plugin.executeMethod("AddContentControl", [2, {"Lock" : 3}]);

Then in ‘onMethodReturn()’ I use InsertAndReplaceContentControls to insert my actual text into the empty inline cc, something like this:

                obj.Props.InternalId = returnVal.InternalId;
                window.Asc.plugin.executeMethod("InsertAndReplaceContentControls", [[obj]]);

Where “obj” is a document object with “Props.Inline” set to true and a Script block that actually some content into the document.

This works great - you get an inline content control with the appropriate content, but the cursor ends up inside the content control [it is editable], at the start of the inserted text.

I’d like instead for the cursor to be after the inserted CC, so the user can type and text will show up in the same paragraph but after the content control.

I’ve tried the following:

  • I can shift it to the end of the content control via executeMethod ("MoveCursorToContentControl", [ returnVal.InternalId, false]); but this is still inside the CC so if the user types they’re typing within the content control.
  • I can select the entire content control via ‘executeMethod(“SelectContentControl”, [returnVal.InternalId]);’ - but that’s again not what I’d like.
  • I can shift the cursor to the end of the entire document via MoveCursorToEnd - but regardless of whether I pass true or false in as the last argument I’m not able to shift the cursor within the document itself

I’m not seeing any other APIs that help with this - either methods available via plugin.executeMethod, or document builder commands available via callCommand that allow me to explicitly position the cursor after a particular element [the contents control I just inserted], but I’m guessing this must be possible?

Thanks for any help or insight!

Document Server version:
OO Docs Developer Edition
[Document editor version shows up as 7.0.0]

Installation method:


  • MacOS, running the doc server via docker and serving the main webpage and plugin HTML from a separate Tomcat instance

Browser version:

  • Chrome Version 99.0.4844.51 (Official Build) (x86_64)

Hello @pablissimo
Could you please provide us with a recorded video with description of your plugin work and desired result?

Hi Alexandre!
Thanks for responding - Here’s a link to a screencast:

To put it in really simple terms

  • I want to inject an inline (non-block) content control into the document where the cursor is, then I want the cursor to appear after the content control so if the user continues to type they are typing into the document but not inside the CC.

I couldn’t see a way to inject an inline content control other than adding an empty content control via executeMethod("AddContentControl", ...) and then replacing it with the content I actually want via executeMethod("InsertAndReplaceContentControls", [[obj]]); [where ‘obj’ is the object to inject with a script block, and InlineId set to the InlineId of the CC we just added].

When I do this, the cursor ends up inside the new content control, before its actual content. I don’t see any way to then move the cursor after the end of the CC

Thanks for any help!

Hello @pablissimo
Sorry for the late reply.
We checked the situation, unfortunately there’s no way to achieve your scenario at the moment. We added your scenario to internal tracklist (internal number - 56278). We have started working on it.

1 Like

Sorry for the necro, has this been resolved in 7.4.0?

Hello @fr3fou
Not yet, we’re still working on the mentioned scenario. We will update this thread when we have something to share.