diff --git a/README.md b/README.md index f16acc0..1e94714 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,7 @@ allprojects { ```groovy dependencies { ... - implementation 'com.github.ahmadaghazadeh:CodeEditor:1.0.15' + implementation 'com.github.ahmadaghazadeh:CodeEditor:1.0.16' } ``` diff --git a/app/src/main/java/com/github/ahmadaghazadeh/sample/MainActivity.java b/app/src/main/java/com/github/ahmadaghazadeh/sample/MainActivity.java index 81df71d..a5ebb6f 100644 --- a/app/src/main/java/com/github/ahmadaghazadeh/sample/MainActivity.java +++ b/app/src/main/java/com/github/ahmadaghazadeh/sample/MainActivity.java @@ -13,13 +13,14 @@ public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - CodeModel codeModel = new CodeModel("", "html"); + CodeModel codeModel = new CodeModel("111111111111111111", "html"); ActivityMainBinding mViewDataBinding = DataBindingUtil.setContentView(this, R.layout.activity_main); mViewDataBinding.setVariable(BR.viewModel, codeModel); mViewDataBinding.setLifecycleOwner(this); -// mViewDataBinding.editor.setOnTextChange(str -> { -// Toast.makeText(this,str,Toast.LENGTH_LONG).show(); -// }); + mViewDataBinding.editor.setOnTextChange(str -> { + Toast.makeText(this, mViewDataBinding.editor.getText(),Toast.LENGTH_LONG).show(); + }); + } diff --git a/library/src/main/java/com/github/ahmadaghazadeh/editor/widget/CodeEditor.java b/library/src/main/java/com/github/ahmadaghazadeh/editor/widget/CodeEditor.java index dd6f162..d158d9c 100644 --- a/library/src/main/java/com/github/ahmadaghazadeh/editor/widget/CodeEditor.java +++ b/library/src/main/java/com/github/ahmadaghazadeh/editor/widget/CodeEditor.java @@ -36,6 +36,11 @@ public class CodeEditor extends FrameLayout { boolean isShowExtendedKeyboard = false; int preHeight = 0; private Context context; + + public TextProcessor getTextProcessor() { + return editor; + } + private TextProcessor editor; private Language language; private LinesCollection lineNumbers; @@ -414,20 +419,20 @@ public void setText(String text, int flag) { if (text != null) { setText(Editable.Factory.getInstance().newEditable(text), flag); } else { - setText("", flag); + setText(Editable.Factory.getInstance().newEditable(""), flag); } } public void setText(Editable text, int flag) { if (flag == 1) { - this.text = text; + // this.text = text; if (editor != null) - editor.setText(this.text); + editor.setText(text); return; } int length = 0; - if (this.text != null) { - length = this.text.length(); + if (text != null) { + length = text.length(); } replaceText(0, length, text); setDirty(false);