File tree Expand file tree Collapse file tree 5 files changed +36
-7
lines changed
application/features/editor/src/commonMain/kotlin/io/writeopia/editor/features/editor
commonMain/kotlin/io/writeopia/ui/manager
jvmMain/kotlin/io/writeopia/ui/drawer/factory Expand file tree Collapse file tree 5 files changed +36
-7
lines changed Original file line number Diff line number Diff line change @@ -38,8 +38,12 @@ internal fun TextEditor(
3838
3939 if (position != null ) {
4040 LaunchedEffect (position, block = {
41- noteEditorViewModel.scrollToPosition.collectLatest {
42- listState.animateScrollBy(70F )
41+ noteEditorViewModel.scrollToPosition.collectLatest { position ->
42+ if (position == - 1 ) {
43+ listState.animateScrollBy(70F )
44+ } else if (position != null ) {
45+ listState.scrollToItem(position, scrollOffset = - 100 )
46+ }
4347 }
4448 })
4549 }
Original file line number Diff line number Diff line change @@ -36,6 +36,11 @@ import androidx.compose.ui.draw.clip
3636import androidx.compose.ui.focus.FocusRequester
3737import androidx.compose.ui.focus.focusRequester
3838import androidx.compose.ui.graphics.SolidColor
39+ import androidx.compose.ui.input.key.Key
40+ import androidx.compose.ui.input.key.KeyEventType
41+ import androidx.compose.ui.input.key.key
42+ import androidx.compose.ui.input.key.onPreviewKeyEvent
43+ import androidx.compose.ui.input.key.type
3944import androidx.compose.ui.text.style.TextAlign
4045import androidx.compose.ui.unit.dp
4146import io.writeopia.common.utils.icons.WrIcons
@@ -128,7 +133,17 @@ fun DesktopNoteEditorScreen(
128133 onValueChange = noteEditorViewModel::searchInDocument,
129134 modifier = Modifier .defaultMinSize(minWidth = 160 .dp)
130135 .focusRequester(focusRequester)
131- .padding(8 .dp),
136+ .padding(8 .dp)
137+ .onPreviewKeyEvent { keyEvent ->
138+ if (keyEvent.type == KeyEventType .KeyUp &&
139+ keyEvent.key.keyCode == Key .Enter .keyCode
140+ ) {
141+ noteEditorViewModel.nextSearchResult()
142+ true
143+ }
144+
145+ false
146+ },
132147 singleLine = true ,
133148 textStyle = MaterialTheme .typography.bodySmall.copy(
134149 color = MaterialTheme .colorScheme.onBackground
Original file line number Diff line number Diff line change @@ -284,9 +284,14 @@ class NoteEditorKmpViewModel(
284284 if (finds.isEmpty()) return @combine drawState
285285
286286 val mutableStories = drawState.stories.toMutableList()
287- val activeFindPosition = if (finds.size > currentSearchIndex) finds.elementAt(currentSearchIndex) else null
287+ val activeFindPosition =
288+ if (finds.size > currentSearchIndex) finds.elementAt(currentSearchIndex) else null
288289 _totalSearchResults .value = finds.size
289290
291+ if (activeFindPosition != null ) {
292+ writeopiaManager.scrollToPosition(activeFindPosition)
293+ }
294+
290295 finds.forEach { position ->
291296 val realPosition = minOf(position * 2 , mutableStories.lastIndex)
292297 val toDraw = mutableStories[realPosition]
@@ -745,7 +750,8 @@ class NoteEditorKmpViewModel(
745750 return @launch
746751 }
747752
748- val currentPosition = writeopiaManager.currentStory.value.focus ? : writeopiaManager.currentStory.value.selection.position
753+ val currentPosition = writeopiaManager.currentStory.value.focus
754+ ? : writeopiaManager.currentStory.value.selection.position
749755 val newIndex = finds.indexOfFirst { it >= currentPosition }
750756
751757 _currentSearchIndex .value = if (newIndex != - 1 ) newIndex else 0
Original file line number Diff line number Diff line change @@ -648,7 +648,7 @@ class WriteopiaStateManager(
648648 // Todo: Fix this when the inner position are completed
649649 // backStackManager.addAction(BackstackAction.Add(newStory, newPosition))
650650 _currentStory .value = newState.copy(selection = Selection .start())
651- _scrollToPosition .value = newPosition
651+ _scrollToPosition .value = - 1
652652 }
653653 }
654654 }
@@ -660,6 +660,10 @@ class WriteopiaStateManager(
660660 _currentStory .value = story.copy(focus = position)
661661 }
662662
663+ fun scrollToPosition (position : Int ) {
664+ _scrollToPosition .value = position
665+ }
666+
663667 private fun selected (isSelected : Boolean , position : Int ) {
664668 if (! isEditable) return
665669 if (_currentStory .value.stories[position] != null ) {
Original file line number Diff line number Diff line change @@ -57,7 +57,7 @@ object DefaultDrawersDesktop : DrawersFactory {
5757
5858 return CommonDrawers .create(
5959 manager,
60- 30 .dp,
60+ 300 .dp,
6161 aiExplanation,
6262 editable,
6363 onHeaderClick,
You can’t perform that action at this time.
0 commit comments