View Javadoc
1   package com.jsql.view.swing.text.action;
2   
3   import javax.swing.text.BadLocationException;
4   import javax.swing.text.DefaultEditorKit;
5   import javax.swing.text.Document;
6   
7   /**
8    * Action to cancel Beep sound when deleting last character.
9    * Used on TextPane and TextArea.
10   */
11  public class DeleteNextCharAction extends AbstractCharAction {
12      
13      /**
14       * Create this object with the appropriate identifier.
15       */
16      public DeleteNextCharAction() {
17          super(DefaultEditorKit.deleteNextCharAction);
18      }
19  
20      @Override
21      protected void delete(Document doc, int dot) throws BadLocationException {
22          if (dot < doc.getLength()) {
23              
24              var delChars = 1;
25  
26              if (dot < doc.getLength() - 1) {
27                  
28                  String dotChars = doc.getText(dot, 2);
29                  var c0 = dotChars.charAt(0);
30                  var c1 = dotChars.charAt(1);
31  
32                  if (c0 >= '\uD800' && c0 <= '\uDBFF' && c1 >= '\uDC00' && c1 <= '\uDFFF') {
33                      delChars = 2;
34                  }
35              }
36  
37              doc.remove(dot, delChars);
38          }
39      }
40  }