RTEditor/src/main/java/com/onegravity/rteditor/utils/Paragraph.java
public boolean isSelected(Selection sel) {
        if (sel == null) {
            return false;
        }
        if (sel.isEmpty()) {
            // selection is a point
            boolean isCompletelyWithin = sel.start() >= start() && sel.end() < end();  // selection is completely within paragraph (not at the end)
            boolean isWithin = sel.start() >= start() && sel.end() <= end();           // selection is within or at the end of the paragraph
            return isCompletelyWithin || (isWithin && mIsLast);
        } else {
            // selection is a range --> at least one character in common
            int start = Math.max(start(), sel.start());
            int end = Math.min(end(), sel.end());
            return start < end;
        }
    }
public boolean isSelected(Selection sel) {
        if (sel == null) {
            return false;
        }
        if (sel.isEmpty()) {
            // selection is a point
            boolean isCompletelyWithin = sel.start() >= start() && sel.end() < end();  // selection is completely within paragraph (not at the end)
            boolean isWithin = sel.start() >= start() && sel.end() <= end();           // selection is within or at the end of the paragraph
            return isCompletelyWithin || (isWithin && mIsLast);
        } else {
            // selection is a range --> at least one character in common
            int start = Math.max(start(), sel.start());
            int end = Math.min(end(), sel.end());
            return start < end;
        }
    }
public boolean isSelected ( Selection sel ) { if ( sel == null ) { return false ; } if ( sel . isEmpty ( ) ) { // selection is a point boolean isCompletelyWithin = sel . start ( ) >= start ( ) && sel . end ( ) < end ( ) ; // selection is completely within paragraph (not at the end) boolean isWithin = sel . start ( ) >= start ( ) && sel . end ( ) <= end ( ) ; // selection is within or at the end of the paragraph return isCompletelyWithin || ( isWithin && mIsLast ) ; } else { // selection is a range --> at least one character in common int start = Math . max ( start ( ) , sel . start ( ) ) ; int end = Math . min ( end ( ) , sel . end ( ) ) ; return start < end ; } }
The paragraph is selected by the Selection if:
<p>
- they have at least one character in common
- the selection is a point within the paragraph ("01\n" -> 0 till 2 intersects while the span is [0, 3])
- the selection is a point within or at the end of the LAST paragraph ("01" -> 0 till 2 intersects while the span is [0, 2]),
e.g. [10, 10] will intersect the paragraph [0, 10] only if it's the last paragraph
The paragraph is selected by the Selection if : <p > - they have at least one character in common - the selection is a point within the paragraph ( 01 \ n - > 0 till 2 intersects while the span is [ 0 3 ] ) - the selection is a point within or at the end of the LAST paragraph ( 01 - > 0 till 2 intersects while the span is [ 0 2 ] ) e . g . [ 10 10 ] will intersect the paragraph [ 0 10 ] only if it s the last paragraph