Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,7 @@ class ReactNativeRichTextEditorView : AppCompatEditText {
if (value == null) return
isSettingValue = true

val isHtmlTagRecognized = value.startsWith("<html>") && value.endsWith("</html>")
val isPTagRecognized = value.startsWith("<p>") && value.endsWith("</p>")
val isHtml = isHtmlTagRecognized || isPTagRecognized
val isHtml = value.startsWith("<html>") && value.endsWith("</html>")
if (isHtml) {
val parsed = EditorParser.fromHtml(value, EditorParser.FROM_HTML_MODE_COMPACT, richTextStyle, null, null)
val withoutLastNewLine = parsed.trimEnd('\n')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -869,9 +869,9 @@ private static void endLi(Editable text, RichTextStyle style) {
List l = getLast(text, List.class);
if (l != null) {
if (l.mType.equals("ol")) {
setListSpanFromMark(text, l, new EditorOrderedListSpan(l.mIndex, style));
setParagraphSpanFromMark(text, l, new EditorOrderedListSpan(l.mIndex, style));
} else {
setListSpanFromMark(text, l, new EditorUnorderedListSpan(style));
setParagraphSpanFromMark(text, l, new EditorUnorderedListSpan(style));
}
}

Expand All @@ -885,18 +885,19 @@ private void startBlockquote(Editable text, Attributes attributes) {

private static void endBlockquote(Editable text, RichTextStyle style) {
endBlockElement(text);
end(text, Blockquote.class, new EditorBlockQuoteSpan(style));
Blockquote last = getLast(text, Blockquote.class);
setParagraphSpanFromMark(text, last, new EditorBlockQuoteSpan(style));
}

private void startCodeBlock(Editable text, Attributes attributes) {
startBlockElement(text, attributes, getMarginBlockquote());
start(text, new CodeBlock());
;
}

private static void endCodeBlock(Editable text, RichTextStyle style) {
endBlockElement(text);
end(text, CodeBlock.class, new EditorCodeBlockSpan(style));
CodeBlock last = getLast(text, CodeBlock.class);
setParagraphSpanFromMark(text, last, new EditorCodeBlockSpan(style));
}

private void startHeading(Editable text, Attributes attributes, int level) {
Expand Down Expand Up @@ -939,7 +940,7 @@ private static void setSpanFromMark(Spannable text, Object mark, Object... spans
}
}

private static void setListSpanFromMark(Spannable text, Object mark, Object... spans) {
private static void setParagraphSpanFromMark(Spannable text, Object mark, Object... spans) {
int where = text.getSpanStart(mark);
text.removeSpan(mark);
int len = text.length();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ class EditorSelection(private val editorView: ReactNativeRichTextEditorView) {
endPosition++
}

if (startPosition >= endPosition) {
// If the start position is equal or greater than the end position, return the same position
startPosition = endPosition
}

return Pair(startPosition, endPosition)
}

Expand Down
Loading