private static int updateOffset(DocumentEvent event, int pos, boolean leanRight) {
      int offset = event.getOffset();
      int oldLength = event.getOldLength();
      int newLength = event.getNewLength();
      if (pos < offset || (pos == offset && (!leanRight || oldLength > 0))) return pos;
      if (pos >= offset + oldLength) return pos + newLength - oldLength;
      return offset + newLength;
    }
private static int updateOffset(DocumentEvent event, int pos, boolean leanRight)