Lines number after setText ('change' event) is broken #1356

Closed
tucnak opened this Issue Apr 6, 2013 · 3 comments

Comments

Projects
None yet
2 participants

tucnak commented Apr 6, 2013

If I call

editor.getSession().setValue('%1')

Also, I have a handler:

editor.on('change', function() {
    var newLines = editor.session.getLength();
    if (newLines != property("lines")) { // property is a storage function
        property("lines", newLines);
        Novile.onLinesChanged(newLines);
    }
});

Application's debug output:

[1] Lines number: 2. Text is "'use strict';
"
[2] Lines number: 1047. Text is "'use strict';

////////////////////////////////////

/**
 * @ngdoc function

...

after one setText call and code listed below. So, 'change' event is called twice (no idea why) and shows 2 lines always ('use strict' + \n) before real number of lines in the document

Member

nightwing commented Apr 6, 2013

Change event is dispatched synchronously during each part operation, setValue creates multiple change events one for removing old text and one for inserting.
Operations inserting multiple lines also will create several change events

tucnak commented Apr 6, 2013

@nightwing How can I handle visual changes, like changing the text or # of lines?

Member

nightwing commented Apr 6, 2013

It depends on what exactly you need, but setTimeout can work see http://jsbin.com/ojijeb/67/edit

tucnak closed this Apr 7, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment