Skip to content

Commit

Permalink
Fix warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
MohamedRejeb committed Mar 31, 2024
1 parent ceede9f commit 896e90c
Show file tree
Hide file tree
Showing 20 changed files with 60 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.mohamedrejeb.richeditor.paragraph

import androidx.compose.ui.text.ParagraphStyle
import androidx.compose.ui.text.TextRange
import com.mohamedrejeb.richeditor.annotation.ExperimentalRichTextApi
import com.mohamedrejeb.richeditor.model.RichSpan
import com.mohamedrejeb.richeditor.paragraph.type.DefaultParagraph
import com.mohamedrejeb.richeditor.paragraph.type.ParagraphType
Expand All @@ -17,6 +18,7 @@ internal class RichParagraph(
var type: ParagraphType = DefaultParagraph(),
) {

@OptIn(ExperimentalRichTextApi::class)
fun getRichSpanByTextIndex(
paragraphIndex: Int,
textIndex: Int,
Expand Down Expand Up @@ -60,6 +62,7 @@ internal class RichParagraph(
return index to null
}

@OptIn(ExperimentalRichTextApi::class)
fun getRichSpanListByTextRange(
paragraphIndex: Int,
searchTextRange: TextRange,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package com.mohamedrejeb.richeditor.paragraph.type

import androidx.compose.ui.text.ParagraphStyle
import com.mohamedrejeb.richeditor.annotation.ExperimentalRichTextApi
import com.mohamedrejeb.richeditor.model.RichSpan
import com.mohamedrejeb.richeditor.paragraph.RichParagraph

internal class DefaultParagraph : ParagraphType {
override val style: ParagraphStyle =
ParagraphStyle()

@OptIn(ExperimentalRichTextApi::class)
override val startRichSpan: RichSpan =
RichSpan(paragraph = RichParagraph(type = this))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import androidx.compose.ui.text.SpanStyle
import androidx.compose.ui.text.style.TextIndent
import androidx.compose.ui.unit.TextUnit
import androidx.compose.ui.unit.sp
import com.mohamedrejeb.richeditor.annotation.ExperimentalRichTextApi
import com.mohamedrejeb.richeditor.model.RichSpan
import com.mohamedrejeb.richeditor.paragraph.RichParagraph

Expand Down Expand Up @@ -46,6 +47,7 @@ internal class OrderedList(
override var startRichSpan: RichSpan =
getNewStartRichSpan()

@OptIn(ExperimentalRichTextApi::class)
private fun getNewStartRichSpan() =
RichSpan(
paragraph = RichParagraph(type = this),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package com.mohamedrejeb.richeditor.paragraph.type

import androidx.compose.ui.text.ParagraphStyle
import androidx.compose.ui.text.style.TextIndent
import androidx.compose.ui.unit.TextUnit
import androidx.compose.ui.unit.sp
import com.mohamedrejeb.richeditor.annotation.ExperimentalRichTextApi
import com.mohamedrejeb.richeditor.model.RichSpan
import com.mohamedrejeb.richeditor.paragraph.RichParagraph

Expand All @@ -20,6 +20,7 @@ internal class UnorderedList : ParagraphType {
)
)

@OptIn(ExperimentalRichTextApi::class)
override var startRichSpan: RichSpan =
RichSpan(
paragraph = RichParagraph(type = this),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import androidx.compose.ui.text.SpanStyle
import com.mohamedrejeb.ksoup.entities.KsoupEntities
import com.mohamedrejeb.ksoup.html.parser.KsoupHtmlHandler
import com.mohamedrejeb.ksoup.html.parser.KsoupHtmlParser
import com.mohamedrejeb.richeditor.annotation.ExperimentalRichTextApi
import com.mohamedrejeb.richeditor.model.*
import com.mohamedrejeb.richeditor.paragraph.RichParagraph
import com.mohamedrejeb.richeditor.paragraph.type.DefaultParagraph
Expand All @@ -18,6 +19,7 @@ import com.mohamedrejeb.richeditor.utils.fastForEachIndexed

internal object RichTextStateHtmlParser : RichTextStateParser<String> {

@OptIn(ExperimentalRichTextApi::class)
override fun encode(input: String): RichTextState {
val openedTags = mutableListOf<Pair<String, Map<String, String>>>()
val stringBuilder = StringBuilder()
Expand Down Expand Up @@ -238,6 +240,7 @@ internal object RichTextStateHtmlParser : RichTextStateParser<String> {
return builder.toString()
}

@OptIn(ExperimentalRichTextApi::class)
private fun decodeRichSpanToHtml(richSpan: RichSpan, parentFormattingTags: List<String> = emptyList()): String {
val stringBuilder = StringBuilder()

Expand Down Expand Up @@ -353,6 +356,7 @@ internal object RichTextStateHtmlParser : RichTextStateParser<String> {
/**
* Encodes HTML elements to [RichSpanStyle].
*/
@OptIn(ExperimentalRichTextApi::class)
private fun encodeHtmlElementToRichSpanStyle(
tagName: String,
attributes: Map<String, String>,
Expand All @@ -369,6 +373,7 @@ internal object RichTextStateHtmlParser : RichTextStateParser<String> {
/**
* Decodes HTML elements from [RichSpanStyle].
*/
@OptIn(ExperimentalRichTextApi::class)
private fun decodeHtmlElementFromRichSpanStyle(
richSpanStyle: RichSpanStyle,
): Pair<String, Map<String, String>> =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.mohamedrejeb.richeditor.parser.markdown
import androidx.compose.ui.text.SpanStyle
import androidx.compose.ui.text.font.FontStyle
import androidx.compose.ui.text.style.TextDecoration
import com.mohamedrejeb.richeditor.annotation.ExperimentalRichTextApi
import com.mohamedrejeb.richeditor.model.*
import com.mohamedrejeb.richeditor.paragraph.RichParagraph
import com.mohamedrejeb.richeditor.paragraph.type.DefaultParagraph
Expand All @@ -22,6 +23,7 @@ import org.intellij.markdown.flavours.gfm.GFMElementTypes

internal object RichTextStateMarkdownParser : RichTextStateParser<String> {

@OptIn(ExperimentalRichTextApi::class)
override fun encode(input: String): RichTextState {
val openedNodes = mutableListOf<ASTNode>()
val stringBuilder = StringBuilder()
Expand Down Expand Up @@ -149,7 +151,7 @@ internal object RichTextStateMarkdownParser : RichTextStateParser<String> {

currentRichSpan = currentRichSpan?.parent
},
onHtml = { html ->
onHtml = { _ ->
// Todo: support HTML in markdown
}
)
Expand Down Expand Up @@ -187,6 +189,7 @@ internal object RichTextStateMarkdownParser : RichTextStateParser<String> {
return builder.toString()
}

@OptIn(ExperimentalRichTextApi::class)
private fun decodeRichSpanToMarkdown(richSpan: RichSpan): String {
val stringBuilder = StringBuilder()

Expand Down Expand Up @@ -239,6 +242,7 @@ internal object RichTextStateMarkdownParser : RichTextStateParser<String> {
/**
* Encodes Markdown elements to [RichSpanStyle].
*/
@OptIn(ExperimentalRichTextApi::class)
private fun encodeMarkdownElementToRichSpanStyle(
node: ASTNode,
markdown: String,
Expand Down Expand Up @@ -269,6 +273,7 @@ internal object RichTextStateMarkdownParser : RichTextStateParser<String> {
/**
* Decodes HTML elements from [RichSpan].
*/
@OptIn(ExperimentalRichTextApi::class)
private fun decodeMarkdownElementFromRichSpan(
text: String,
richSpanStyle: RichSpanStyle,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import androidx.compose.ui.platform.ClipboardManager
import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.text.buildAnnotatedString
import androidx.compose.ui.text.withStyle
import com.mohamedrejeb.richeditor.annotation.ExperimentalRichTextApi
import com.mohamedrejeb.richeditor.model.RichSpanStyle
import com.mohamedrejeb.richeditor.model.RichTextState
import com.mohamedrejeb.richeditor.paragraph.type.ParagraphType.Companion.startText
Expand All @@ -27,6 +28,7 @@ internal class RichTextClipboardManager(
return clipboardManager.getText()
}

@OptIn(ExperimentalRichTextApi::class)
override fun setText(annotatedString: AnnotatedString) {
val selection = richTextState.selection
val richTextAnnotatedString = buildAnnotatedString {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ internal fun DebugRichTextEditor(
.padding(8.dp),
)

Divider(modifier = Modifier.padding(vertical = 20.dp))
HorizontalDivider(modifier = Modifier.padding(vertical = 20.dp))

Text(
text = "Annotation Length: ${richTextState.annotatedString.text.length}",
Expand Down Expand Up @@ -83,7 +83,7 @@ internal fun DebugRichTextEditor(
RichTextStyleTreeRepresentation(childIndex, richTextStyle, " -")
}

Divider(modifier = Modifier.padding(vertical = 20.dp))
HorizontalDivider(modifier = Modifier.padding(vertical = 20.dp))
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ package com.mohamedrejeb.richeditor.model

import androidx.compose.runtime.mutableStateListOf
import androidx.compose.ui.text.TextRange
import com.mohamedrejeb.richeditor.annotation.ExperimentalRichTextApi
import com.mohamedrejeb.richeditor.paragraph.RichParagraph
import kotlin.test.Test
import kotlin.test.assertEquals

class RichParagraphStyleTest {
private val paragraph = RichParagraph(key = 0)
@OptIn(ExperimentalRichTextApi::class)
private val richSpanLists get() = listOf(
RichSpan(
key = 0,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package com.mohamedrejeb.richeditor.model

import androidx.compose.ui.text.TextRange
import com.mohamedrejeb.richeditor.annotation.ExperimentalRichTextApi
import com.mohamedrejeb.richeditor.paragraph.RichParagraph
import kotlin.test.Test
import kotlin.test.assertEquals

class RichSpanTest {
private val paragraph = RichParagraph(key = 0)
@OptIn(ExperimentalRichTextApi::class)
private val richSpan get() = RichSpan(
key = 0,
paragraph = paragraph,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.lazy.LazyRow
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.outlined.FormatAlignLeft
import androidx.compose.material.icons.automirrored.outlined.FormatAlignRight
import androidx.compose.material.icons.automirrored.outlined.FormatListBulleted
import androidx.compose.material.icons.filled.Circle
import androidx.compose.material.icons.outlined.*
import androidx.compose.runtime.Composable
Expand All @@ -20,9 +23,11 @@ import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.text.style.TextDecoration
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.mohamedrejeb.richeditor.annotation.ExperimentalRichTextApi
import com.mohamedrejeb.richeditor.model.RichTextState
import com.mohamedrejeb.richeditor.sample.common.richeditor.SpellCheck

@OptIn(ExperimentalRichTextApi::class)
@Composable
fun RichTextStyleRow(
modifier: Modifier = Modifier,
Expand All @@ -42,7 +47,7 @@ fun RichTextStyleRow(
)
},
isSelected = state.currentParagraphStyle.textAlign == TextAlign.Left,
icon = Icons.Outlined.FormatAlignLeft
icon = Icons.AutoMirrored.Outlined.FormatAlignLeft
)
}

Expand Down Expand Up @@ -70,7 +75,7 @@ fun RichTextStyleRow(
)
},
isSelected = state.currentParagraphStyle.textAlign == TextAlign.Right,
icon = Icons.Outlined.FormatAlignRight
icon = Icons.AutoMirrored.Outlined.FormatAlignRight
)
}

Expand Down Expand Up @@ -189,7 +194,7 @@ fun RichTextStyleRow(
state.toggleUnorderedList()
},
isSelected = state.isUnorderedList,
icon = Icons.Outlined.FormatListBulleted,
icon = Icons.AutoMirrored.Outlined.FormatListBulleted,
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@ package com.mohamedrejeb.richeditor.sample.common.htmleditor

import androidx.compose.foundation.layout.*
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.ArrowBack
import androidx.compose.material.icons.automirrored.filled.ArrowBack
import androidx.compose.material.icons.filled.SwapHoriz
import androidx.compose.material3.*
import androidx.compose.runtime.*
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.input.TextFieldValue
import cafe.adriel.voyager.navigator.LocalNavigator
import cafe.adriel.voyager.navigator.currentOrThrow
import com.mohamedrejeb.richeditor.model.rememberRichTextState
import com.mohamedrejeb.richeditor.sample.common.ui.theme.ComposeRichEditorTheme

@OptIn(ExperimentalMaterial3Api::class, ExperimentalLayoutApi::class)
@Composable
Expand Down Expand Up @@ -39,7 +37,7 @@ fun HtmlEditorContent() {
IconButton(
onClick = { navigator?.pop() }
) {
Icon(Icons.Default.ArrowBack, contentDescription = "Back")
Icon(Icons.AutoMirrored.Filled.ArrowBack, contentDescription = "Back")
}
},
actions = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ fun HtmlToRichText(

Spacer(Modifier.width(8.dp))

Divider(
HorizontalDivider(
modifier = Modifier
.fillMaxHeight()
.width(2.dp)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ fun RichTextToHtml(

Spacer(Modifier.width(8.dp))

Divider(
HorizontalDivider(
modifier = Modifier
.fillMaxHeight()
.width(2.dp)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.mohamedrejeb.richeditor.sample.common.markdowneditor

import androidx.compose.foundation.layout.*
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.ArrowBack
import androidx.compose.material.icons.automirrored.filled.ArrowBack
import androidx.compose.material.icons.filled.SwapHoriz
import androidx.compose.material3.*
import androidx.compose.runtime.*
Expand All @@ -11,9 +11,8 @@ import androidx.compose.ui.text.input.TextFieldValue
import cafe.adriel.voyager.navigator.LocalNavigator
import cafe.adriel.voyager.navigator.currentOrThrow
import com.mohamedrejeb.richeditor.model.rememberRichTextState
import com.mohamedrejeb.richeditor.sample.common.ui.theme.ComposeRichEditorTheme

@OptIn(ExperimentalMaterial3Api::class, ExperimentalLayoutApi::class)
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun MarkdownEditorContent() {
val navigator = LocalNavigator.currentOrThrow
Expand All @@ -39,7 +38,7 @@ fun MarkdownEditorContent() {
IconButton(
onClick = { navigator.pop() }
) {
Icon(Icons.Default.ArrowBack, contentDescription = "Back")
Icon(Icons.AutoMirrored.Filled.ArrowBack, contentDescription = "Back")
}
},
actions = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ fun MarkdownToRichText(

Spacer(Modifier.width(8.dp))

Divider(
HorizontalDivider(
modifier = Modifier
.fillMaxHeight()
.width(2.dp)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ fun RichTextToMarkdown(

Spacer(Modifier.width(8.dp))

Divider(
HorizontalDivider(
modifier = Modifier
.fillMaxHeight()
.width(2.dp)
Expand Down
Loading

0 comments on commit 896e90c

Please sign in to comment.