-
Notifications
You must be signed in to change notification settings - Fork 120
InsertInlinePictureFromBase64("base64Image, "replace") 2x, causes RichApi Error #6573
Description
When inserting 2 images using context.document.getSelection()[InsertInlinePictureFromBase64](base64Image, "Replace"), the first image places properly but the 2nd image places together with an error message Uncaught (in promise) RichApi.Error: Cannot read properties of null (reading 'runIndex'). This is because there is no selection but getSelection() still thinks there is a selection.
Your Environment
- Platform [PC desktop, Mac, iOS, Office on the web]: Office on the Web (Windows and Mac)
- Host [Excel, Word, PowerPoint, etc.]: Word
- Operating System: Microsoft 365
- Browser (if using Office on the web): Chrome
Expected behavior
Since no image is selected, getSelection() should return without a selection and no error message should appear.
Current behavior
The first image replaces properly, but any subsequent image fails with an error message (and also places). This is because getSelection() is returning with a selection even when there is no selection.
Steps to reproduce
- Select an image from the Word web document
- Replace the image using
Word.run(async (context) => {
const selection = context.document.getSelection();
selection.insertInlinePictureFromBase64(base64Image, "Replace");
await context.sync();
});
- Don't change your cursor or selection and place another image.
- The image will place but an error message appears.
Note: I would think that the 2nd image wouldn't be within a selection, but context.document.getSelection() is returning with a selection.