Fix bug that caused zero-length spans to occasionally survive edits

Issue #1561