Larry Tesler recently passed, and Chris Espinosa has a nice thread on Twitter about one of his contributions to the Mac, which was a heuristic for inserting a space before or after a pasted section of text. This was a little piece of magic that I unknowingly benifited from for decades, until I was working on code editing support for one of my projects and I needed to override this behavior.
Larry's heuristic lives on in the Cocoa frameworks via the property
smartInsertDeleteEnabled in NSTextView. There's actually a handful of methods related to it, which you can find by searching for "smart" in the
NSTextView headers or documentation.