11package com.raival.compose.file.explorer.screen.textEditor.ui
22
3- import androidx.compose.animation.AnimatedVisibility
4- import androidx.compose.animation.expandIn
5- import androidx.compose.animation.shrinkOut
6- import androidx.compose.animation.slideInVertically
7- import androidx.compose.animation.slideOutVertically
83import androidx.compose.foundation.background
94import androidx.compose.foundation.layout.Arrangement
105import androidx.compose.foundation.layout.Column
@@ -18,7 +13,6 @@ import androidx.compose.material3.TextField
1813import androidx.compose.material3.surfaceColorAtElevation
1914import androidx.compose.runtime.Composable
2015import androidx.compose.runtime.LaunchedEffect
21- import androidx.compose.ui.Alignment
2216import androidx.compose.ui.Modifier
2317import androidx.compose.ui.res.stringResource
2418import androidx.compose.ui.unit.dp
@@ -32,154 +26,147 @@ import io.github.rosemoe.sora.widget.EditorSearcher
3226@Composable
3327fun SearchPanel (
3428 codeEditor : CodeEditor ,
35- searcher : Searcher ,
36- show : Boolean
29+ searcher : Searcher
3730) {
38- AnimatedVisibility (
39- visible = show,
40- enter = expandIn(expandFrom = Alignment .TopCenter ) + slideInVertically(initialOffsetY = { it }),
41- exit = shrinkOut(shrinkTowards = Alignment .BottomCenter ) + slideOutVertically(targetOffsetY = { it })
31+ fun codeEditorSearcher () = codeEditor.searcher
32+ fun hasQuery () =
33+ searcher.query.isNotEmpty() && codeEditorSearcher().matchedPositionCount > 0
34+
35+ Column (
36+ modifier = Modifier
37+ .fillMaxWidth()
38+ .background(colorScheme.surfaceContainer)
39+ .padding(8 .dp)
4240 ) {
43- fun codeEditorSearcher () = codeEditor.searcher
44- fun hasQuery () =
45- searcher.query.isNotEmpty() && codeEditorSearcher().matchedPositionCount > 0
41+ LaunchedEffect (Unit ) {
42+ if (searcher.query.isNotEmpty()) {
43+ codeEditor.searcher.search(
44+ searcher.query,
45+ EditorSearcher .SearchOptions (! searcher.caseSensitive, searcher.useRegex)
46+ )
47+ }
48+ }
4649
47- Column (
48- modifier = Modifier
49- .fillMaxWidth()
50- .background(colorScheme.surfaceContainer)
51- .padding(8 .dp)
52- ) {
53- LaunchedEffect (Unit ) {
54- if (searcher.query.isNotEmpty()) {
50+ TextField (
51+ modifier = Modifier .fillMaxWidth(),
52+ value = searcher.query,
53+ onValueChange = {
54+ searcher.query = it
55+ if (it.isEmpty()) {
56+ codeEditor.searcher.stopSearch()
57+ codeEditor.invalidate()
58+ } else {
5559 codeEditor.searcher.search(
56- searcher.query ,
60+ it ,
5761 EditorSearcher .SearchOptions (! searcher.caseSensitive, searcher.useRegex)
5862 )
5963 }
60- }
64+ },
65+ label = { Text (text = stringResource(R .string.find)) },
66+ )
67+
68+ Space (size = 4 .dp)
6169
62- TextField (
63- modifier = Modifier .fillMaxWidth(),
64- value = searcher.query,
65- onValueChange = {
66- searcher.query = it
67- if (it.isEmpty()) {
70+ TextField (
71+ modifier = Modifier .fillMaxWidth(),
72+ value = searcher.replace,
73+ onValueChange = { searcher.replace = it },
74+ label = { Text (text = stringResource(R .string.replace)) },
75+ )
76+
77+ Row (
78+ modifier = Modifier
79+ .fillMaxWidth()
80+ .padding(horizontal = 4 .dp),
81+ horizontalArrangement = Arrangement .Center
82+ ) {
83+ CheckableText (
84+ modifier = Modifier
85+ .weight(1f )
86+ .padding(12 .dp),
87+ checked = searcher.useRegex,
88+ onCheckedChange = {
89+ searcher.useRegex = it
90+ if (searcher.query.isEmpty()) {
6891 codeEditor.searcher.stopSearch()
6992 codeEditor.invalidate()
7093 } else {
7194 codeEditor.searcher.search(
72- it,
73- EditorSearcher .SearchOptions (! searcher.caseSensitive, searcher.useRegex)
95+ searcher.query,
96+ EditorSearcher .SearchOptions (
97+ ! searcher.caseSensitive,
98+ searcher.useRegex
99+ )
74100 )
75101 }
76102 },
77- label = { Text (text = stringResource(R .string.find)) },
78- )
79-
80- Space (size = 4 .dp)
81-
82- TextField (
83- modifier = Modifier .fillMaxWidth(),
84- value = searcher.replace,
85- onValueChange = { searcher.replace = it },
86- label = { Text (text = stringResource(R .string.replace)) },
103+ uncheckedBoxBackgroundColor = colorScheme.surfaceColorAtElevation(8 .dp),
104+ text = { Text (text = stringResource(R .string.regex)) }
87105 )
88106
89- Row (
107+ CheckableText (
90108 modifier = Modifier
91- .fillMaxWidth()
92- .padding(horizontal = 4 .dp),
93- horizontalArrangement = Arrangement .Center
94- ) {
95- CheckableText (
96- modifier = Modifier
97- .weight(1f )
98- .padding(12 .dp),
99- checked = searcher.useRegex,
100- onCheckedChange = {
101- searcher.useRegex = it
102- if (searcher.query.isEmpty()) {
103- codeEditor.searcher.stopSearch()
104- codeEditor.invalidate()
105- } else {
106- codeEditor.searcher.search(
107- searcher.query,
108- EditorSearcher .SearchOptions (
109- ! searcher.caseSensitive,
110- searcher.useRegex
111- )
112- )
113- }
114- },
115- uncheckedBoxBackgroundColor = colorScheme.surfaceColorAtElevation(8 .dp),
116- text = { Text (text = stringResource(R .string.regex)) }
117- )
118-
119- CheckableText (
120- modifier = Modifier
121- .weight(1f )
122- .padding(12 .dp),
123- checked = searcher.caseSensitive,
124- onCheckedChange = {
125- searcher.caseSensitive = it
126- if (searcher.query.isEmpty()) {
127- codeEditor.searcher.stopSearch()
128- codeEditor.invalidate()
129- } else {
130- codeEditor.searcher.search(
131- searcher.query,
132- EditorSearcher .SearchOptions (
133- ! searcher.caseSensitive,
134- searcher.useRegex
135- )
109+ .weight(1f )
110+ .padding(12 .dp),
111+ checked = searcher.caseSensitive,
112+ onCheckedChange = {
113+ searcher.caseSensitive = it
114+ if (searcher.query.isEmpty()) {
115+ codeEditor.searcher.stopSearch()
116+ codeEditor.invalidate()
117+ } else {
118+ codeEditor.searcher.search(
119+ searcher.query,
120+ EditorSearcher .SearchOptions (
121+ ! searcher.caseSensitive,
122+ searcher.useRegex
136123 )
137- }
138- },
139- uncheckedBoxBackgroundColor = colorScheme.surfaceColorAtElevation(8 .dp),
140- text = { Text (text = stringResource(R .string.case_sensitive)) }
141- )
142- }
143-
144- Row (
145- modifier = Modifier .fillMaxWidth()
146- ) {
147- Space (size = 8 .dp)
148- OutlinedButton (
149- onClick = {
150- if (hasQuery()) codeEditorSearcher().replaceCurrentMatch(searcher.replace)
124+ )
151125 }
152- ) {
153- Text (text = stringResource(R .string.rep))
126+ },
127+ uncheckedBoxBackgroundColor = colorScheme.surfaceColorAtElevation(8 .dp),
128+ text = { Text (text = stringResource(R .string.case_sensitive)) }
129+ )
130+ }
131+
132+ Row (
133+ modifier = Modifier .fillMaxWidth()
134+ ) {
135+ Space (size = 8 .dp)
136+ OutlinedButton (
137+ onClick = {
138+ if (hasQuery()) codeEditorSearcher().replaceCurrentMatch(searcher.replace)
154139 }
155- Space (size = 8 .dp)
156- OutlinedButton (
157- onClick = {
158- if (hasQuery()) codeEditorSearcher().replaceAll(searcher.replace )
159- }
160- ) {
161- Text (text = stringResource( R .string.all) )
140+ ) {
141+ Text (text = stringResource( R .string.rep))
142+ }
143+ Space (size = 8 .dp )
144+ OutlinedButton (
145+ onClick = {
146+ if (hasQuery()) codeEditorSearcher().replaceAll(searcher.replace )
162147 }
163- Space (size = 8 .dp)
164- OutlinedButton (
165- modifier = Modifier .weight( 1f ),
166- onClick = {
167- if (hasQuery()) codeEditorSearcher().gotoPrevious()
168- }
169- ) {
170- Text (text = stringResource( R .string.prev) )
148+ ) {
149+ Text (text = stringResource( R .string.all))
150+ }
151+ Space (size = 8 .dp)
152+ OutlinedButton (
153+ modifier = Modifier .weight( 1f ),
154+ onClick = {
155+ if (hasQuery()) codeEditorSearcher().gotoPrevious( )
171156 }
172- Space (size = 8 .dp)
173- OutlinedButton (
174- modifier = Modifier .weight( 1f ),
175- onClick = {
176- if (hasQuery()) codeEditorSearcher().gotoNext()
177- }
178- ) {
179- Text (text = stringResource( R .string.next) )
157+ ) {
158+ Text (text = stringResource( R .string.prev))
159+ }
160+ Space (size = 8 .dp)
161+ OutlinedButton (
162+ modifier = Modifier .weight( 1f ),
163+ onClick = {
164+ if (hasQuery()) codeEditorSearcher().gotoNext( )
180165 }
181- Space (size = 8 .dp)
166+ ) {
167+ Text (text = stringResource(R .string.next))
182168 }
169+ Space (size = 8 .dp)
183170 }
184171 }
185172}
0 commit comments