@@ -49,9 +49,11 @@ abstract class LineNumbersEditText @JvmOverloads constructor(
4949 override fun beforeTextChanged (s : CharSequence? , start : Int , count : Int , after : Int ) {
5050 doBeforeTextChanged(s, start, count, after)
5151 }
52+
5253 override fun onTextChanged (s : CharSequence? , start : Int , before : Int , count : Int ) {
5354 doOnTextChanged(s, start, before, count)
5455 }
56+
5557 override fun afterTextChanged (s : Editable ? ) {
5658 doAfterTextChanged(s)
5759 }
@@ -68,12 +70,17 @@ abstract class LineNumbersEditText @JvmOverloads constructor(
6870 InputType .TYPE_TEXT_FLAG_NO_SUGGESTIONS
6971 }
7072
71- open fun doBeforeTextChanged (text : CharSequence? , start : Int , count : Int , after : Int ) {
73+ protected open fun doBeforeTextChanged (
74+ text : CharSequence? ,
75+ start : Int ,
76+ count : Int ,
77+ after : Int
78+ ) {
7279 textChangeStart = start
7380 textChangeEnd = start + count
7481 }
7582
76- open fun doOnTextChanged (text : CharSequence? , start : Int , before : Int , count : Int ) {
83+ protected open fun doOnTextChanged (text : CharSequence? , start : Int , before : Int , count : Int ) {
7784 textChangedNewText = text?.subSequence(start, start + count) ? : " "
7885 replaceText(textChangeStart, textChangeEnd, textChangedNewText)
7986 val startLine = structure.getLineForIndex(textChangeStart)
@@ -87,7 +94,15 @@ abstract class LineNumbersEditText @JvmOverloads constructor(
8794 }
8895 }
8996
90- open fun doAfterTextChanged (text : Editable ? ) = Unit
97+ protected open fun doAfterTextChanged (text : Editable ? ) = Unit
98+
99+ protected open fun processLine (lineNumber : Int , lineStart : Int , lineEnd : Int ) = Unit
100+
101+ protected open fun addLine (lineNumber : Int , lineStart : Int ) =
102+ structure.add(lineNumber, lineStart)
103+
104+ protected open fun removeLine (lineNumber : Int ) =
105+ structure.remove(lineNumber)
91106
92107 open fun setTextContent (text : CharSequence ) {
93108 removeTextChangedListener(textWatcher)
@@ -103,7 +118,7 @@ abstract class LineNumbersEditText @JvmOverloads constructor(
103118 addTextChangedListener(textWatcher)
104119 }
105120
106- open fun replaceText (newStart : Int , newEnd : Int , newText : CharSequence ) {
121+ private fun replaceText (newStart : Int , newEnd : Int , newText : CharSequence ) {
107122 val start = if (newStart < 0 ) 0 else newStart
108123 val end = if (newEnd > structure.text.length) structure.text.length else newEnd
109124 val newCharCount = newText.length - (end - start)
@@ -124,14 +139,4 @@ abstract class LineNumbersEditText @JvmOverloads constructor(
124139 editable.replace(start, end, newText)
125140 }
126141 }
127-
128- open fun processLine (lineNumber : Int , lineStart : Int , lineEnd : Int ) = Unit
129-
130- open fun addLine (lineNumber : Int , lineStart : Int ) {
131- structure.add(lineNumber, lineStart)
132- }
133-
134- open fun removeLine (lineNumber : Int ) {
135- structure.remove(lineNumber)
136- }
137142}
0 commit comments