private void TextBoxPhonetic_TextChanged(object sender, EventArgs e) { if (textBoxPhonetic.Modified && textBoxPhonetic.SelectionStart > 0) { var cursorPosition = textBoxPhonetic.SelectionStart; var newChar = textBoxPhonetic.Text[cursorPosition - 1]; var result = editor.PutNewChar(newChar, cursorPosition); if (result.replaceLength > 0) { var replaceStartPosition = cursorPosition - result.replaceLength; textBoxPhonetic.Text = textBoxPhonetic.Text .Remove(replaceStartPosition, result.replaceLength) .Insert(replaceStartPosition, result.output); textBoxPhonetic.Select(replaceStartPosition + result.output.Length, 0); } } }
private void Test1() { editor.Reset(); editor.PutNewChar('k', 1); editor.PutNewChar('o', 2); editor.PutNewChar('r', 2); var result = editor.PutNewChar('r', 3); Assert.Equal(expected: "করর", result.output); result = editor.PutNewChar('m', 4); Assert.Equal(expected: "কর্ম", result.output); result = editor.PutNewChar(' '); Assert.Null(result.output); }