{"action":"opened","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":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-12-24T20:13:22Z","updated_at":"2015-12-24T20:13:22Z","closed_at":null,"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 `doc.setValue(doc.getValue())`."}}