// Delete all of the existing text, minus the last newline.
int deleteCount =
LineUtils.getTextCount(topLine, 0, bottomLine, bottomLine.getText().length() -
(deleteEndingNewline ? 0 : 1));
documentMutator.insertText(topLine, topLineInfo.number(), 0, text, false);
Position endOfInsertion =
PositionUtils.getPosition(topLine, topLineInfo.number(), 0, text.length() - 1);
documentMutator.deleteText(endOfInsertion.getLine(), endOfInsertion.getColumn(), deleteCount);
}