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
'change' event fires when setting Ace programmatically #503
Comments
Same reason why I dropped CodeMirror for ACE. But ACE's code is a lot easier to read. I made a patch to somewhat fix this. The change event is still fired, but I added a boolean property to the data object: userTyped. Will be true if the user typed or pasted text into the editor. False if it was programmatically entered. This works for my specific use case in Chrome. This is for the ace-uncompressed.js file from 0.2.0: http://dl.dropbox.com/u/310281/ace-patch.txt |
i don't think there is a good way of separating 'programmatical' and user changes (e.g. to which type belongs text entered by autocomplete widget?) if you want only text input events you can add dom "input" event listener to editor.container |
either use method described in #1547 (comment) or editor.on("change", function(e) {
if (editor.curOp && editor.curOp.command.name) console.log("user change");
else console.log("other change")
}) |
The snippet posted by nightwing does not work as it should while copy-paste is applied. Another solution that may solve the issue is something like that e.g with jquery:
|
Well
doesn't work if you have two editor divs and they are both |
The bug with paste not having a command have been solved some time ago. Use either #1547 (comment) |
I just tried
verbatim and when I pasted, it said "other change". I'm on Safari 9.0.1. Is that a supported platform? |
Maybe you are using old version? |
Yep so I though you meant adding the |
Sorry there was an error in the example. silent = true
editor.session.setValue("some text");
silent = false and in change listener if (silent) return so silent is a variable in your module, not something you pass to ace. Note that using applyDeltas is not enough for syncing, as you'll need to change deltas to take account that document to which you applying is most likely different from the document for which they were created. |
Yes, the bug I was experiencing was unrelated to the actual API of ace. Ace is ace - I was experiencing a concurrency issue with multiple (collaborative) editors in the same document, coordinated by a central server. That problem is non-trivial, requiring something called operational transformation; itself well beyond the scope of Ace. For those interested: https://en.wikipedia.org/wiki/Operational_transformation. Sorry for any inconvenience I've caused on your great project :/ haha! |
changes externally (by setting juicyAceEditor.value = "..") should not result in change event being triggered this avoids unnecessary notifications to two way data binding libraries such as Polymer solution is inspired by ajaxorg/ace#503
For code like this:
editor.getSession().on('change', function() {
// Do something
});
I would expect this event to only fire when there's a user interaction. However, I've found that it fires when I set the value of the editor programmatically, which is not consistent with something like, say, the DOM. (If you add a 'change' event listener for an input field, it will not fire if we set the value with JavaScript.)
Can this be fixed, and is there a workaround or a different event that fires when the value of the editor has updated, but not programmatically?
@Gissues:{"order":33.540372670807756,"status":"backlog"}
The text was updated successfully, but these errors were encountered: