@@ -130,6 +130,10 @@ class NoteEditorKmpViewModel(
130130 showSearch()
131131 }
132132
133+ KeyboardEvent .LIST -> {
134+ writeopiaManager.addListItem()
135+ }
136+
133137 else -> {}
134138 }
135139 }
@@ -142,15 +146,15 @@ class NoteEditorKmpViewModel(
142146
143147 private var isDarkTheme: Boolean = true
144148
145- private val _showSearch = MutableStateFlow (false )
149+ private val showSearch = MutableStateFlow (false )
146150 private val _searchText = MutableStateFlow (" " )
147- private val _currentSearchIndex = MutableStateFlow (0 )
148- private val _totalSearchResults = MutableStateFlow (0 )
151+ private val _currentSearchIndexState = MutableStateFlow (0 )
152+ private val _totalSearchResultsState = MutableStateFlow (0 )
149153
150- override val showSearchState: StateFlow <Boolean > = _showSearch .asStateFlow()
154+ override val showSearchState: StateFlow <Boolean > = showSearch .asStateFlow()
151155 override val searchText: StateFlow <String > = _searchText .asStateFlow()
152- override val currentSearchIndexState: StateFlow <Int > = _currentSearchIndex .asStateFlow()
153- override val totalSearchResultsState: StateFlow <Int > = _totalSearchResults .asStateFlow()
156+ override val currentSearchIndexState: StateFlow <Int > = _currentSearchIndexState .asStateFlow()
157+ override val totalSearchResultsState: StateFlow <Int > = _totalSearchResultsState .asStateFlow()
154158
155159 private val hasLinesSelection = writeopiaManager.onEditPositions
156160 .map { it.isNotEmpty() }
@@ -228,7 +232,7 @@ class NoteEditorKmpViewModel(
228232 private val _shouldGoToNextScreen = MutableStateFlow (false )
229233 override val shouldGoToNextScreen = _shouldGoToNextScreen .asStateFlow()
230234
231- private val _expandedFolders = MutableStateFlow (setOf<String >())
235+ private val expandedFolders = MutableStateFlow (setOf<String >())
232236
233237 override val isEditState: StateFlow <EditState > by lazy {
234238 writeopiaManager.onEditPositions.map { set ->
@@ -257,8 +261,8 @@ class NoteEditorKmpViewModel(
257261 .stateIn(viewModelScope, SharingStarted .Lazily , " " )
258262 }
259263
260- private val _sideMenuTab = MutableStateFlow (SideMenuTab .NONE )
261- override val sideMenuTabState: StateFlow <SideMenuTab > = _sideMenuTab .asStateFlow()
264+ private val _sideMenuTabState = MutableStateFlow (SideMenuTab .NONE )
265+ override val sideMenuTabState: StateFlow <SideMenuTab > = _sideMenuTabState .asStateFlow()
262266
263267 /* *
264268 * This property defines if the document is favorite
@@ -278,16 +282,16 @@ class NoteEditorKmpViewModel(
278282 writeopiaManager.toDraw,
279283 findsOfSearch,
280284 searchText,
281- _showSearch ,
282- _currentSearchIndex
285+ showSearch ,
286+ _currentSearchIndexState
283287 ) { drawState, finds, query, showSearch, currentSearchIndex ->
284288 if (finds.isEmpty() && showSearch) return @combine drawState.copy(focus = null )
285289 if (finds.isEmpty()) return @combine drawState
286290
287291 val mutableStories = drawState.stories.toMutableList()
288292 val activeFindPosition =
289293 if (finds.size > currentSearchIndex) finds.elementAt(currentSearchIndex) else null
290- _totalSearchResults .value = finds.size
294+ _totalSearchResultsState .value = finds.size
291295
292296 if (activeFindPosition != null ) {
293297 writeopiaManager.scrollToPosition(activeFindPosition)
@@ -360,7 +364,7 @@ class NoteEditorKmpViewModel(
360364 authRepository.listenForWorkspace()
361365 .flatMapLatest { workspace ->
362366 combine(
363- _expandedFolders ,
367+ expandedFolders ,
364368 folderRepository.listenForFoldersByParentId(
365369 " root" ,
366370 workspace.id
@@ -385,7 +389,7 @@ class NoteEditorKmpViewModel(
385389 }.stateIn(viewModelScope, SharingStarted .Lazily , emptyList())
386390
387391 override fun changeSideMenu (tab : SideMenuTab ) {
388- _sideMenuTab .value = tab
392+ _sideMenuTabState .value = tab
389393 }
390394
391395 override fun deleteSelection () {
@@ -485,7 +489,7 @@ class NoteEditorKmpViewModel(
485489
486490 override fun onAddListItemClick () {
487491 if (! isEditable.value) return
488- writeopiaManager.onListItemClicked ()
492+ writeopiaManager.addListItem ()
489493 }
490494
491495 override fun onAddCodeBlockClick () {
@@ -581,10 +585,10 @@ class NoteEditorKmpViewModel(
581585 }
582586
583587 override fun expandFolder (folderId : String ) {
584- val expanded = _expandedFolders .value
588+ val expanded = expandedFolders .value
585589 if (expanded.contains(folderId)) {
586590 viewModelScope.launch(Dispatchers .Default ) {
587- _expandedFolders .value = expanded - folderId
591+ expandedFolders .value = expanded - folderId
588592 }
589593 } else {
590594 viewModelScope.launch {
@@ -593,7 +597,7 @@ class NoteEditorKmpViewModel(
593597 folderId,
594598 workspace.id
595599 )
596- _expandedFolders .value = expanded + folderId
600+ expandedFolders .value = expanded + folderId
597601 }
598602 }
599603 }
@@ -739,15 +743,15 @@ class NoteEditorKmpViewModel(
739743 }
740744
741745 override fun showSearch () {
742- _showSearch .value = true
746+ showSearch .value = true
743747 }
744748
745749 override fun hideSearch () {
746750 viewModelScope.launch {
747- _showSearch .value = false
751+ showSearch .value = false
748752 delay(100 )
749753 _searchText .value = " "
750- _currentSearchIndex .value = 0
754+ _currentSearchIndexState .value = 0
751755 }
752756 }
753757
@@ -756,16 +760,16 @@ class NoteEditorKmpViewModel(
756760 _searchText .value = query
757761 val finds = findsOfSearch.first().toList().sorted()
758762 if (finds.isEmpty()) {
759- _currentSearchIndex .value = 0
760- _totalSearchResults .value = 0
763+ _currentSearchIndexState .value = 0
764+ _totalSearchResultsState .value = 0
761765 return @launch
762766 }
763767
764768 val currentPosition = writeopiaManager.currentStory.value.focus
765769 ? : writeopiaManager.currentStory.value.selection.position
766770 val newIndex = finds.indexOfFirst { it >= currentPosition }
767771
768- _currentSearchIndex .value = if (newIndex != - 1 ) newIndex else 0
772+ _currentSearchIndexState .value = if (newIndex != - 1 ) newIndex else 0
769773 }
770774 }
771775
@@ -774,8 +778,8 @@ class NoteEditorKmpViewModel(
774778 val total = findsOfSearch.first().size
775779 if (total == 0 ) return @launch
776780
777- val currentIndex = _currentSearchIndex .value
778- _currentSearchIndex .value = (currentIndex - 1 + total) % total
781+ val currentIndex = _currentSearchIndexState .value
782+ _currentSearchIndexState .value = (currentIndex - 1 + total) % total
779783 }
780784 }
781785
@@ -784,8 +788,8 @@ class NoteEditorKmpViewModel(
784788 val total = findsOfSearch.first().size
785789 if (total == 0 ) return @launch
786790
787- val currentIndex = _currentSearchIndex .value
788- _currentSearchIndex .value = (currentIndex + 1 ) % total
791+ val currentIndex = _currentSearchIndexState .value
792+ _currentSearchIndexState .value = (currentIndex + 1 ) % total
789793 }
790794 }
791795
0 commit comments