KodeEditor - A simple code editor with syntax highlighting and pinch to zoom

Overview

KodeEditor

A simple code editor with syntax highlighting and pinch to zoom

Editing Scroll and zoom Minimap

Build Status

Master
codebeat badge

Features

  • Pinch-To-Zoom
  • Line numbers
  • Syntax highlighting
    • import languages you need
    • or simply create your own highlighter using regex or other techniques
    • themes
  • "Minimap" style document overview
  • Written entirely in Kotlin

How to use

Have a look at the demo app (app module) for a complete sample.

Gradle

To use this library just include it in your dependencies using

repositories {
    ...
    maven { url "https://jitpack.io" }
}

in your project build.gradle file and

dependencies {
    ...

    def codeEditorVersion = "v4.0.1"
    implementation("com.github.markusressel:KodeEditor:${codeEditorVersion}")
}

in your desired module build.gradle file.

Add to your layout

To use this editor simply add something similar to this to your desired layout xml file:

">

Syntax highlighting

Language Autodetection

Currently there is no auto detection for the language used in a document. You have to manage the syntax highlighter yourself and call the setSyntaxHighlighter method when appropriate.

Integrated syntax highlighters

Have a look at the KodeHighlighter section about this.

Writing a custom syntax highlighter

Have a look at the KodeHighlighter section about this.

Styling

KodeEditor can be styled in multiple ways:

  1. xml attributes on KodeEditor
  2. theme attributes in your custom theme
  3. methods on the view object itself

Theme Attributes

Name Description Type Default
ke_lineNumbers_textColor Specifies the text color of line numbers Color android.R.attr.textColorPrimary
ke_lineNumbers_backgroundColor Specifies the background color of the line numbers view Color android.R.attr.windowBackground
ke_divider_enabled Specifies if a divider should be drawn between line numbers and the actual code editor content Boolean true
ke_divider_color Specifies the color of the divider (has no effect if ke_divider_enabled is set to false) Color android.R.attr.textColorPrimary
ke_editor_backgroundColor Specifies the background color of the code editor view Color android.R.attr.windowBackground
ke_editor_maxZoom Specifies the maximum zoom level of the editor Float 10
ke_minimap_enabled Enables the minimap Boolean true
ke_minimap_maxDimension Specifies the maximum dimension of the minimap for both axis Dimension 150dp
ke_minimap_borderColor Specifies the border color of the minimap Color Color.BLACK
ke_minimap_indicatorColor Specifies the color of the minimap indicator Color Color.RED

You can either use those attributes directly on the view in your layout like this:

">

or specify them in your application theme (styles.xml in dem app) for to apply a style globally:

@color/colorPrimary @color/colorPrimaryDark @color/colorAccent #ccc #000 false #000 #fff 10.0 true true 200dp [...] ">


    
    


APIs

All styling attributes can also be specified using code. Since KodeEditorLayout is just a wrapper to extend the CodeEditorView with line numbers and the minimap to use some of those methods you need to access the matching property of the KodeEditorLayout first.

KodeEditorLayout

Name Description Type
text Sets the given text in the editor. String
setText(@StringRes) Sets the given string resource as the text in the editor. Int
languageRuleBook Gets/Sets the active language rule book used for highlighting. Use null to disable highlighting altogether. LanguageRuleBook?
editable Gets/Sets if the editor content is editable. Boolean

Line numbers

Name Description Type
showDivider Gets/Sets if the divider between line numbers and code editor is shown. Boolean
lineNumberGenerator Sets text to show for line number based on total number of lines (Long) -> List

Minimap

Name Description Type
showMinimap Gets/Sets if the minimap is shown. Boolean
minimapMaxDimension Gets/Sets the maximum dimension of the minimap in pixels. Float
minimapBorderWidth Gets/Sets the minimap border size in in pixels. Number
minimapBorderColor Gets/Sets the minimap border color. @ColorInt
minimapIndicatorColor Gets/Sets the minimap indicator color. @ColorInt
minimapGravity Gets/Sets the minimap positioning gravity. Int

CodeEditorView

To acces these API methods use the codeEditorLayout.codeEditorView property.

Name Description Type
text Sets the given text in the editor. String
setText(@StringRes) Sets the given string resource as the text in the editor. Int
getLineCount() Returns the current line count. Long
languageRuleBook Gets/Sets the active language rule book used for highlighting. Use null to disable highlighting altogether. LanguageRuleBook?
editable Gets/Sets if the editor content is editable. Boolean
hasSelection True when a range is selected. Boolean
selectionStart The start index of the current selection. Int
selectionEnd The end index of the current selection. Int
selectionChangedListener Gets/Sets the Listener for selection changes. SelectionChangedListener?

Contributing

GitHub is for social coding: if you want to write code, I encourage contributions through pull requests from forks of this repository. Create GitHub tickets for bugs and new features and comment on the ones that you are interested in.

License

MIT License

Copyright (c) 2018 Markus Ressel

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.
Comments
  • Gradle sync error. Failed to resolve com.github.markusressel.KodeEditor.

    Gradle sync error. Failed to resolve com.github.markusressel.KodeEditor.

    Describe the bug When trying to sync Gradle. Shows this error:

    ERROR: Failed to resolve: com.github.markusressel.KodeEditor:library:v2.1.1
    Show in Project Structure dialog
    Affected Modules: app
    

    To Reproduce Steps to reproduce the behavior:

    1. Add maven { url "https://jitpack.io" } to build.gradle (project)
    2. Add def codeEditorVersion = "v2.1.1" implementation("com.github.markusressel.KodeEditor:library:${codeEditorVersion}") to dependencies in build.gradle(module app)
    3. Sync Gradle
    4. See error

    Expected behavior Successfully sync Gradle and add libraries to the project.

    Screenshots image

    Smartphone

    • Device: [ OPPO A3S (CPH1853) ]
    • OS: [ Android 8.1 ]
    bug 
    opened by yeppiidev 12
  •  java.lang.IllegalArgumentException: Cannot round NaN value.

    java.lang.IllegalArgumentException: Cannot round NaN value.

    10-06 09:17:17.796 29733-29733/com.apkzube.learnpythonpro E/AndroidRuntime: FATAL EXCEPTION: main Process: com.apkzube.learnpythonpro, PID: 29733 java.lang.IllegalArgumentException: Cannot round NaN value. at kotlin.math.MathKt__MathJVMKt.roundToInt(MathJVM.kt:1132) at de.markusressel.kodeeditor.library.view.CodeEditorLayout$updateLineNumbers$1.run(CodeEditorLayout.kt:477) at android.os.Handler.handleCallback(Handler.java:742) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:157) at android.app.ActivityThread.main(ActivityThread.java:5603) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:774) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:652)

    bug 
    opened by Vpn97 7
  • Fixed dark theme editor background color

    Fixed dark theme editor background color

    When using the view on a dark theme system, editor background was white. I fixed it adding android.R.attr.windowBackground in default values, as said in the documentation.

    image

    opened by NathanFallet 5
  • Added support for custom line number generation

    Added support for custom line number generation

    Hey!

    Loved your project and decided to use it in my personal project but there was a little feature missing from it which was custom lines support. So forked it and added a property to allow changing this behavior. If the code up to par or the feature is not unnecessary, you can merge it.

    opened by UbadahJ 4
  • Failed to resolve: com.github.markusressel.KodeEditor:v3.0.2

    Failed to resolve: com.github.markusressel.KodeEditor:v3.0.2

    Describe the bug Hi, I was trying to use this module (KodeEditor) By following the instructions written in the README.md file. When i was syncing build.gradle, an error occurred : Failed to resolve: com.github.markusressel.KodeEditor:v3.0.2: Affected Modules: app

    To Reproduce Steps to reproduce the behavior:

    1. Adding maven { url "https://jitpack.io" } into build.gradle (Project)
    2. Adding def codeEditorVersion = "v3.0.2" implementation("com.github.markusressel.KodeEditor:${codeEditorVersion}") to the build.gradle (Module: App)
    3. Sync gradle
    4. See error

    Expected behavior Gradle synced successfully

    Screenshots Screenshot from 2020-08-03 21-01-41

    Smartphone (please complete the following information):

    • minSdk 21
    • targetSdk 30
    • buildToolsVersion 30.0.1
    opened by Iyxan23 2
  • Fixed two other missing default colors

    Fixed two other missing default colors

    Updating to 4.0.0, I noticed that two other defaults are missing... so adding them in code.

    image image

    (And this time I checked all colors, no others are missing)

    opened by NathanFallet 1
  • Use AndroidX instead of Android Support

    Use AndroidX instead of Android Support

    Describe the bug Using Android Support views in an AndroidX app prevent the app to build (gradle errors)

    To Reproduce Steps to reproduce the behavior:

    1. Create an AndroidX app
    2. Import KodeEditor and use it somewhere
    3. Build the app
    4. See error

    Screenshots image image

    Additional context https://github.com/markusressel/KodeEditor/blob/ee19acd833bf6beec35dec4333852f834c9ddac1/library/build.gradle#L36-L37

    Also see this question on StackOverflow explaining the problem: https://stackoverflow.com/questions/55217992/manifest-merger-failed-attribute-applicationappcomponentfactory-androidx

    enhancement 
    opened by NathanFallet 1
  • Extract syntax highlighting to seperate repository

    Extract syntax highlighting to seperate repository

    Syntax highlighting of spannables shouldn't be tied to the code editor. Therefore it should be extracted to a separate library called KodeHighlighter. Maybe the CodeTextView could be part of it too but I'm not sure about this yet.

    opened by markusressel 1
  • Minimap positioning gravity

    Minimap positioning gravity

    Is your feature request related to a problem? Please describe. Sometimes the minimap can get in the way of the editor content, due to its size and static positioning.

    Describe the solution you'd like Provide a gravity setting (left, top, right, bottom), that allows a user to position the minimap along the editor view border.

    Describe alternatives you've considered Provide an api to set the specific location and dimensions of the minimap.

    enhancement 
    opened by markusressel 0
  • Follow cursor movement

    Follow cursor movement

    Is your feature request related to a problem? Please describe. When editing a document the cursor can go offscreen.

    Describe the solution you'd like The view should follow the cursor maintaining the current zoom level.

    enhancement 
    opened by markusressel 0
  • CodeEditorView.text returns

    CodeEditorView.text returns "null" when called too early

    Describe the bug CodeEditorView.text returns a "null" string instead of an actual null value or an empty string when asked too early.

    This is because of the way the current text is retrieved in this lines:

    var text: String
      get() = codeEditText.text.toString()
    

    where text is an Editable that may be null and the toString() is the kotlin extension function that can handle null values which in this case is not desirable.

    To Reproduce Steps to reproduce the behavior: Call codeEditorView.text before a text has been set either by code or layout phase (I an empty string will have been set automatically by the time the view is rendered).

    Expected behavior return an empty string or an actual null value.
    Imo the null value doesn't add any useful information to the method so I think just returning an empty string and in doing so keeping the non-nullability of the property is better.

    bug 
    opened by markusressel 0
  • Text color for editor background in CodeEditorLayout

    Text color for editor background in CodeEditorLayout

    How to change the text color for the background text in the CodeEditorLayout?

    By default, it's black in color. I have tried android:textColor="@color/white" but its not working.

    Maybe something like app:ke_editor_textColor similar to app:ke_lineNumbers_textColor can help in this.

    enhancement 
    opened by spongycode 1
  • Color is not resolved correctly

    Color is not resolved correctly

    I though this would work, but it seems that color is not resolved correctly here: (and same thing a few lines later because it is used twice) https://github.com/markusressel/KodeEditor/blob/6e5e2f6840c261551a15b9c2ca1a343c8fe608e4/library/src/main/java/de/markusressel/kodeeditor/library/view/CodeEditorLayout.kt#L264

    Seems to be linked to this, but don't know how to fix it without breaking everything: https://stackoverflow.com/a/46477727/8261566

    bug 
    opened by NathanFallet 0
  • Automatic line wrapping

    Automatic line wrapping

    Is your feature request related to a problem? Please describe. Navigating long lines can be cumbersome.

    Describe the solution you'd like Allow automatic line wrapping. Wrapped lines should not increase line count.

    enhancement 
    opened by markusressel 0
Releases(v4.0.1)
  • v4.0.1(May 24, 2021)

  • v4.0.0(May 24, 2021)

    What’s Changed

    • Fixed dark theme editor background color (#41) by @NathanFallet

    🚀 Features and ✨ Enhancements

    • androidx migration (#42) by @markusressel
    Source code(tar.gz)
    Source code(zip)
  • v3.0.3(Apr 10, 2021)

    What’s Changed

    • Added support for custom line number generation (#38) by @UbadahJ

    🐛 Bugfixes

    • Bugfix/#37 NaN when visibility gone (#39) by @markusressel
    Source code(tar.gz)
    Source code(zip)
  • v3.0.2(Jun 29, 2020)

  • v3.0.1(Jun 29, 2020)

    What’s Changed

    • Feature/#18 kotlin flow (#31) by @markusressel

    🚀 Features and ✨ Enhancements

    • added parameter to set minimap positioning gravity (#32) by @markusressel
    Source code(tar.gz)
    Source code(zip)
  • v3.0.0(Jun 26, 2020)

    What’s Changed

    • AndroidX migration
    • Updated KodeHighlighter to v2.0.0, including breaking changes

    🚀 Features and ✨ Enhancements

    • Feature/#25 follow cursor movement (#27) by @markusressel

    🐛 Bugfixes

    • fixes #24 (#28) by @markusressel
    Source code(tar.gz)
    Source code(zip)
  • v2.1.1(Feb 10, 2019)

    What’s Changed

    Updated mininum SDK to 19 (from 16)

    🚀 Features and ✨ Enhancements

    • Feature/on selection changed listener (#23) by @markusressel

    🐛 Bugfixes

    • styling fixes (#22) by @markusressel
    Source code(tar.gz)
    Source code(zip)
  • v2.1.0(Feb 5, 2019)

    What’s Changed

    🚀 Features and ✨ Enhancements

    • Feature/minimap styling (#21) by @markusressel

    🐛 Bugfixes

    • fix minimap for editable=false (#20) by @markusressel
    Source code(tar.gz)
    Source code(zip)
  • v2.0.0(Feb 4, 2019)

  • v1.0.0(Jan 28, 2019)

    What’s Changed

    • Many bugfixes
    • Extract syntaxhighlighter (#16) by @markusressel
    • Extract syntax highlighter to separate library (#15) by @markusressel
    • added telegram script (#3) by @markusressel
    • disable hyphenation on line number textview and codeeditor as well (#2) by @markusressel

    🚀 Features and ✨ Enhancements

    • Fixed linenumbers (#5) by @markusressel
    Source code(tar.gz)
    Source code(zip)
Owner
Markus Ressel
❤️ Open Source 📱 Mobile App Development 💡 Home Automation 🔐 Typed Languages 🏍 Motorcycling
Markus Ressel
This repository contains a simple script that lets you kill gradle and kotlin daemons.

AndroidDaemonKiller This repository contains a simple script that lets you kill gradle and kotlin daemons. After updating gradle or kotlin or checking

Paul Woitaschek 25 Dec 3, 2022
A simple and scalable Android bot emulation framework, as presented at Black Hat Europe's Arsenal

m3 A simple and scalable Android bot emulation framework. A detailed explanation can be found here. This project was first published at Black Hat Euro

null 22 Aug 20, 2022
Multitask、MultiThread(MultiConnection)、Breakpoint-resume、High-concurrency、Simple to use、Single/NotSingle-process

FileDownloader Android multi-task file download engine. 中文文档 FileDownloader2 Now, FileDownloader2-OkDownload is released, okdownload will contain all

LAIX Inc. (formerly LingoChamp Inc.) 10.7k Jan 3, 2023
A simple screen starter written in kotlin

screen-starter A simple screen starter written in kotlin. Compilation Use clean shadowJar! Usage Use java -jar screen-starter-1.0-SNAPSHOT.jar --confi

GrowlyX 3 Sep 1, 2021
Simple Artificial Neural Network java library

SANN Simple Artificial Neural Network java library WIP Creating neural network Variant 1 //create new net (input, hidden, default len, output) Net net

Korpusov Maxim 14 Oct 11, 2022
Simple system for building dialogue in Cepi

Dialogue Dialogue builder for Cepi Installation Download the jar from Releases OR compile it yourself. Instructions to do so are in Compile header Dro

Cepi 2 Dec 14, 2022
Create a simple one screen application with scrollable table view

Create a simple one screen application with scrollable table view

Nikola Crnogorac 0 Jan 2, 2023
Simple spring boot JWT authentication example

JWT authentication This an example how to set up jwt authentication with access and refresh token. Related blog post is available here: https://coding

null 1 Feb 9, 2022
****. Use the native and support library variants instead - https://developer.android.com/guide/topics/ui/look-and-feel/fonts-in-xml.html. An android library that makes it easy to add custom fonts to edittexts and textviews

Add to your project Add this line to your dependencies in build.gradle compile 'in.workarounds.typography:typography:0.0.8' Using the views There are

Workarounds 43 Nov 6, 2021
SL4A brings scripting languages to Android by allowing you to edit and execute scripts and interactive interpreters directly on the Android device.

#Scripting Layer for Android (SL4A) SL4A brings scripting languages to Android by allowing you to edit and execute scripts and interactive interpreter

Damon Kohler 2.3k Dec 23, 2022
An application for runners and cyclists. Allows you to monitor your physical activity, weight and receive reminders about workouts.

An application for runners and cyclists. Allows you to monitor your physical activity, weight and receive reminders about workouts.

Just_Amalll 3 Feb 7, 2022
A curated list of standards, tests and benchmarks that can be used for testing and evaluating dev-tools

A curated list of standards, tests and benchmarks that can be used for testing and evaluating dev tools Contribution Add the description of the benchm

null 13 Dec 16, 2022
A gradle plugin for getting java lambda support in java 6, 7 and android

Gradle Retrolambda Plugin This plugin will automatically build your java or android project with retrolambda, giving you lambda goodness on java 6 or

Evan Tatarka 5.3k Jan 5, 2023
A Job Queue specifically written for Android to easily schedule jobs (tasks) that run in the background, improving UX and application stability.

Development in this repository is stopped. Future development continues on https://github.com/yigit/android-priority-jobqueue ========================

Path Mobile Inc Pte. Ltd. 2.4k Dec 9, 2022
An android library for displaying fps from the choreographer and percentage of time with two or more frames dropped

DEPRECATED TinyDancer is deprecated. No more development will be taking place. Check out the Google Android developer documentation for UI performance

Friendly Robot 1.9k Jan 3, 2023
📄The reliable, generic, fast and flexible logging framework for Android

logback-android v2.0.0 Overview logback-android brings the power of logback to Android. This library provides a highly configurable logging framework

Tony Trinh 1.1k Jan 8, 2023
It makes a preview from an url, grabbing all the information such as title, relevant texts and images. This a version for Android of my web link preview https://github.com/LeonardoCardoso/Link-Preview

LeoCardz Link Preview for Android It makes a preview from an url, grabbing all the information such as title, relevant texts and images. Visual Exampl

Leonardo Cardoso 420 Nov 19, 2022
A plug and play ;) android library for displaying a "rate this app" dialog

Easy Rating Dialog This lib provides a simple way to display an alert dialog for rating app. Default conditions to show: User opened the app more than

Fernando Martínez 111 Dec 30, 2022
AudioPlayerView is an Android view that loads audio from an url and have basic playback tools.

AudioPlayerView AudioPlayerView is an Android view that loads audio from an url and have basic playback tools. It makes use of the Android MediaPlayer

Hugo Matilla 86 Nov 29, 2022