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

Cannot edit Ace in a taskpane of an add-in in Excel for Windows #3375

Closed
SoftTimur opened this issue Aug 7, 2017 · 9 comments
Closed

Cannot edit Ace in a taskpane of an add-in in Excel for Windows #3375

SoftTimur opened this issue Aug 7, 2017 · 9 comments

Comments

@SoftTimur
Copy link

I just realised that we cannot modify well texts of Ace in a taskpane of an add-in in Excel for Windows. Although Office may not be a supported platform of Ace, this problem seems to apply to other source editors like CodeMirror as well. I would like to know if you have a solution or workaround, because one important of mine is disabled by this.

Here is the details.

Thank you in advance

@nightwing
Copy link
Member

I have not heard about excel addins running webviews before.
Does it run in some version of ie or edge?

Does it work if you click add textarea to the page, and click on it before clicking on the ace?

@SoftTimur
Copy link
Author

SoftTimur commented Aug 7, 2017

Yes, JavaScript API for Office is available to build Office add-ins with web languages, the add-ins are just like web pages...

Ace and CodeMirror of the web page of my testing add-in work fine in Chrome, IE, Safari, Excel Online (in Chrome, IE and Safari), and Excel for Mac. They just don't work in Excel for Windows.

"Does it work if you click add textarea to the page, and click on it before clicking on the ace?" ==> I don't know what you mean by "click add textarea to the page". But I just realised that, if we click on Excel, then click on a useless area (somewhere without element) in the taskpane before clicking in the Ace textarea, we could then edit its content. Is this information useful for you? Can we make some workaround?

@nightwing
Copy link
Member

try adding

window.addEventListener("mousedown", function(e) {
    if (!document.hasFocus()) e.stopPropagation()
}, true)

browsers sometimes do not focus the window, when mousedown even is cancelled. Normally ace does https://github.com/ajaxorg/ace/blob/v1.2.8/lib/ace/mouse/mouse_handler.js#L55, but maybe it doesn't work on the browser that excel uses

@SoftTimur
Copy link
Author

SoftTimur commented Aug 8, 2017

With the mousedown listener, It is better than before:

  1. if we click on Excel, then click back to Ace textarea, we still cannot edit the content
  2. if we click on Excel, then click back to Ace textarea, then click again, we can now edit the content

So do you have a solution? I think we are in the right direction...

Thank you

@nightwing
Copy link
Member

try adding editor.focus() call after stopPropagation()

@SoftTimur
Copy link
Author

I have done

window.addEventListener("mousedown", function(e) {
  if (!document.hasFocus()) {
    e.stopPropagation();
    editor.focus()
  }
}, true)

Now, each time I click back to anything in the taskpane, the focus is systematically set to the Ace textarea, I think we need to bind mousedown event only to the Ace textarea, right?

Actually, I will finally use ui-ace, because I am using AngularJS 1.X. How can we add the mousedown listener properly here?

Thank you very much

@nightwing
Copy link
Member

add

document.querySelector(".editor").addEventListener("mousedown", function(e) {
  if (!document.hasFocus()) {
    e.stopPropagation();
    e.currentTarget.env.editor.focus()
  }
}, true)

@nightwing
Copy link
Member

@SoftTimur Did the above solve your issue?

@SoftTimur
Copy link
Author

Yes, your last solution (see full code) did work in Excel for Windows. However, as I mentioned before, I need to use this in Angular 1.X framework. So I tried to make a directive like here, unfortunately it did not work in Excel for Windows.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants