void moveCaretAfterInsertionIfNeeded(int insertionLineStartOffset, int insertionLength) {
      if (caret.getOffset() != insertionLineStartOffset) {
        return;
      }
      int newLineStartOffset = insertionLineStartOffset + insertionLength;
      VisualPosition newLineStartPosition = caret.getEditor().offsetToVisualPosition(newLineStartOffset);
      int lineShift = newLineStartPosition.line - lineStartPosition.line;
      VisualPosition newPosition = new VisualPosition(position.line + lineShift,
                                                      position.column,
                                                      position.leansRight);
      caret.moveToVisualPosition(newPosition);
      // the following shouldn't happen, but just to be sure
      if (caret.getOffset() != newLineStartOffset) {
        caret.moveToOffset(newLineStartOffset);
      }
    }
void moveCaretAfterInsertionIfNeeded(int insertionLineStartOffset, int insertionLength)