Skip to content

[Word] Unexpected font inheritance when typing after insertContentControl #6448

@VictoriaSirghii

Description

@VictoriaSirghii

After calling context.document.getSelection().insertContentControl() and applying font formatting to the ContentControl, any text typed by the user afterward unexpectedly inherits the same font formatting. The formatting is not reset to the paragraph’s default once.

Your Environment

  • Platform [PC desktop, Mac, iOS, Office on the web]: Microsoft Word Mac, Microsoft Word online
  • Host [Excel, Word, PowerPoint, etc.]: Word
  • Office version number: Microsoft Word Mac - Version 16.106 (26011411), Microsoft Word Online - 20260114.4
  • Operating System: MacOs
  • Browser (if using Office on the web): Google Chrome

Expected behavior

Only the text inside the inserted ContentControl should have the specified formatting (superscript, bold, italic, red).
Text typed by the user afterward should use the paragraph’s default formatting.

Current behavior

Text typed after the ContentControl insertion continues to inherit the font formatting applied to the ContentControl.

Steps to reproduce

  1. Open Word on the web and separately Word desktop with a blank document.
  2. Use Script Lab and run the following code.
  3. Click on Insert text.
  4. After the code executes, place the cursor at the end of the inserted ContentControl (outside of it) and type some text.
  5. Observe that the typed text inherits the same font formatting as the ContentControl

Provide additional details

_Script_
$("#run-code").on("click", () => tryCatch(runCode));

async function runCode() {
  await Word.run(async (context) => {
    const contentControl = context.document.getSelection().insertContentControl();

    contentControl.insertText("Hello Word", Word.InsertLocation.replace);
    contentControl.font.superscript = true;
    contentControl.font.bold = true;
    contentControl.font.italic = true;
    contentControl.font.color = "red";

    await context.sync();
  });
}

/** Default helper for invoking an action and handling errors. */
async function tryCatch(callback) {
  try {
    await callback();
  } catch (error) {
    console.error(error);
  }
}

_HTML_
<section class="ms-font-m">
	<p>Unexpected font inheritance when typing after insertContentControl.</p>
</section>

<section class="samples ms-font-m">
	<h3>Try it out</h3>
	<p><b>Instructions:</b></p>
	<ol>
		<li>Place your cursor in the document where you want to insert the text</li>
		<li>Click the button below</li>
	</ol>
	<button id="run-footnote" class="ms-Button">
        <span class="ms-Button-label">Insert text</span>
      </button>
</section>

_CSS_
    section.samples {
        margin-top: 20px;
    }

    section.samples .ms-Button, section.setup .ms-Button {
        display: block;
        margin-bottom: 5px;
        margin-left: 20px;
        min-width: 80px;
    }

_Libraries_
  https://appsforoffice.microsoft.com/lib/1/hosted/office.js
  @types/office-js

  office-ui-fabric-js@1.4.0/dist/css/fabric.min.css
  office-ui-fabric-js@1.4.0/dist/css/fabric.components.min.css

  core-js@2.4.1/client/core.min.js
  @types/core-js

  jquery@3.1.1
  @types/jquery@3.3.1

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions