/text-editor-compose

A simple text editor library for Jetpack Compose

Primary LanguageKotlinMIT LicenseMIT

Android API kotlin License MIT

Text Editor Compose

A simple text editor for Jetpack Compose

✨Features

  • Edit multiple line text
  • Insert and delete newline
  • Get selected line index
  • Display line number
  • Copy multiple line
  • Delete multiple line
  • Support physical keyboard

🪄Usage

This library is easy to use, just follow the steps below to add a dependency and write codes.

Step 1: Add the JitPack repository to build.gradle

allprojects {
	repositories {
		...
		maven { url 'https://jitpack.io' }
	}
}

Step 2: Add the library to the dependencies

dependencies {
	implementation 'com.github.kaleidot725:text-editor-compose:0.6.0'
}

Step 3: Declare TextEditor & TextEditorState

class MainActivity : ComponentActivity() {
    @OptIn(ExperimentalComposeUiApi::class)
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
	
        setContent {
            SampleTheme {
                var textEditorState by remember { mutableStateOf(TextEditorState.create(DemoText)) }
		val bottomPaddingValue = with(LocalDensity.current) { WindowInsets.ime.getBottom(this).toDp() }
                val contentPaddingValues = PaddingValues(bottom = bottomPaddingValue)
		
                Box(modifier = Modifier.fillMaxSize().systemBarsPadding()) {
                    TextEditor(
                        textEditorState = textEditorState,
                        onChanged = { textEditorState = it },
                        contentPaddingValues = contentPaddingValues,
                    )
                }
            }
        }
    }
}

🧪Demo

Check out the demo code here.

No Title Movie
1 Edit multiple line text Edit multiple line text
2 Insert and delete newline Insert and delete newline
3 Copy multiple line Insert and delete newline
4 Delete multiple line Insert and delete newline

💡License

Copyright (c) 2022 Yusuke Katsuragawa

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.