title: EDITTEXT Android : Need to control the cursor position (prevent or allow)
body: <p>I am developing an app where I am facing the below issue:</p>
  <p>Let's say I have the following expression : 5+9x6/6+SIN(8)+TAN(78) in a calculator app:</p>
  <p>So, what I am trying to achieve is that if the editText's current cursor was just after the N in TAN or the N in SIN or the S in COS, and given that the user decided to delete SIN, or COS or TAN, I want to delete the whole String at once (without having the user to delete each of the 3 chars one by one.</p>
  <p>That, I have managed to achieve using the below snippet:</p>
  <pre><code> int cursorPosition = editTxt.getSelectionStart();
                  try {
                      if (editTxt.getText().toString().substring(cursorPosition - 4, cursorPosition).equals(&quot;SIN&quot;) ||      ///runs if TAN, COS, or SIN were detected during deletion
                              editTxt.getText().toString().substring(cursorPosition - 4, cursorPosition).equals(&quot;COS&quot;) ||
                              editTxt.getText().toString().substring(cursorPosition - 4, cursorPosition).equals(&quot;TAN&quot;)) {
  
                          Toast.makeText(getApplicationContext(), &quot;here&quot;, Toast.LENGTH_SHORT).show();
  
                          editTxt.setText(editTxt.getText().delete(cursorPosition - 4, cursorPosition));
                          editTxt.setSelection(cursorPosition - 4);
                      }else{
                          ///here is the regular char delete process
                          editTxt.setText(editTxt.getText().delete(cursorPosition-1,cursorPosition));
                          editTxt.setSelection(cursorPosition-1);
                      }
                  }catch (Exception e){
                      editTxt.setText(editTxt.getText().delete(cursorPosition-1,cursorPosition));
                      editTxt.setSelection(cursorPosition-1);
                  }
  </code></pre>
  <p>BUT THE ISSUE HERE IS: If the user decides to delete the &quot;T&quot; from TAN, then I need to find a way, to delete the rest of the &quot;AN&quot;, in other words, I want to delete the whole string &quot;TAN&quot; if the user attempts to delete any of its chars, and the same for SIN and COS as well.</p>
  <p>Attached is a short GIF showing what I am trying to achieve (taken from Google Calculator). (Basically I want to prevent the user from setting the placing the cursor anywhere in between the &quot;TAN&quot; , <a href="https://i.stack.imgur.com/0C6yG.gif" rel="nofollow noreferrer">The way it works in Google Calculator</a>&quot;COS&quot; and &quot;SIN&quot;</p>