The Magic of the Text Editor Cursor: You Always Type Out of Range

2025-03-01
The Magic of the Text Editor Cursor: You Always Type Out of Range

Have you ever wondered why, in a text editor, the cursor always seems to sit at the end of a word, allowing you to add characters seamlessly? This is actually a clever illusion. This article explores the subtle relationship between cursor position and string ranges in text editors, using the metaphor of a 'rake and its prongs' to explain why you always type 'out of range'. It also provides an improved `NSRange` extension for more accurate handling of cursor insertion points.

Development