diff options
Diffstat (limited to 'plugins/grazie/src/main/kotlin/com/intellij/grazie/text/TextContent.java')
-rw-r--r-- | plugins/grazie/src/main/kotlin/com/intellij/grazie/text/TextContent.java | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/plugins/grazie/src/main/kotlin/com/intellij/grazie/text/TextContent.java b/plugins/grazie/src/main/kotlin/com/intellij/grazie/text/TextContent.java index 6978f1faba6a..7518cb30635d 100644 --- a/plugins/grazie/src/main/kotlin/com/intellij/grazie/text/TextContent.java +++ b/plugins/grazie/src/main/kotlin/com/intellij/grazie/text/TextContent.java @@ -117,6 +117,14 @@ public interface TextContent extends CharSequence, UserDataHolderEx { TextContent excludeRanges(List<Exclusion> ranges); /** + * @return the part of this text inside the corresponding range, or {@code null} if the result is empty + */ + default @Nullable TextContent subText(TextRange range) { + if (range.isEmpty()) return null; + return excludeRange(new TextRange(range.getEndOffset(), length())).excludeRange(new TextRange(0, range.getStartOffset())); + } + + /** * @return whether the given PSI file text range has non-empty intersection with any fragment covered by this text content. */ @Contract(pure = true) |