Abstract to document...
When this.tx
is a WPF TextBox,
int index = 0;
int lineClicked = 0;
while (index < text.Length) {
if (text[index] == '\n')
lineClicked++;
if (this.tx.SelectionStart <= index)
break;
index++;
}
can be replaced by
int lineClicked = this.tx.GetLineIndexFromCharacterIndex(this.tx.SelectionStart);
I found that code in a sample. I do not know what worries me the most: that someone thought it was easier to write this many lines of inefficient code or the fact that may be it was not simple enough to find the method in the documentation. Is it because there is no abstraction for the character index, making it not consistently used through the documentation ? Therefore it is not clear whether the CaretIndex and the SelectionStart both refers to a char index or, better, a TextPointer.
I guess typedef
in C/C++ could prevent this.