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 @@ -103,7 +103,7 @@ public fun JsonTree(
is JsonTreeParserState.Ready -> {
Box(modifier = modifier) {
JsonTreeList(
items = state.list,
state = state,
contentPadding = contentPadding,
colors = colors,
icon = icon,
Expand Down Expand Up @@ -148,7 +148,7 @@ public fun JsonTree(

@Composable
private fun JsonTreeList(
items: List<JsonTreeElement>,
state: JsonTreeParserState.Ready,
contentPadding: PaddingValues,
colors: TreeColors,
icon: ImageVector,
Expand All @@ -160,6 +160,8 @@ private fun JsonTreeList(
lazyListState: LazyListState,
onClick: (JsonTreeElement) -> Unit,
) {
val items = state.list

LazyColumn(
state = lazyListState,
contentPadding = contentPadding
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ internal class JsonTreeParser(
val expandedList = state.list.first().expand(expansion = Expansion.All).toList()

withContext(mainDispatcher) {
parserState.value = state.copy(expandedList)
parserState.value = state.copy(list = expandedList)
}
expandedList
}
Expand Down Expand Up @@ -103,7 +103,7 @@ internal class JsonTreeParser(
}

withContext(mainDispatcher) {
parserState.value = state.copy(newList)
parserState.value = state.copy(list = newList)
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.sebastianneubauer.jsontree

import androidx.compose.runtime.Immutable
import kotlinx.serialization.json.JsonElement

@Immutable
internal sealed interface JsonTreeParserState {
data object Loading : JsonTreeParserState
data class Ready(val list: List<JsonTreeElement>) : JsonTreeParserState
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
package com.sebastianneubauer.jsontree.search

import androidx.compose.runtime.Immutable
import com.sebastianneubauer.jsontree.JsonTreeElement
import com.sebastianneubauer.jsontree.search.SearchState.SearchResult
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.withContext

@Immutable
internal data class SearchOccurrence(
// the index in the JsonTree list
val listIndex: Int,
// the ranges of the search query matches
val ranges: List<Range>,
) {
@Immutable
sealed interface Range {
val range: IntRange

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.sebastianneubauer.jsontree.search

import androidx.compose.runtime.Composable
import androidx.compose.runtime.Immutable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
Expand Down Expand Up @@ -178,6 +179,7 @@ public class SearchState internal constructor(
)
}

@Immutable
internal data class SearchResult(
val query: String?,
val occurrences: Map<Int, SearchOccurrence>,
Expand Down