Skip to content

Commit

Permalink
Add protected visibility modifier
Browse files Browse the repository at this point in the history
  • Loading branch information
massivemadness committed Mar 20, 2023
1 parent c17c62f commit 1a0d1ea
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,11 @@ abstract class LineNumbersEditText @JvmOverloads constructor(
override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {
doBeforeTextChanged(s, start, count, after)
}

override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
doOnTextChanged(s, start, before, count)
}

override fun afterTextChanged(s: Editable?) {
doAfterTextChanged(s)
}
Expand All @@ -68,12 +70,17 @@ abstract class LineNumbersEditText @JvmOverloads constructor(
InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS
}

open fun doBeforeTextChanged(text: CharSequence?, start: Int, count: Int, after: Int) {
protected open fun doBeforeTextChanged(
text: CharSequence?,
start: Int,
count: Int,
after: Int
) {
textChangeStart = start
textChangeEnd = start + count
}

open fun doOnTextChanged(text: CharSequence?, start: Int, before: Int, count: Int) {
protected open fun doOnTextChanged(text: CharSequence?, start: Int, before: Int, count: Int) {
textChangedNewText = text?.subSequence(start, start + count) ?: ""
replaceText(textChangeStart, textChangeEnd, textChangedNewText)
val startLine = structure.getLineForIndex(textChangeStart)
Expand All @@ -87,7 +94,15 @@ abstract class LineNumbersEditText @JvmOverloads constructor(
}
}

open fun doAfterTextChanged(text: Editable?) = Unit
protected open fun doAfterTextChanged(text: Editable?) = Unit

protected open fun processLine(lineNumber: Int, lineStart: Int, lineEnd: Int) = Unit

protected open fun addLine(lineNumber: Int, lineStart: Int) =
structure.add(lineNumber, lineStart)

protected open fun removeLine(lineNumber: Int) =
structure.remove(lineNumber)

open fun setTextContent(text: CharSequence) {
removeTextChangedListener(textWatcher)
Expand All @@ -103,7 +118,7 @@ abstract class LineNumbersEditText @JvmOverloads constructor(
addTextChangedListener(textWatcher)
}

open fun replaceText(newStart: Int, newEnd: Int, newText: CharSequence) {
private fun replaceText(newStart: Int, newEnd: Int, newText: CharSequence) {
val start = if (newStart < 0) 0 else newStart
val end = if (newEnd > structure.text.length) structure.text.length else newEnd
val newCharCount = newText.length - (end - start)
Expand All @@ -124,14 +139,4 @@ abstract class LineNumbersEditText @JvmOverloads constructor(
editable.replace(start, end, newText)
}
}

open fun processLine(lineNumber: Int, lineStart: Int, lineEnd: Int) = Unit

open fun addLine(lineNumber: Int, lineStart: Int) {
structure.add(lineNumber, lineStart)
}

open fun removeLine(lineNumber: Int) {
structure.remove(lineNumber)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,11 @@ abstract class SyntaxHighlightEditText @JvmOverloads constructor(
syntaxHighlight()
}

open fun onLanguageChanged() {
protected open fun onLanguageChanged() {
syntaxHighlight()
}

open fun onColorSchemeChanged() {
protected open fun onColorSchemeChanged() {
findResultStyleSpan = StyleSpan(color = colorScheme.findResultBackgroundColor)
setTextColor(colorScheme.textColor)
setCursorDrawableColor(colorScheme.cursorColor)
Expand Down

0 comments on commit 1a0d1ea

Please sign in to comment.