private static @NlsSafe @NotNull String truncateAndSaveIssueId(@NotNull TextRange issueIdRange,
                                                                 @NotNull String branchName,
                                                                 int maxBranchNameLength,
                                                                 int suffixLength, int delta) {
    String truncatedByDefault = StringUtil.shortenTextWithEllipsis(branchName,
                                                                   maxBranchNameLength,
                                                                   suffixLength, true);
    String issueId = issueIdRange.substring(branchName);

    if (truncatedByDefault.contains(issueId)) return truncatedByDefault;

    try {
      int branchNameLength = branchName.length();
      int endOffset = issueIdRange.getEndOffset();
      int startOffset = issueIdRange.getStartOffset();

      // suffix intersects with the issue id
      if (endOffset >= branchNameLength - suffixLength - delta) {
        return StringUtil.shortenTextWithEllipsis(branchName,
                                                  maxBranchNameLength,
                                                  branchNameLength - startOffset, true);
      }

      String suffix = branchName.substring(branchNameLength - suffixLength);
      int prefixLength = maxBranchNameLength - suffixLength - issueId.length();

      String prefixAndIssue;
      if (Math.abs(startOffset - prefixLength) <= delta) {
        prefixAndIssue = branchName.substring(0, endOffset);
      }
      else {
        String prefix = branchName.substring(0, prefixLength);
        prefixAndIssue = prefix + StringUtil.ELLIPSIS + issueId;
      }

      return prefixAndIssue + StringUtil.ELLIPSIS + suffix;
    }
    catch (Throwable e) {
      return truncatedByDefault;
    }
  }
private static @NlsSafe @NotNull String truncateAndSaveIssueId(@NotNull TextRange issueIdRange,
                                                                 @NotNull String branchName,
                                                                 int maxBranchNameLength,
                                                                 int suffixLength, int delta)