Fix #1674 and add more tests

I don't completely understand the purpose behind `noncontent_right()` etc.  If this fix breaks something else, we should make sure to add reftests for whatever it broke.

cc @ksh8281 who introduced those functions.