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 @@ -38,8 +38,12 @@ internal fun TextEditor(

if (position != null) {
LaunchedEffect(position, block = {
noteEditorViewModel.scrollToPosition.collectLatest {
listState.animateScrollBy(70F)
noteEditorViewModel.scrollToPosition.collectLatest { position ->
if (position == -1) {
listState.animateScrollBy(70F)
} else if (position != null) {
listState.scrollToItem(position, scrollOffset = -100)
}
}
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ import androidx.compose.ui.draw.clip
import androidx.compose.ui.focus.FocusRequester
import androidx.compose.ui.focus.focusRequester
import androidx.compose.ui.graphics.SolidColor
import androidx.compose.ui.input.key.Key
import androidx.compose.ui.input.key.KeyEventType
import androidx.compose.ui.input.key.key
import androidx.compose.ui.input.key.onPreviewKeyEvent
import androidx.compose.ui.input.key.type
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import io.writeopia.common.utils.icons.WrIcons
Expand Down Expand Up @@ -128,7 +133,17 @@ fun DesktopNoteEditorScreen(
onValueChange = noteEditorViewModel::searchInDocument,
modifier = Modifier.defaultMinSize(minWidth = 160.dp)
.focusRequester(focusRequester)
.padding(8.dp),
.padding(8.dp)
.onPreviewKeyEvent { keyEvent ->
if (keyEvent.type == KeyEventType.KeyUp &&
keyEvent.key.keyCode == Key.Enter.keyCode
) {
noteEditorViewModel.nextSearchResult()
true
}

false
},
singleLine = true,
textStyle = MaterialTheme.typography.bodySmall.copy(
color = MaterialTheme.colorScheme.onBackground
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,9 +284,14 @@ class NoteEditorKmpViewModel(
if (finds.isEmpty()) return@combine drawState

val mutableStories = drawState.stories.toMutableList()
val activeFindPosition = if (finds.size > currentSearchIndex) finds.elementAt(currentSearchIndex) else null
val activeFindPosition =
if (finds.size > currentSearchIndex) finds.elementAt(currentSearchIndex) else null
_totalSearchResults.value = finds.size

if (activeFindPosition != null) {
writeopiaManager.scrollToPosition(activeFindPosition)
}

finds.forEach { position ->
val realPosition = minOf(position * 2, mutableStories.lastIndex)
val toDraw = mutableStories[realPosition]
Expand Down Expand Up @@ -745,7 +750,8 @@ class NoteEditorKmpViewModel(
return@launch
}

val currentPosition = writeopiaManager.currentStory.value.focus ?: writeopiaManager.currentStory.value.selection.position
val currentPosition = writeopiaManager.currentStory.value.focus
?: writeopiaManager.currentStory.value.selection.position
val newIndex = finds.indexOfFirst { it >= currentPosition }

_currentSearchIndex.value = if (newIndex != -1) newIndex else 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,7 @@ class WriteopiaStateManager(
// Todo: Fix this when the inner position are completed
// backStackManager.addAction(BackstackAction.Add(newStory, newPosition))
_currentStory.value = newState.copy(selection = Selection.start())
_scrollToPosition.value = newPosition
_scrollToPosition.value = -1
}
}
}
Expand All @@ -660,6 +660,10 @@ class WriteopiaStateManager(
_currentStory.value = story.copy(focus = position)
}

fun scrollToPosition(position: Int) {
_scrollToPosition.value = position
}

private fun selected(isSelected: Boolean, position: Int) {
if (!isEditable) return
if (_currentStory.value.stories[position] != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ object DefaultDrawersDesktop : DrawersFactory {

return CommonDrawers.create(
manager,
30.dp,
300.dp,
aiExplanation,
editable,
onHeaderClick,
Expand Down