@@ -39,8 +39,10 @@ public class CodeView extends AppCompatMultiAutoCompleteTextView {
3939 private int mUpdateDelayTime = 500 ;
4040
4141 private boolean modified = true ;
42- private boolean hasErrors ;
43- private boolean mRemoveErrorsWhenTextChanged ;
42+ private boolean highlightWhileTextChanging = true ;
43+
44+ private boolean hasErrors = false ;
45+ private boolean mRemoveErrorsWhenTextChanged = true ;
4446
4547 private final Handler mUpdateHandler = new Handler ();
4648 private MultiAutoCompleteTextView .Tokenizer mAutoCompleteTokenizer ;
@@ -194,8 +196,9 @@ private void createBackgroundColorSpan(Editable editable, Matcher matcher, @Colo
194196 }
195197
196198 private Editable highlight (Editable editable ) {
199+ if (editable .length () == 0 ) return editable ;
200+
197201 try {
198- if (editable .length () == 0 ) return editable ;
199202 clearSpans (editable );
200203 highlightErrorLines (editable );
201204 highlightSyntax (editable );
@@ -213,7 +216,7 @@ private void highlightWithoutChange(Editable editable) {
213216 }
214217
215218 public void setTextHighlighted (CharSequence text ) {
216- if (text == null ) text = "" ;
219+ if (text == null || text . length () == 0 ) return ;
217220
218221 cancelHighlighterRender ();
219222
@@ -349,6 +352,10 @@ public int getUpdateDelayTime() {
349352 return mUpdateDelayTime ;
350353 }
351354
355+ public void setHighlightWhileTextChanging (boolean updateWhileTextChanging ) {
356+ this .highlightWhileTextChanging = updateWhileTextChanging ;
357+ }
358+
352359 @ Override
353360 public void showDropDown () {
354361 int [] screenPoint = new int [2 ];
@@ -390,20 +397,29 @@ public void beforeTextChanged(CharSequence charSequence, int start, int before,
390397
391398 @ Override
392399 public void onTextChanged (CharSequence charSequence , int start , int before , int count ) {
400+ if (!modified ) return ;
401+
402+ if (highlightWhileTextChanging ) {
403+ if (mSyntaxPatternMap .size () > 0 ) {
404+ convertTabs (getEditableText (), start , count );
405+ mUpdateHandler .postDelayed (mUpdateRunnable , mUpdateDelayTime );
406+ }
407+ }
408+
409+ if (mRemoveErrorsWhenTextChanged ) removeAllErrorLines ();
393410 }
394411
395412 @ Override
396413 public void afterTextChanged (Editable editable ) {
397- cancelHighlighterRender ();
398-
399- if (getSyntaxPatternsSize () > 0 ) {
400- convertTabs (editable , start , count );
401-
414+ if (!highlightWhileTextChanging ) {
402415 if (!modified ) return ;
403416
404- mUpdateHandler . postDelayed ( mUpdateRunnable , mUpdateDelayTime );
417+ cancelHighlighterRender ( );
405418
406- if (mRemoveErrorsWhenTextChanged ) removeAllErrorLines ();
419+ if (mSyntaxPatternMap .size () > 0 ) {
420+ convertTabs (getEditableText (), start , count );
421+ mUpdateHandler .postDelayed (mUpdateRunnable , mUpdateDelayTime );
422+ }
407423 }
408424 }
409425 };
0 commit comments