Skip to content

[Word Online] context.document.getSelection().getBookmarks() returns all bookmarks located in the paragraph of current selection instead of only selection #6352

@NataliaKravcheniaTR

Description

@NataliaKravcheniaTR

Your Environment

  • Platform [PC desktop, Mac, iOS, Office on the web]: Office on the web
  • Host [Excel, Word, PowerPoint, etc.]: Word
  • Operating System: Windows
  • Browser (if using Office on the web): Chrome

Expected behavior

context.document.getSelection().getBookmarks() returns all bookmarks located within the current selection.
Note: This is the behavior in the Desktop version.

Current behavior

context.document.getSelection().getBookmarks() returns all bookmarks located in the paragraph of the current selection.

Steps to reproduce

Image

Click 'Setup' and 'Run' button

name: Basic API call (TypeScript)
description: Performs a basic Word API call using TypeScript.
host: WORD
api_set: {}
script:
  content: >
    document.getElementById("setup").addEventListener("click", () =>
    tryCatch(setup));

    document.getElementById("run").addEventListener("click", () =>
    tryCatch(run));


    async function run() {
      Word.run(async (context) => {
        context.document.body.getRange(Word.RangeLocation.start).select();

        await context.sync();

        const bookmarks = context.document.getSelection().getBookmarks();

        await context.sync();

        console.log(bookmarks.value);
      }).catch((error) => {
        throw error;
      });
    }


    async function setup() {
      Word.run(async (context) => {
        context.document.body.insertText("Selection ", Word.InsertLocation.replace);
        await context.sync();

        const bookmark = context.document.body.insertText("bookmark ", Word.InsertLocation.end);
        bookmark.insertBookmark("bookmark");

        await context.sync();
      }).catch((error) => {
        throw error;
      });
    }


    // Default helper for invoking an action and handling errors.

    async function tryCatch(callback) {
      try {
        await callback();
      } catch (error) {
        // Note: In a production add-in, you'd want to notify the user through your add-in's UI.
        console.error(error);
      }
    }
  language: typescript
template:
  content: |-
    <button id="setup" class="ms-Button">
        <span class="ms-Button-label">Setup document</span>
    </button>

    <button id="run" class="ms-Button">
        <span class="ms-Button-label">Run </span>
    </button>
  language: html
style:
  content: |-
    section.samples {
        margin-top: 20px;
    }

    section.samples .ms-Button, section.setup .ms-Button {
        display: block;
        margin-bottom: 5px;
        margin-left: 20px;
        min-width: 80px;
    }
  language: css
libraries: |-
  https://appsforoffice.microsoft.com/lib/1/hosted/office.js
  https://appsforoffice.microsoft.com/lib/1/hosted/office.d.ts

  https://unpkg.com/[email protected]/dist/css/fabric.min.css
  https://unpkg.com/[email protected]/dist/css/fabric.components.min.css


In Desktop version - []
In Word Online - ['bookmark']

Metadata

Metadata

Labels

Area: WordIssue related to Word add-insNeeds: attention 👋Waiting on Microsoft to provide feedback

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions