private int getCaretShiftForScopeEndingAt(int offset, boolean remove) {
      List<RangeMarker> scopes = getCurrentScopes(false);
      if (scopes == null) return 0;
      for (Iterator<RangeMarker> it = scopes.iterator(); it.hasNext(); ) {
        RangeMarker scope = it.next();
        if (offset == scope.getEndOffset()) {
          if (remove) it.remove();
          Integer caretShift = scope.getUserData(CARET_SHIFT);
          return caretShift == null ? 1 : caretShift;
        }
      }
      return 0;
    }
private int getCaretShiftForScopeEndingAt(int offset, boolean remove)