Posts

Showing posts from August, 2015

Read Assistant

Image
I took 4 courses as part of my masters degree at university last semester. If I said I had tons of textual material to read I would not be exaggerating. Literally hundreds and hundreds of pages to read each week. Some of the readings were difficult academic articles too. Stuff you can't just read casually, to absorb and understand the material. On top of all the textbook reading I had to read at least two academic articles on the topic of philosophy of science per week. I had to understand these two articles and critique them. If I didn't do that regularly I would fall behind on the readings for that course and it would simply be impossible to complete the readings for the following week. I had to write tons of material too. Writing and editing of documents takes a lot of time too - a lot of rereading of what I wrote. At times, my mind was at the brink of exploding. My eyes would sting from all the screen time. The will to learn was certainly there but sometimes I felt I was

Finding and highlighting a section of text in WPF RichTextBox

I'm working on a hobby project and I was stumped by this seemingly simple task. RichTextBox class does not implement a straightforward way to do this out of the box. I found several useful snippets of code on StackOverflow but none worked perfectly with formatted text I was displaying in my RichTextBox. Text spread over multiple paragraphs, spans and containing embedded elements proved to be particularly problematic.  I figured out that I need to somehow use TextPointer class to find the section of the text I wanted to highlight. The main problem I had was finding the text within the document and then correctly obtaining the absolute character positions for the start of the section and the end of the section. If the document contained multiple paragraphs and the text I was trying to highlight spanned over multiple lines of text, the built-in methods would return character positions which were slightly off. My final solution was to implement TextPointer class extensions which ac