OfficeDev / office-js

A repo and NPM package for Office.js, corresponding to a copy of what gets published to the official "evergreen" Office.js CDN, at https://appsforoffice.microsoft.com/lib/1/hosted/office.js.
https://learn.microsoft.com/javascript/api/overview
Other
690 stars 95 forks source link

When adding ContentControl in Arabic language text its changing its position #5007

Open aamirhusnain opened 1 month ago

aamirhusnain commented 1 month ago

Provide required information needed to triage your issue

Your Environment

Expected behavior

I am inserting ContentControl after finding a text and it is working correctly in English language but it doesn't working correctly in the Arabic language when I am inserting the ContentControl my selected text going to left from right

Current behavior

In the Arabic language when I am inserting the ContentControl my selected text going to left from right

Steps to reproduce

  1. Open Word __
  2. Open Script Lab add-in
  3. Open Script Lab samples and use Content Control basis and replace the JavaScript code with my provided code

Link to live example(s)

  1. Open Word __
  2. Open Script Lab add-in
  3. Open Script Lab samples and use Content Control bacis and replace the JavaScript code with my provided code
$("#insert-controls").on("click", () => tryCatch(insertContentControls));
$("#setup").on("click", () => tryCatch(setup));

async function insertContentControls() {
  // Traverses each paragraph of the document and wraps a content control on each with either a even or odd tags.
  await Word.run(async (context) => {
    let original = "مصرر";
    const body = context.document.body;
    const rangeCollection = body.search(original, {
      matchCase: true,
      matchWholeWord: true
    });

    rangeCollection.load("items");
    await context.sync();

    if (rangeCollection.items.length > 0) {
      console.log(rangeCollection.items);
      const range = rangeCollection.items[0];
      console.log(`The word "${original}" with index ${0} is found.`);
      range.select();
      const contentControl = range.insertContentControl();
      contentControl.tag = "test123";
      contentControl.title = "test123";
      await context.sync();
    } else {
      console.log(`The word "${original}" with index ${0} was not found.`);
    }

    await context.sync();
  });
}

async function setup() {
  await Word.run(async (context) => {
    const body: Word.Body = context.document.body;
    body.clear();
    body.insertParagraph(
      "مصرر أم الدنيا و توونس البلد الجميل مصرر أم الدنيا و توونس البلد الجميل مصرر أم الدنيا و توونس البلد الجميل مصرر أم الدنيا و توونس البلد الجميل مصرر أم الدنيا و توونس",
      "Start"
    );
    body.paragraphs.getFirst().alignment = "Right";
  });
}

// 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

Useful logs

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.

RuizhiSunMS commented 1 month ago

ACK. Thx for your submit. I did a try following your repro steps. The string's alignment was 'right' both before and after 'inserting content control'. The below are screenshots. I suppose this is different from yours? If different, would you please share yours here? before: image after (I made changes to highlight searched range and string's head and tail): image

aamirhusnain commented 4 weeks ago

Hi @RuizhiSunMS Yes you are right this issue

RuizhiSunMS commented 4 weeks ago

@aamirhusnain, would you please share more information about the case? For example, screenshot of what you see or something else. Since I can't repro it, extra information would be helpful for us to repro and locate the root cause.

aamirhusnain commented 3 weeks ago

Hi @RuizhiSunMS The simple is that when we are adding contentControl on any selection not full line its changing its alignment and position

before image

After

image

RuizhiSunMS commented 3 weeks ago

@aamirhusnain thx for your sharing. I can repro it. Create an item #9501870 into our backlog to track it. We will reply to you as soon as there is any progress. Thank you for your patience.