{"action":"created","issue":{"url":"https://api.github.com/repos/atom/atom/issues/10075","labels_url":"https://api.github.com/repos/atom/atom/issues/10075/labels{/name}","comments_url":"https://api.github.com/repos/atom/atom/issues/10075/comments","events_url":"https://api.github.com/repos/atom/atom/issues/10075/events","html_url":"https://github.com/atom/atom/issues/10075","id":122335832,"number":10075,"title":"Weird issue with backwardsScanInBufferRange on first buffer line","user":{"login":"lierdakil","id":7275622,"avatar_url":"https://avatars.githubusercontent.com/u/7275622?v=3","gravatar_id":"","url":"https://api.github.com/users/lierdakil","html_url":"https://github.com/lierdakil","followers_url":"https://api.github.com/users/lierdakil/followers","following_url":"https://api.github.com/users/lierdakil/following{/other_user}","gists_url":"https://api.github.com/users/lierdakil/gists{/gist_id}","starred_url":"https://api.github.com/users/lierdakil/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lierdakil/subscriptions","organizations_url":"https://api.github.com/users/lierdakil/orgs","repos_url":"https://api.github.com/users/lierdakil/repos","events_url":"https://api.github.com/users/lierdakil/events{/privacy}","received_events_url":"https://api.github.com/users/lierdakil/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-12-15T18:33:21Z","updated_at":"2015-12-15T19:20:09Z","closed_at":null,"body":"We've recently run into a weird issue with `TextEditor::backwardsScanInBufferRange` (see https://github.com/fcrespo82/atom-markdown-table-formatter/issues/23)\r\n\r\nConsider this snippet:\r\n\r\n```javascript\r\natom.workspace.getActiveTextEditor().backwardsScanInBufferRange(/./g, atom.workspace.getActiveTextEditor().getBuffer().getRange(), function(m) { console.log(m); m.replace(m.matchText+m.matchText); });\r\n```\r\n\r\nThis should, as far as I can gather, duplicate every character in current editor's buffer.\r\n\r\nOn a buffer with empty first line, it evidently does, i.e. buffer text like this\r\n\r\n```\r\n\r\nabcdefg\r\nhijklmn\r\nopqrstu\r\nvwzyz\r\n```\r\n\r\nbecomes\r\n\r\n```\r\n\r\naabbccddeeffgg\r\nhhiijjkkllmmnn\r\nooppqqrrssttuu\r\nvvwwzzyyzz\r\n```\r\n\r\nNote empty first line.\r\nThis is expected.\r\n\r\nWhat is unexpected is if we take the same buffer without empty first line, e.g.\r\n\r\n```\r\nabcdefg\r\nhijklmn\r\nopqrstu\r\nvwzyz\r\n```\r\n\r\nthen it becomes\r\n\r\n```\r\naabbccddeeffggdhhiijjkkllmmnnhooppqqrrssttuulvvwwzzyyzz\r\nooppqqrrssttuu\r\nvvwwzzyyzz\r\n```\r\n\r\nNote how it gobbled up newlines and introduced duplication.\r\n\r\nYou can use code snippet mentioned above in dev.console to test this.\r\n\r\nThis is really strange. Hope that someone can shed some light on this behavior.\r\nLooks like a bug if you ask me."},"comment":{"url":"https://api.github.com/repos/atom/atom/issues/comments/164863682","html_url":"https://github.com/atom/atom/issues/10075#issuecomment-164863682","issue_url":"https://api.github.com/repos/atom/atom/issues/10075","id":164863682,"user":{"login":"lierdakil","id":7275622,"avatar_url":"https://avatars.githubusercontent.com/u/7275622?v=3","gravatar_id":"","url":"https://api.github.com/users/lierdakil","html_url":"https://github.com/lierdakil","followers_url":"https://api.github.com/users/lierdakil/followers","following_url":"https://api.github.com/users/lierdakil/following{/other_user}","gists_url":"https://api.github.com/users/lierdakil/gists{/gist_id}","starred_url":"https://api.github.com/users/lierdakil/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lierdakil/subscriptions","organizations_url":"https://api.github.com/users/lierdakil/orgs","repos_url":"https://api.github.com/users/lierdakil/repos","events_url":"https://api.github.com/users/lierdakil/events{/privacy}","received_events_url":"https://api.github.com/users/lierdakil/received_events","type":"User","site_admin":false},"created_at":"2015-12-15T19:20:09Z","updated_at":"2015-12-15T19:20:09Z","body":"Yep, just tested. Reverting atom/text-buffer@51782bd fixes this issue.\r\n\r\n@maxbrunsfeld, care to join this discussion?"}}