File tree Expand file tree Collapse file tree
shared/src/commonMain/kotlin/com/softartdev/notedelight/shared/presentation/note Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -106,23 +106,19 @@ class NoteViewModel(
106106 private fun createTitleIfNeed (title : String? , text : String ) =
107107 if (title.isNullOrEmpty()) createTitle(text) else title
108108
109- // TODO trim '\n'
110109 private fun createTitle (text : String ): String {
111- // Get the note's length
112- val length = text.length
110+ var title = text.substring(0 , 30 .coerceAtMost(text.length))
113111
114- // Sets the title by getting a substring of the text that is 31 characters long
115- // or the number of characters in the note plus one, whichever is smaller.
116- var title = text.substring(0 , 30 .coerceAtMost(length))
117-
118- // If the resulting length is more than 30 characters, chops off any
119- // trailing spaces
120- if (length > 30 ) {
112+ if (text.length > 30 ) {
121113 val lastSpace: Int = title.lastIndexOf(' ' )
122114 if (lastSpace > 0 ) {
123115 title = title.substring(0 , lastSpace)
124116 }
125117 }
118+ val firstLine = title.indexOf(' \n ' )
119+ if (firstLine > 0 ) {
120+ title = title.substring(0 , firstLine)
121+ }
126122 return title
127123 }
128124
You can’t perform that action at this time.
0 commit comments