Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Call to Range.ExpandTo() triggers autosave on Word Online #4912

Open
Acibi opened this issue Sep 20, 2024 · 3 comments
Open

Call to Range.ExpandTo() triggers autosave on Word Online #4912

Acibi opened this issue Sep 20, 2024 · 3 comments
Assignees
Labels
Area: Word Issue related to Word add-ins Needs: attention 👋 Waiting on Microsoft to provide feedback

Comments

@Acibi
Copy link

Acibi commented Sep 20, 2024

Call to Range.ExpandTo() triggers autosave on Word Online

Your Environment

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

Expected behavior

Call to Range.ExpandTo() should not triggers auto-save on Word Online

Current behavior

Call to Range.ExpandTo() is triggering auto-save on Word Online. The save complete when an interaction occurs in the document (click, cursor move, etc)

Steps to reproduce

  1. Open a new document and insert text.
  2. Call ExpandTo() on some range.

Link to live example(s)

Script Lab Script to reproduce :

Script :

$("#run").on("click", () => tryCatch(run));
$("#register").on("click", () => tryCatch(register));

async function register() {
  await Word.run(async (context) => {
    context.document.onParagraphChanged.add(paragraphChanged);
    context.document.onParagraphAdded.add(paragraphAdd);
    context.document.onParagraphDeleted.add(paragraphDel);
    console.log("Ready!");
  });
}

async function run() {
  await Word.run(async (context) => {
    const rangeSel = context.document.getSelection();
    await context.sync();

    const range1 = rangeSel.getRange(Word.RangeLocation.start);
    const range2 = context.document.body.getRange(Word.RangeLocation.end);

    const rangeExp = range1.expandTo(range2);
    // Document is already saving here.

    rangeExp.load("text");
    await context.sync();
    console.log(rangeExp.text);
  });
}

async function paragraphAdd(event: Word.ParagraphAddedEventArgs) {
  await Word.run(async (context) => {
    console.log(`${event.type} event detected. IDs of paragraphs where content was added:`, event.uniqueLocalIds);
  });
}

async function paragraphDel(event: Word.ParagraphAddedEventArgs) {
  await Word.run(async (context) => {
    console.log(`${event.type} event detected. IDs of paragraphs where content was deleted:`, event.uniqueLocalIds);
  });
}

async function paragraphChanged(event: Word.ParagraphChangedEventArgs) {
  await Word.run(async (context) => {
    console.log(`${event.type} event detected. IDs of paragraphs where content was changed:`, event.uniqueLocalIds);
  });
}

// 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);
  }
}

Html:

<button id="register" class="ms-Button">
    <span class="ms-Button-label">Register</span>
</button>

<button id="run" class="ms-Button">
    <span class="ms-Button-label">Run</span>
</button>

Provide additional details

  1. Register : Install listener on paragraphs
  2. Run : Reproduce the bug.

During the run, the autosave will be triggered and after an interaction with the document, the Word.ParagraphChanged will be also triggered.

@microsoft-github-policy-service microsoft-github-policy-service bot added the Area: Word Issue related to Word add-ins label Sep 20, 2024
@microsoft-github-policy-service microsoft-github-policy-service bot added the Needs: attention 👋 Waiting on Microsoft to provide feedback label Sep 20, 2024
Copy link
Contributor

Thank you for letting us know about this issue. We will take a look shortly. Thanks.

@Acibi
Copy link
Author

Acibi commented Sep 20, 2024

I believe this bug is related : #2225

@shanshanzheng-dev
Copy link
Contributor

Hi @Acibi Thanks for reporting this issue, we'll take a look and report back if we have a suggestion for you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Word Issue related to Word add-ins Needs: attention 👋 Waiting on Microsoft to provide feedback
Projects
None yet
Development

No branches or pull requests

3 participants