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.
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.
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)
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.
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.
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:
Adding maven { url "https://jitpack.io" } into build.gradle (Project)
Adding def codeEditorVersion = "v3.0.2" implementation("com.github.markusressel.KodeEditor:${codeEditorVersion}") to the build.gradle (Module: App)
Sync gradle
See error
Expected behavior
Gradle synced successfully
Screenshots
Smartphone (please complete the following information):
Also see this question on StackOverflow explaining the problem: https://stackoverflow.com/questions/55217992/manifest-merger-failed-attribute-applicationappcomponentfactory-androidx
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.
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.
Describe the bugCodeEditorView.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.
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