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

[Word] difference behavior of Word.range from Tracked Change between native and online #5334

Open
3 tasks
shinji-morimitsu opened this issue Jan 30, 2025 · 2 comments
Assignees
Labels
Area: Word Issue related to Word add-ins Platform: Online Issues occurred on online platform Status: under investigation Issue is being investigated

Comments

@shinji-morimitsu
Copy link

Provide required information needed to triage your issue

We are implementing an automatic text update program in Word AddIn.
We need to update the document with take care of the tracked change histories.
To do this, we need to retrieve the TrackedChange object and its surrounding text,
but we are having trouble because the retrieved text is different between Native Word and Word Online.

Your Environment

  • Platform [PC desktop, Mac, iOS, Office on the web]: PC desktop, Office on the web
  • Host [Excel, Word, PowerPoint, etc.]: Word
  • Office version number: Version 2502 (build 18516.20000)
  • Operating System: Windows and Web
  • Browser (if using Office on the web): Chrome 132.0.6834.112

Expected behavior

  1. Getting track change object.
  2. Get left range, same range and right range from track change object.
  3. Get each texts of those ranges.

Native Word and Word Online should return same results.

By the live example:

rangeTexts[0]: left:[LEFT ] mid:[updated] mid:[center RIGHT]
rangeTexts[1]: left:[LEFT updated] mid:[center] mid:[ RIGHT]

Current behavior

Word Online: Left range and right range contains the text of tracked change itself.
Native Word: Left range and right range does not contain the text of tracked change itself.

Word Online by the live example:

rangeTexts[0]: left:[LEFT center] mid:[center] mid:[centerupdated RIGHT]
rangeTexts[1]: left:[LEFT centerupdated] mid:[updated] mid:[updated RIGHT]

Steps to reproduce

  1. run live examples.

Link to live example(s)

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

async function run() {
  await Word.run(async context => {
    // tracking mode off
    context.document.changeTrackingMode = Word.ChangeTrackingMode.off;
    await context.sync();
    console.log('tracking mode: off');

    // clear paragraph
    context.document.body.paragraphs.getFirst().delete();
    await context.sync();
    console.log('clear paragraph');
  });
  await Word.run(async context => {
    // insert text
    context.document.body.insertParagraph("LEFT center RIGHT", Word.InsertLocation.start);
    try {
      await context.sync();
    } catch (error) {
      console.error(`insert failed: ${JSON.stringify(error)}`);
    }
    console.log('insert initial text');

    // tracking mode on
    context.document.changeTrackingMode = Word.ChangeTrackingMode.trackAll;
    await context.sync();
    console.log('tracking mode: on');

    // update txt
    const paragraph = context.document.body.paragraphs.getFirst();
    const targetText = paragraph.search('center');
    const targetRange = targetText.getFirst().getRange(Word.RangeLocation.whole);
    targetRange.insertText('updated', Word.InsertLocation.replace);
    try {
      await context.sync();
    } catch (error) {
      console.error(`insert failed: ${JSON.stringify(error)}`);
    }
    console.log('update text');

    // get track change object
    const changes = paragraph.getTrackedChanges();
    changes.load('text,type');
    await context.sync();
    changes.items.forEach((change, index) => {
      console.log(`change[${index}]: text:${change.text} type:${change.type}`);
    });

    // get range of tarck change object
    const rangesList = changes.items.map(change => {
      const leftRange = paragraph.getRange(Word.RangeLocation.start).expandTo(change.getRange(Word.RangeLocation.start));
      const midRange = change.getRange(Word.RangeLocation.whole);
      const rightRange = paragraph.getRange(Word.RangeLocation.end).expandTo(change.getRange(Word.RangeLocation.end));
      leftRange.load('text');
      midRange.load('text');
      rightRange.load('text');
      return [leftRange, midRange, rightRange];
    });
    await context.sync();

    rangesList.forEach((ranges, index) => {
      console.log(`rangeTexts[${index}]: left:[${ranges[0].text}] mid:[${ranges[1].text}] mid:[${ranges[2].text}]`)
    });
  });
}

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

Provide additional details




Context

We are implementing an automatic text update program (sort of proofreading) in Word AddIn.
We need to update the document with take care of the tracked change histories.
To do this, we need to retrieve the TrackedChange object and its surrounding text,
but we are having trouble because the retrieved text is different between Native Word and Word Online.

e.g.
Document text is "a a a" and center "a" is deleted by tracked change.
And then our text base proofreading engine expect "a a" should be updated to "a b".
We need to skip the center 'a' (because it is deleted), and we need to update 3rd 'a' to 'b'.
So, it is important to check the tracked change text and surrounding texts.

Useful logs

  • Console errors
  • Screenshots
  • Test file (if only happens on a particular file)

Thank you for taking the time to report an issue. Our triage team will respond to you in less than 72 hours. Normally, response time is <10 hours Monday through Friday. We do not triage on weekends.

Copy link
Contributor

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

@microsoft-github-policy-service microsoft-github-policy-service bot added the Needs: attention 👋 Waiting on Microsoft to provide feedback label Jan 30, 2025
@guoms1 guoms1 added Status: under investigation Issue is being investigated Platform: Online Issues occurred on online platform and removed Needs: attention 👋 Waiting on Microsoft to provide feedback labels Feb 6, 2025
@guoms1
Copy link

guoms1 commented Feb 6, 2025

Hi,@shinji-morimitsu

Thanks for reporting this issue! I've been able to reproduce it locally and am currently discussing my understanding of the problem with the relevant team. I’ll keep you updated as soon as I have more details.

Let me know if you have any further questions in the meantime!

Best,

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 Platform: Online Issues occurred on online platform Status: under investigation Issue is being investigated
Projects
None yet
Development

No branches or pull requests

2 participants