Attaching an handler to DocumentSelectionChanged event disables the Undo stack on Office for Mac
Asked Answered
I

1

1

We have run in to, what seems like, a bug in Office.js on Office for Mac.

If you attach an event handler to DocumentSelectionChanged event that calls Excel.run the standard Excel "undo" functionality gets disabled. And this remains disabled until the add-in is unloaded (i.e. the event handler is unhooked).

You can replicate this problem by (for example), taking the Excel-Add-in-JS-CollegeCreditsTracker sample app and inserting the following block of code in app.initialize method.

Office.context.document.addHandlerAsync(
        Office.EventType.DocumentSelectionChanged,
        function () {
            Excel.run(function (ctx) {
                var activeCell = ctx.workbook.getSelectedRange();
                activeCell.load(["address", "worksheet", "rowIndex", "columnIndex", "values", "formulas"]);
                return ctx.sync().then(function () {
                    app.showNotification(activeCell.address);
                });
            }).catch(function (err) {
                console.log(err);
            });
        },
        null,
        function (asyncResult) {
            console.log("Handler added: " + JSON.stringify(asyncResult));
        }
    );

Note that this works fine on Excel Desktop an Excel Online. Is there a specific reason, such as API version supported on Office for Mac, that this would be failing?

This answer on an unrelated question suggests that there's an alternative way to handle selection change in newer API versions (although it doesn't say how). In which case, is that a possible workaround for this?

We cannot use BindingChanged events because we want to know when the user moves in and out of bindings, when user switches worksheets etc.

Irritable answered 19/5, 2017 at 1:22 Comment(4)
I have updated the answer on the other thread. Would be curious to learn whether the new syntax solves the issue (though I assume it's merely syntactic, and shouldn't impact the underlying issue, if there is in fact a platform bug here). But do let us know...Gamekeeper
@MichaelZlatkovsky-Microsoft Yes, as expected that didn't have any impact on the issue. Is this an issue that your team can take a look at?Irritable
Ok, thanks for checking this. Yes, I will pass it along to the team.Gamekeeper
thanks for reporting this, we are investigating the issue internally, its apparently a bug.Midvictorian
I
2

Just want to let everyone know that this issue has been resolved by the Office team.

Irritable answered 20/10, 2017 at 1:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.