Fixes errant newlines being added or removed when the selected region contains multiple leading or trailing newlines.