{"action":"created","issue":{"url":"https://api.github.com/repos/Microsoft/vscode/issues/16475","repository_url":"https://api.github.com/repos/Microsoft/vscode","labels_url":"https://api.github.com/repos/Microsoft/vscode/issues/16475/labels{/name}","comments_url":"https://api.github.com/repos/Microsoft/vscode/issues/16475/comments","events_url":"https://api.github.com/repos/Microsoft/vscode/issues/16475/events","html_url":"https://github.com/Microsoft/vscode/issues/16475","id":193407197,"number":16475,"title":"Undo stops are created by extensions even when undoStopBefore/After options are both false","user":{"login":"axefrog","id":298883,"avatar_url":"https://avatars.githubusercontent.com/u/298883?v=3","gravatar_id":"","url":"https://api.github.com/users/axefrog","html_url":"https://github.com/axefrog","followers_url":"https://api.github.com/users/axefrog/followers","following_url":"https://api.github.com/users/axefrog/following{/other_user}","gists_url":"https://api.github.com/users/axefrog/gists{/gist_id}","starred_url":"https://api.github.com/users/axefrog/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/axefrog/subscriptions","organizations_url":"https://api.github.com/users/axefrog/orgs","repos_url":"https://api.github.com/users/axefrog/repos","events_url":"https://api.github.com/users/axefrog/events{/privacy}","received_events_url":"https://api.github.com/users/axefrog/received_events","type":"User","site_admin":false},"labels":[{"id":290465400,"url":"https://api.github.com/repos/Microsoft/vscode/labels/api","name":"api","color":"1d76db","default":false},{"id":256129998,"url":"https://api.github.com/repos/Microsoft/vscode/labels/question","name":"question","color":"E2A1C2","default":true}],"state":"open","locked":false,"assignee":{"login":"alexandrudima","id":5047891,"avatar_url":"https://avatars.githubusercontent.com/u/5047891?v=3","gravatar_id":"","url":"https://api.github.com/users/alexandrudima","html_url":"https://github.com/alexandrudima","followers_url":"https://api.github.com/users/alexandrudima/followers","following_url":"https://api.github.com/users/alexandrudima/following{/other_user}","gists_url":"https://api.github.com/users/alexandrudima/gists{/gist_id}","starred_url":"https://api.github.com/users/alexandrudima/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alexandrudima/subscriptions","organizations_url":"https://api.github.com/users/alexandrudima/orgs","repos_url":"https://api.github.com/users/alexandrudima/repos","events_url":"https://api.github.com/users/alexandrudima/events{/privacy}","received_events_url":"https://api.github.com/users/alexandrudima/received_events","type":"User","site_admin":false},"assignees":[{"login":"alexandrudima","id":5047891,"avatar_url":"https://avatars.githubusercontent.com/u/5047891?v=3","gravatar_id":"","url":"https://api.github.com/users/alexandrudima","html_url":"https://github.com/alexandrudima","followers_url":"https://api.github.com/users/alexandrudima/followers","following_url":"https://api.github.com/users/alexandrudima/following{/other_user}","gists_url":"https://api.github.com/users/alexandrudima/gists{/gist_id}","starred_url":"https://api.github.com/users/alexandrudima/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alexandrudima/subscriptions","organizations_url":"https://api.github.com/users/alexandrudima/orgs","repos_url":"https://api.github.com/users/alexandrudima/repos","events_url":"https://api.github.com/users/alexandrudima/events{/privacy}","received_events_url":"https://api.github.com/users/alexandrudima/received_events","type":"User","site_admin":false}],"milestone":null,"comments":3,"created_at":"2016-12-05T04:02:16Z","updated_at":"2016-12-13T09:03:52Z","closed_at":null,"body":"- VSCode Version: 1.7.2\r\n- OS Version: Windows 10\r\n\r\nI've just been updating my extension to make it so that automatic edits, made by the extension in between any two manual edits made by the user, are not included in the user's undo history and are simply removed as a batch as the user steps through the undo history made by their manual edits, so that the minor edits made by the extension are not given the same weight as a user's normal edits. Unfortunately, the `undoStopBefore` and `undoStopAfter` options seem to have no effect.\r\n\r\nSteps to Reproduce:\r\n\r\n1. Clone the simple extension _autotrim_ from https://github.com/axefrog/vscode-autotrim\r\n2. Modify [line 36 of extension.ts](https://github.com/axefrog/vscode-autotrim/blob/master/src/extension.ts#L36), disabling undo stops so that the code matches the code block further below.\r\n3. Set up a text file with five lines of text, and some trailing spaces on lines 2, 3 and 4.\r\n4. Test the extension in debug mode by making a change to line 1 and then using the arrow keys to move the cursor to line 5 and make another edit there. The extension will trim lines 2, 3 and 4 as it moves past them on the way to line 5.\r\n5. Try and undo the edits to lines 5 and 1.\r\n\r\n**Bug:** I'd expect the first undo to remove the edit to line 5, and the next undo to reverse all of the automatic changes to lines 2, 3, and 4, as well as the manual edit made to line 1. Instead, undo stops are also created for each line that was automatically trimmed by the extension, requiring several additional undos before the manual edit to line 1 is undone.\r\n\r\nThe code for line 36 should be:\r\n\r\n```ts\r\neditor.edit(ed => ed.replace(line.range, text), {undoStopBefore: false, undoStopAfter: false});\r\n```"},"comment":{"url":"https://api.github.com/repos/Microsoft/vscode/issues/comments/266683517","html_url":"https://github.com/Microsoft/vscode/issues/16475#issuecomment-266683517","issue_url":"https://api.github.com/repos/Microsoft/vscode/issues/16475","id":266683517,"user":{"login":"alexandrudima","id":5047891,"avatar_url":"https://avatars.githubusercontent.com/u/5047891?v=3","gravatar_id":"","url":"https://api.github.com/users/alexandrudima","html_url":"https://github.com/alexandrudima","followers_url":"https://api.github.com/users/alexandrudima/followers","following_url":"https://api.github.com/users/alexandrudima/following{/other_user}","gists_url":"https://api.github.com/users/alexandrudima/gists{/gist_id}","starred_url":"https://api.github.com/users/alexandrudima/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alexandrudima/subscriptions","organizations_url":"https://api.github.com/users/alexandrudima/orgs","repos_url":"https://api.github.com/users/alexandrudima/repos","events_url":"https://api.github.com/users/alexandrudima/events{/privacy}","received_events_url":"https://api.github.com/users/alexandrudima/received_events","type":"User","site_admin":false},"created_at":"2016-12-13T09:03:52Z","updated_at":"2016-12-13T09:03:52Z","body":"@axefrog I'm sorry I misunderstood initially. \r\n\r\n**TL;DR** the API works, your edits do not create undo stops, but moving the cursor creates those undo stops, long explanation below\r\n\r\nI have now tried your steps, and I can understand the intent of your extension: removing trailing whitespace on lines that have been \"visited\" by the cursor.\r\n\r\nThe root cause of this behaviour is that moving the cursor creates undo stops. Here I have logged in the undoStack manager what edit operations arrive to it and when undo stops are created:\r\n\r\n![16475](https://cloud.githubusercontent.com/assets/5047891/21133501/61296caa-c119-11e6-9977-b8d105438454.gif)\r\n\r\nI hope you notice how simply moving the cursor (without any edit operations) creates undo stops. Unfortunately, **this is by design**. The reason is simple: cursor moving is the single best hint of when to push undo stops in 90% of the cases. To further explain, consider the following steps:\r\n\r\n### Typing does not push undo stops\r\n* open an editor\r\n* type `a`\r\n* type `b`\r\n* type `c`\r\n* type `d`\r\n* undo: notice how typing does not introduce undo stops and it is possible to undo `a`, `b`, `c` and `d` having been typed in a single undo operation.\r\n\r\n![16475-ab](https://cloud.githubusercontent.com/assets/5047891/21133643/2fc4b8da-c11a-11e6-845c-f9a576295d48.gif)\r\n\r\n### Cursor movement pushes undo stops\r\n* open an editor\r\n* type `a`\r\n* type `b`\r\n* press arrow left\r\n* press arrow right\r\n* type `c`\r\n* type `d`\r\n* undo: notice how the first undo removes `cd` and the second undo removes `ab`\r\n\r\n![16475-ab-cd](https://cloud.githubusercontent.com/assets/5047891/21133700/7923b7a6-c11a-11e6-88f6-b6988cceb0d5.gif)\r\n\r\n### In closing\r\n\r\nThis is expected and consistent with other editors I have tried. \r\n\r\nNotice how from a logical point of view, the edits are 100% the same in both cases. i.e:\r\n* insert `a` at position (6, 0)\r\n* after some time, insert `b` at position (6, 1)\r\n* after some time, insert `c` at position (6, 2)\r\n* after some time, insert `d` at position (6, 3)\r\n\r\nThe only difference between the two cases is that the cursor was moved, hence moving the cursor inserts undo stops. I welcome any suggestions for improving how this works (while keeping the current undo behaviour around typing, deleting, etc.), including in the form of a PR."}}
{"actor":{"display_login":"alexandrudima"}}