Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(Firefox Android) Backspace at beginning of line error #54

Open
pablojan opened this issue Mar 27, 2017 · 1 comment
Open

(Firefox Android) Backspace at beginning of line error #54

pablojan opened this issue Mar 27, 2017 · 1 comment

Comments

@pablojan
Copy link
Contributor

In FF Android backspace keystroke at beginning of new line generates a set of composition events (IME) mutating the DOM but no a proper key event [1].

In this situation the editor tries to undo DOM changes (DomMutationReverter) when detecting the DOM events (EditorEventHandler.handleEventInner:346). Result is a inconsistency of the document in-memory model.

[1] Composition events:

("DOMNodeRemoved","BR")
("DOMSubtreeModified","DIV")
("DOMNodeInserted","BR")
("DOMSubtreeModified","DIV")
("DOMNodeRemoved","DIV")
("DOMSubtreeModified","UL")
("DOMNodeRemoved","BR")
("DOMSubtreeModified","DIV")
@pablojan
Copy link
Contributor Author

Here some code used to detect that event sequence:



  public static class DetectorState {
    String event;
    String target;
    
    public DetectorState(String e, String t) {
      this.event = e;
      this.target = t;
    }
    
  }
  private static DetectorState[] backspaceDetectorStateSpace = {
              new DetectorState("DOMNodeRemoved","BR"),
              new DetectorState("DOMSubtreeModified","DIV"),
              new DetectorState("DOMNodeInserted","BR"),
              new DetectorState("DOMSubtreeModified","DIV"),
              new DetectorState("DOMNodeRemoved","DIV"),
              new DetectorState("DOMSubtreeModified","UL"),
              new DetectorState("DOMNodeRemoved","BR"),
              new DetectorState("DOMSubtreeModified","DIV") };
  
  private int currentBackspaceDetectorState = 0;
      
...

      if (backspaceDetectorStateSpace[currentBackspaceDetectorState].event.equalsIgnoreCase(event.getType()) &&
          backspaceDetectorStateSpace[currentBackspaceDetectorState].target.equalsIgnoreCase(event.getTarget().getTagName())) {
        currentBackspaceDetectorState++;
      } else {
        currentBackspaceDetectorState = 0;
      }
           
      if (currentBackspaceDetectorState == 8) {
        currentBackspaceDetectorState = 0;
        EditorStaticDeps.logger.trace().log("Detected backspace mutation set");
        
        EditorStaticDeps.startIgnoreMutations();
        
        Point<ContentNode> caret;
        // refreshEditorWithCaret(event);
        caret = editorInteractor.getSelectionPoints().getAnchor();
        ContentNode node = caret.getContainer();
        ContentElement element = node.asElement();
        if (element == null)
          element = node.getParentElement();
        
        //node.getMutableDoc().deleteNode(element);
        // editorInteractor.rebiasSelection(CursorDirection.FROM_RIGHT);        
        // router.handleBackspace(node, event);
        
        EditorStaticDeps.endIgnoreMutations();
      }
      
      

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant