I'm working on a MS Word Add-in project and basically there is one use case wherein I need to insert content controls on selected content on the document. I was able to do it easily however there is one issue where in if the selected content are empty spaces. Basically, if the selected content are empty spaces it will just add or append a content control after the empty spaces. The desired result would be that it should encapsulate the empty spaces inside the content control.
It basically works on any selected text on the document. However the issue only occurs on empty spaces.
javascript
// code snippet of the function which inserts the content control
const insertContentControl = () => {
Word.run(async function(context) {
// get selected range on document
var range = context.document.getSelection();
context.load(range);
await context.sync();
const text = range.text;
// insert content control on selected content on document
var contentControl = range.insertContentControl();
context.load(contentControl);
await context.sync();
// add content control customization.
contentControl.placeholderText = text;
contentControl.font.underline = "WaveHeavy";
contentControl.font.color = "blue";
await context.sync();
});
};
The desired result would be that it should encapsulate the empty spaces inside the content control just like the other selected text/content on the document.