{"action":"opened","issue":{"url":"https://api.github.com/repos/jacobslusser/ScintillaNET/issues/400","repository_url":"https://api.github.com/repos/jacobslusser/ScintillaNET","labels_url":"https://api.github.com/repos/jacobslusser/ScintillaNET/issues/400/labels{/name}","comments_url":"https://api.github.com/repos/jacobslusser/ScintillaNET/issues/400/comments","events_url":"https://api.github.com/repos/jacobslusser/ScintillaNET/issues/400/events","html_url":"https://github.com/jacobslusser/ScintillaNET/issues/400","id":322561407,"number":400,"title":"Possible bug with CharAdded event and non-English letters","user":{"login":"xv","id":410373,"avatar_url":"https://avatars3.githubusercontent.com/u/410373?v=4","gravatar_id":"","url":"https://api.github.com/users/xv","html_url":"https://github.com/xv","followers_url":"https://api.github.com/users/xv/followers","following_url":"https://api.github.com/users/xv/following{/other_user}","gists_url":"https://api.github.com/users/xv/gists{/gist_id}","starred_url":"https://api.github.com/users/xv/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/xv/subscriptions","organizations_url":"https://api.github.com/users/xv/orgs","repos_url":"https://api.github.com/users/xv/repos","events_url":"https://api.github.com/users/xv/events{/privacy}","received_events_url":"https://api.github.com/users/xv/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-05-13T03:46:17Z","updated_at":"2018-05-13T03:46:17Z","closed_at":null,"author_association":"NONE","body":"I just realised I have an issue with `CharAdded` event when calling `AutoIndentLines()`. It is somehow caused by non-English letters. Here's the code used for auto indentation:\r\n\r\n```c#\r\npublic static void AutoIndentLines(Scintilla sci, CharAddedEventArgs e)\r\n{\r\n    if (e.Char != '\\n')\r\n        return;\r\n\r\n    var currentPosition = sci.CurrentPosition;\r\n    var currentLine     = sci.LineFromPosition(currentPosition);\r\n    var previousIndent  = sci.Lines[currentLine - 1].Indentation;\r\n\r\n    sci.Lines[currentLine].Indentation = previousIndent;\r\n\r\n    var newCaretPosition = sci.PositionFromLine(currentLine) + previousIndent;\r\n    sci.GotoPosition(newCaretPosition);\r\n}\r\n\r\nprivate void Sci_CharAdded(object sender, CharAddedEventArgs e)\r\n{\r\n    SciMethods.AutoIndentLines(Sci, e);\r\n}\r\n```\r\n\r\n### What's happening?\r\nAs you can see in the demonstration below, in the first code block, auto indentation behaves correctly, as the caret remains behind the curly braces and in the correct position when auto indenting `// lines`. \r\n\r\nHowever, do you see that non-English alphabet letter `ä` in the in the comment after the first block? The indentation itself will work fine, but this where `sci.GotoPosition()` messes up. Any `\\r` or `\\n` entry after that letter will cause `sci.GotoPosition(newCaretPosition)` to add up 1 extra position to the right.\r\n\r\nI don't think my method is wrong. I wrote it in multiple different ways and the result is still the same. I have also tested it on native/C++ Scintilla and the behaviour is all correct.\r\n\r\n![bug_gif](https://i.imgur.com/cJmADPk.gif)\r\n\r\n### To replicate...\r\nYou can replicate the issue using the code above with this dummy code below:\r\n```c#\r\n// change the world!\r\n\r\nprivate void foo() {\r\n    if (something) {\r\n        // lines\r\n        // lines\r\n    }   \r\n}\r\n\r\n// ändere die Welt!\r\n\r\nprivate void roo() {\r\n    if (something) {\r\n        // lines\r\n        // lines\r\n    }\r\n}\r\n```\r\n\r\n### Notes\r\n1. It is not this letter in specific that is causing the abnormal behaviour. It can be any foreign letter, such as `ش`, `д`, `š`, etc.\r\n2. The method `scintilla.GotoPosition()` may not necessarily be the culprit. I have tried setting the caret position with `scintilla.SetSel()` as well and still having the issue."}}
{"actor":{"display_login":"xv"}}