Actually, there is a light at the end of the tunnel. This pull request: https://github.com/angular/angular/issues/6311 [2] should fix most of the problem. The conditional "if (sOld === s) return" will be needed still but the jumping cursor and the endless loop should disappear. Once this is fixed, I guess it should be enough to investigate how does ngModel handle these "echos" to get rid of the conditional...
On 2016-01-18 18:15, Naftis wrote: > Geez, thanks for this... that's unfortunate. I had not yet played with this > solution, yet it seems it's a rather big issue. If I find some workaround or > fix I'll surely post it here. I'm also wondering how I can help you > attracting attention to your posted issue, of course this would be beneficial > for all of us. Should I make another post or append something to your own > just tell me. > > On Monday, January 18, 2016 at 9:46:09 AM UTC+1, Radek Holý wrote: > > Unfortunately, this is not the end. Sooner or later you will hit the same > problem as I did while trying to integrate CodeMirror... > > Actually, you hit it already. When you type something into the editor, your > directive emits an event which causes the "xml" property to be set. The > change of the "xml" property emits another event which is sent back to the > directive because of the two-way binding. On such event, the directive calls > "editor.setValue" and this method moves the cursor to the end of the > document. You have already "fixed" that using the conditional "if (sOld === > s) return". I did that as well. > > But once you start using the code in practice, you quickly realize that the > "fix" was not enough. Try to type something into the editor. Then move to > cursor at the beginning, hold a key down for several seconds and watch the > cursor. Sooner or later, you realize that the cursor have skipped to the end > of the editor and maybe that the editor have ended in an endless loop. > > To reproduce it easier, I recommend running enough busy loops (e.g. "python > -c 'while True:pass'") on the client. > > I've already reported the issue: > https://github.com/angular/angular/issues/6114 [1]. Unfortunately, I failed > to attract enough attention. > > If you find a workaround, please, let me know. I spent two weeks trying to > find one and I gave up when I tried to inspect the call stack. The only > acceptable workaround I was able to come up with is to ignore the incoming > changes while the editor is focused. But it has some drawbacks too... > > On 2016-01-17 15:48, Naftis wrote: > Thanks Michael, this did it! Now it seems that the binding is working in both > directions. I updated the Plunker accordingly. Of course, this is a hack but > I suppose/hope that once Angular 2 is released such issues should be removed. > Meantime, thanks again! > > On Sunday, January 17, 2016 at 3:31:17 PM UTC+1, michael corbridge wrote: > Update: > ummmm .... that ndx is for debugging - you can get rid of it > > On Sunday, January 17, 2016 at 9:29:31 AM UTC-5, michael corbridge wrote: > I see that same ... > > so I did this > ------------------------------------------------------------------------------------------------------------------- > > > this.editor.on("change", (e:any) => { > this.ndx++; > if(this.ndx === 10){ > return; > } > let s = this.editor.getValue(); > if(s.length !== 0){ //<--------------------check the length of the string > sent back > this.textChanged.emit(s); > } > }); > > ----------------------------------------------------------------- > > and that seems to fix the race condition > > On Sunday, January 17, 2016 at 1:36:41 AM UTC-5, Naftis wrote: > Thank you, this fixed the issue, I had misinterpreted the docs when they say > that the [(...)] notation is conceptually equivalent to a [...] plus a (...) > notation so I thought I had not to add the event handler explicitly. Anyway, > this now poses ANOTHER PROBLEM: try _first _typing something in the editor, > and _then _clicking the SET XML button: now the editor flickers in an endless > loop, as the change on one side is reflected on the other side, and > vice-versa, so that Angular seems stuck in a circular update. This also > happens if you type something, select a part or whole the typed text, and > type something else, thus replacing the selection. How could I solve this? -- You received this message because you are subscribed to the Google Groups "AngularJS" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/angular [3]. For more options, visit https://groups.google.com/d/optout [4]. -- You received this message because you are subscribed to the Google Groups "AngularJS" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/angular [3]. For more options, visit https://groups.google.com/d/optout [4]. Links: ------ [1] https://github.com/angular/angular/issues/6114 [2] https://github.com/angular/angular/issues/6311 [3] https://groups.google.com/group/angular [4] https://groups.google.com/d/optout -- You received this message because you are subscribed to the Google Groups "AngularJS" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/angular. For more options, visit https://groups.google.com/d/optout.
