{"action":"created","issue":{"url":"https://api.github.com/repos/codemirror/CodeMirror/issues/3734","labels_url":"https://api.github.com/repos/codemirror/CodeMirror/issues/3734/labels{/name}","comments_url":"https://api.github.com/repos/codemirror/CodeMirror/issues/3734/comments","events_url":"https://api.github.com/repos/codemirror/CodeMirror/issues/3734/events","html_url":"https://github.com/codemirror/CodeMirror/issues/3734","id":123831849,"number":3734,"title":"What about not moving the cursor if setValue does not change the content?","user":{"login":"radek-holy","id":15715940,"avatar_url":"https://avatars.githubusercontent.com/u/15715940?v=3","gravatar_id":"","url":"https://api.github.com/users/radek-holy","html_url":"https://github.com/radek-holy","followers_url":"https://api.github.com/users/radek-holy/followers","following_url":"https://api.github.com/users/radek-holy/following{/other_user}","gists_url":"https://api.github.com/users/radek-holy/gists{/gist_id}","starred_url":"https://api.github.com/users/radek-holy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/radek-holy/subscriptions","organizations_url":"https://api.github.com/users/radek-holy/orgs","repos_url":"https://api.github.com/users/radek-holy/repos","events_url":"https://api.github.com/users/radek-holy/events{/privacy}","received_events_url":"https://api.github.com/users/radek-holy/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-12-24T20:13:22Z","updated_at":"2015-12-25T21:29:50Z","closed_at":"2015-12-25T21:29:50Z","body":"Hello,\r\n\r\nI'm trying to integrate CodeMirror into my Angular 2 based application. IIUIC, Angular encourages people to write forms in such a way that a controller listens to events fired from the form fields and updates the internal models of these fields. Under certain circumstances the controller [fires events back](https://github.com/angular/angular/issues/6114) to the form fields if the internal model changes. (This is useful e.g. if you need to initialize the field with a value.)\r\n\r\nIn such case in my application, every change in the CodeMirror editor results in an event that consequently calls the editor's `setValue` with the same value which is already there. Since the `setValue` method apparently sets the cursor position to the beginning of the document, it results in resetting the cursor position after every change in the editor.\r\n\r\nTo resolve this, I have included a test `if (value != editor.getDoc().getValue())` before the `setValue` call. There is a problem that if I hold a key down, it apparently updates the editor's value before the previous event is handled which results in an endless loop. But I have to investigate this more deeply first. For now, I just wanted to suggest whether it would make sense to (optionally) not reset the cursor position if I (consequently) call something like `doc.setValue(doc.getValue())`."},"comment":{"url":"https://api.github.com/repos/codemirror/CodeMirror/issues/comments/167263183","html_url":"https://github.com/codemirror/CodeMirror/issues/3734#issuecomment-167263183","issue_url":"https://api.github.com/repos/codemirror/CodeMirror/issues/3734","id":167263183,"user":{"login":"marijnh","id":144427,"avatar_url":"https://avatars.githubusercontent.com/u/144427?v=3","gravatar_id":"","url":"https://api.github.com/users/marijnh","html_url":"https://github.com/marijnh","followers_url":"https://api.github.com/users/marijnh/followers","following_url":"https://api.github.com/users/marijnh/following{/other_user}","gists_url":"https://api.github.com/users/marijnh/gists{/gist_id}","starred_url":"https://api.github.com/users/marijnh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/marijnh/subscriptions","organizations_url":"https://api.github.com/users/marijnh/orgs","repos_url":"https://api.github.com/users/marijnh/repos","events_url":"https://api.github.com/users/marijnh/events{/privacy}","received_events_url":"https://api.github.com/users/marijnh/received_events","type":"User","site_admin":false},"created_at":"2015-12-25T21:29:50Z","updated_at":"2015-12-25T21:29:50Z","body":"This would be overhead and complexity, as well as a non-obvious exception in the editor's behavior, for a use case that concerns precisely only you. So no, I'm not going to do this. Just do your own check, as you describe (and figure out where the infinite loop is coming from -- \"change\" event occur after the change has been applied, so you should definitely see the post-change document when they fire)"}}