This migration guide will help you adapt your existing code to match the latest version of EditorKit library.
- v2.4.0 -> v2.5.0
- v2.3.0 -> v2.4.0
- v2.2.0 -> v2.3.0
- v2.1.2 -> v2.1.3
- v2.0.0 -> v2.1.0
- v1.3.0 -> v2.0.0
- v1.2.1 -> v1.3.0
- v1.2.0 -> v1.2.1
- v1.1.0 -> v1.2.0
- v1.0.1 -> v1.1.0
- v1.0.0 -> v1.0.1
Migration steps:
- If you're using custom plugin DSL, change
PluginSupplier#plugin()
signature:// Before fun PluginSupplier.codeCompletion(block: AutoCompletePlugin.() -> Unit = {}) { plugin(AutoCompletePlugin(), block) } // After fun PluginSupplier.codeCompletion(block: AutoCompletePlugin.() -> Unit = {}) { plugin(AutoCompletePlugin().apply(block)) }
Migration steps:
- The
LanguageStyler
andLanguageParser
now takeTextStructure
as a parameter. This is a new class that contains text + metadata, which can help you to optimize the process. TheLanguageStyler
has no longer access toColorScheme
and span attributes. You have to provide a special token that represents the data type, the spans will be applied by the code editor itself.// Before class CustomStyler : LanguageStyler { override fun execute(source: String, scheme: ColorScheme): List<SyntaxHighlightSpan> { val syntaxHighlightSpans = mutableListOf<SyntaxHighlightSpan>() // Before val styleSpan = StyleSpan(scheme.methodColor) val syntaxHighlightSpan = SyntaxHighlightSpan(styleSpan, matcher.start(), matcher.end()) syntaxHighlightSpans.add(syntaxHighlightSpan) return syntaxHighlightSpans } } // After class CustomStyler : LanguageStyler { override fun execute(structure: TextStructure): List<SyntaxHighlightResult> { val syntaxHighlightResults = mutableListOf<SyntaxHighlightResult>() // After val tokenType = TokenType.METHOD val syntaxHighlightResult = SyntaxHighlightResult(tokenType, matcher.start(), matcher.end()) syntaxHighlightResults.add(syntaxHighlightResult) return syntaxHighlightResults } }
- If you're using custom plugins, the
clearLines
andonTextReplaced
methods has been removed. ThebeforeDraw
andafterDraw
methods has been renamed todrawBehind
andonDraw
.
Migration steps:
- If you have a custom plugin that uses
setEmptyText
method, simply remove it. There is no alternative to this method. - JavaScript compiler has also been removed due to large amount of issues. It will be rewritten from scratch in the future.
Migration steps:
- If you're using custom languages, replace 'getName' method with
languageName
property.// Before override fun getName() { return "custom language" } // After override val languageName = "custom language"
Migration steps:
- Setup of the code editor was completely rewritten from scratch, the
EditorConfig
class was removed, you have to apply the settings by usingPluginSupplier
as shown below:You can enable/disable plugins in runtime by surrounding necessary methods with// Before editor.editorConfig = EditorConfig( fontSize = 14f, fontType = Typeface.MONOSPACE, wordWrap = true, codeCompletion = true, pinchZoom = true, lineNumbers = true, ... ) // After val pluginSupplier = PluginSupplier.create { codeCompletion { suggestionAdapter = ... } pinchZoom { // or simply pinchZoom() minTextSize = 10f maxTextSize = 20f } lineNumbers { // or simply lineNumbers() lineNumbers = true highlightCurrentLine = true } highlightDelimiters() autoIndentation() // ... } editor.plugins(pluginSupplier)
if (enabled) { ... }
operator:Since v2.1.0 there's no alternative toval pluginSupplier = PluginSupplier.create { if (preferences.isLineNumbersEnabled) { lineNumbers() } if (preferences.isPinchZoomEnabled) { pinchZoom() } // ... } editor.plugins(pluginSupplier)
fontSize
,fontType
and some other properties inPluginSupplier
, to configure these parameters use following methods:editor.setTextSize(14f) // previous `fontSize` editor.setTypeface(Typeface.MONOSPACE) // previous `fontType` editor.setHorizontallyScrolling(false) // previous `wordWrap` editor.softKeyboard = false // previous `softKeyboard` editor.useSpacesInsteadOfTabs = true // previous `useSpacesInsteadOfTabs` editor.tabWidth = 4 // previous `tabWidth`
FindParams
model now hasquery
property, which previously was passed to aTextProcessor.find()
method as the first argument:// Before val params = FindParams( regex = false, matchCase = true, wordsOnly = true ) editor.find("function", params) // After val params = FindParams( query = "function", regex = false, matchCase = true, wordsOnly = true ) editor.find(params)
- If you're using custom themes, the
SyntaxScheme
class was removed and all it's properties were moved inColorScheme
itself. - If you're using custom languages:
- Remove
enqueue()
andcancel()
methods inLanguageStyler
. Theexecute()
method now invoked on the background thread, so now you don't need to write the asynchronous work by yourself. - The
execute()
method now takesColorScheme
as the parameter since theSyntaxScheme
class was removed.class CustomStyler : LanguageStyler { override fun execute(source: String, scheme: ColorScheme): List<SyntaxHighlightSpan> { val syntaxHighlightSpans = mutableListOf<SyntaxHighlightSpan>() // TODO Implement syntax highlighting return syntaxHighlightSpans } }
- Remove
Migration steps:
- Change the package name from
com.brackeys.ui
tocom.blacksquircle.ui
- Everything else remains the same
Migration steps:
- If you're using custom themes, add new
variableColor
property to theSyntaxScheme
object
Migration steps:
- Change the groupId from
com.brackeys.ui
tocom.blacksquircle.ui
as shown below:// Before implementation 'com.brackeys.ui:editorkit:1.2.0' // After implementation 'com.blacksquircle.ui:editorkit:1.2.1'
- The package name
com.brackeys.ui
remains the same, but it will be changed in the future
Migration steps:
- If you're using
TextScroller
, rename it'slink()
method toattachTo()
as shown below:// Before scroller.link(editor) // After scroller.attachTo(editor)
Migration steps:
- Rename
Config
toEditorConfig
as shown below:// Before editor.config = Config(...) // After editor.editorConfig = EditorConfig(...)
Migration steps:
- Rename
ShortcutListener
toOnShortcutListener
as shown below:// Before editor.shortcutListener = object : ShortcutListener { ... } // After editor.onShortcutListener = object : OnShortcutListener { ... }