23
23
- [x] Display line number
24
24
- [x] Copy multiple line
25
25
- [x] Delete multiple line
26
- - [ ] Support physical keyboard
26
+ - [x ] Support physical keyboard
27
27
28
28
## Usage
29
29
@@ -44,139 +44,85 @@ allprojects {
44
44
45
45
``` groovy
46
46
dependencies {
47
- implementation 'com.github.kaleidot725:text-editor-compose:0.2 .0'
47
+ implementation 'com.github.kaleidot725:text-editor-compose:0.3 .0'
48
48
}
49
49
```
50
50
51
- ### Step 3: Declare TextEditor & TextEditorState
51
+ ### Step 3: Change windowSoftInputMode
52
52
53
- ``` kotlin
54
- class MainActivity : ComponentActivity () {
55
- override fun onCreate (savedInstanceState : Bundle ? ) {
56
- super .onCreate(savedInstanceState)
57
- setContent {
58
- SampleTheme {
59
- val textEditorState by rememberTextEditorState(lines = DemoText .lines())
60
- TextEditor (
61
- textEditorState = textEditorState,
62
- onUpdatedState = { },
63
- modifier = Modifier .fillMaxSize()
64
- )
65
- }
66
- }
67
- }
68
- }
53
+ ** AndroidManifest.xml**
54
+ ```
55
+ <?xml version="1.0" encoding="utf-8"?>
56
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android"
57
+ xmlns:tools="http://schemas.android.com/tools">
58
+
59
+ <application
60
+ android:allowBackup="true"
61
+ android:dataExtractionRules="@xml/data_extraction_rules"
62
+ android:fullBackupContent="@xml/backup_rules"
63
+ android:icon="@mipmap/ic_launcher"
64
+ android:label="@string/app_name"
65
+ android:roundIcon="@mipmap/ic_launcher_round"
66
+ android:supportsRtl="true"
67
+ android:theme="@style/Theme.Sample"
68
+ tools:targetApi="31">
69
+ <activity
70
+ android:name=".MainActivity"
71
+ android:exported="true"
72
+ android:label="@string/app_name"
73
+ android:theme="@style/Theme.Sample"
74
+ android:windowSoftInputMode="adjustResize" // !! ADD THIS LINE !!
75
+ >
76
+ <intent-filter>
77
+ <action android:name="android.intent.action.MAIN" />
78
+
79
+ <category android:name="android.intent.category.LAUNCHER" />
80
+ </intent-filter>
81
+ </activity>
82
+ </application>
83
+
84
+ </manifest>
69
85
```
70
-
71
- ### Step 4: Customize text fields
72
86
73
87
``` kotlin
74
88
class MainActivity : ComponentActivity () {
89
+ @OptIn(ExperimentalComposeUiApi ::class )
75
90
override fun onCreate (savedInstanceState : Bundle ? ) {
76
91
super .onCreate(savedInstanceState)
77
- setContent {
78
- SampleTheme {
79
- val textEditorState by rememberTextEditorState(lines = DemoText .lines())
80
- TextEditor (
81
- textEditorState = textEditorState,
82
- onUpdatedState = { },
83
- modifier = Modifier .fillMaxSize(),
84
- decorationBox = { index, isSelected, innerTextField ->
85
- val backgroundColor = if (isSelected) Color (0x8000ff00 ) else Color .White
86
- Row (modifier = Modifier .background(backgroundColor)) {
87
- Text (text = (index + 1 ).toString().padStart(3 , ' 0' ))
88
- Spacer (modifier = Modifier .width(4 .dp))
89
- innerTextField(modifier = Modifier .fillMaxWidth())
90
- }
91
- }
92
- )
93
- }
94
- }
95
- }
92
+
93
+ WindowCompat .setDecorFitsSystemWindows(window, false ) // !! ADD THIS LINE !!
94
+
95
+ }
96
96
}
97
97
```
98
98
99
- ### Step 5: Create multiple selection menu
99
+ ### Step 4: Declare TextEditor & TextEditorState
100
100
101
101
``` kotlin
102
102
class MainActivity : ComponentActivity () {
103
+ @OptIn(ExperimentalComposeUiApi ::class )
103
104
override fun onCreate (savedInstanceState : Bundle ? ) {
104
105
super .onCreate(savedInstanceState)
106
+
107
+ WindowCompat .setDecorFitsSystemWindows(window, false )
108
+
105
109
setContent {
106
110
SampleTheme {
107
- val textEditorState by rememberTextEditorState(lines = DemoText .lines())
108
- TextEditor (
109
- textEditorState = textEditorState,
110
- onUpdatedState = { },
111
- modifier = Modifier .fillMaxSize(),
112
- decorationBox = { index, isSelected, innerTextField ->
113
- val backgroundColor = if (isSelected) Color (0x8000ff00 ) else Color .White
114
- Row (modifier = Modifier .background(backgroundColor)) {
115
- Text (text = (index + 1 ).toString().padStart(3 , ' 0' ))
116
- Spacer (modifier = Modifier .width(4 .dp))
117
- innerTextField(modifier = Modifier .fillMaxWidth())
118
- }
119
- }
120
- )
121
- }
122
- }
123
- }
124
- }
125
-
126
- @Composable
127
- private fun ColumnScope.TextEditorMenu (textEditorState : TextEditorState ) {
128
- val context: Context = LocalContext .current
129
- val clipboardManager: ClipboardManager = LocalClipboardManager .current
130
-
131
- Row (modifier = Modifier .padding(8 .dp)) {
132
- Text (
133
- text = " Enable multiple selection mode" ,
134
- modifier = Modifier
135
- .weight(0.9f , true )
136
- .align(Alignment .CenterVertically )
137
- )
138
- Switch (
139
- checked = textEditorState.isMultipleSelectionMode.value,
140
- onCheckedChange = {
141
- textEditorState.enableMultipleSelectionMode(
142
- ! textEditorState.isMultipleSelectionMode.value
111
+ var textEditorState by remember { mutableStateOf(TextEditorState .create(DemoText )) }
112
+ val contentPaddingValues = PaddingValues (
113
+ bottom = with (LocalDensity .current) { WindowInsets .ime.getBottom(this ).toDp() }
143
114
)
144
- }
145
- )
146
- }
147
115
148
- Row (modifier = Modifier .padding(8 .dp)) {
149
- Text (
150
- text = " Copy selected lines" ,
151
- modifier = Modifier
152
- .weight(0.9f , true )
153
- .align(Alignment .CenterVertically )
154
- )
155
- Button (
156
- onClick = {
157
- val text = textEditorState.getSelectedText()
158
- textEditorState.enableMultipleSelectionMode(false )
159
-
160
- clipboardManager.setText(AnnotatedString (text))
161
- Toast .makeText(context, " Copy selected text to clipboard" , Toast .LENGTH_SHORT ).show()
116
+ Box (modifier = Modifier
117
+ .fillMaxSize()
118
+ .systemBarsPadding()) {
119
+ TextEditor (
120
+ textEditorState = textEditorState,
121
+ onChanged = { textEditorState = it },
122
+ contentPaddingValues = contentPaddingValues,
123
+ )
124
+ }
162
125
}
163
- ) {
164
- Text (text = " EXECUTE" )
165
- }
166
- }
167
-
168
- Row (modifier = Modifier .padding(8 .dp)) {
169
- Text (
170
- text = " Delete selected lines" ,
171
- modifier = Modifier
172
- .weight(0.9f , true )
173
- .align(Alignment .CenterVertically )
174
- )
175
- Button (onClick = {
176
- textEditorState.deleteSelectedLines()
177
- textEditorState.enableMultipleSelectionMode(false )
178
- }) {
179
- Text (text = " EXECUTE" )
180
126
}
181
127
}
182
128
}
@@ -192,18 +138,10 @@ private fun ColumnScope.TextEditorMenu(textEditorState: TextEditorState) {
192
138
193
139
![ Insert and delete newline] ( ./docs/2.gif )
194
140
195
- ### Get selected line index
196
-
197
- ![ Get selected line index] ( ./docs/3.gif )
198
-
199
- ### Display line number
200
-
201
- ![ Display line number] ( ./docs/4.gif )
202
-
203
141
### Copy multiple line
204
142
205
- ![ Copy multiple line] ( ./docs/5 .gif )
143
+ ![ Copy multiple line] ( ./docs/3 .gif )
206
144
207
145
### Delete multiple line
208
146
209
- ![ Delete multiple line] ( ./docs/6 .gif )
147
+ ![ Delete multiple line] ( ./docs/4 .gif )
0 commit comments