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

Cannot type after a link on Chrome #34

Open
matsjoyce opened this issue Dec 16, 2020 · 2 comments
Open

Cannot type after a link on Chrome #34

matsjoyce opened this issue Dec 16, 2020 · 2 comments

Comments

@matsjoyce
Copy link
Contributor

Steps to reproduce:

Cause: Chrome adds the text after the link, which is ignored by the editor. See https://bugs.chromium.org/p/chromium/issues/detail?id=1115085#c3 for details

Possible fix:

  • Rendering links without the href does fix the issue (but will also stop them being rendered as links). Unfortunately, removing the href cannot be done though decorations, so it will have to be done though the linkToHtmlNode which will then affect the Html.toHtml function.
  • Add a new command for typing after a link. However, it is hard to determine which nodes render to an a, since the only place the a element is used is in the linkToHtmlNode function.
  • Modify the JS that handles the mutation list to move the changes into the link. This can be complicated if the link contains nested markup. Going down that route results is a monstrosity like this:
     characterDataMutations(mutationsList) {
        if (!mutationsList) {
            return null;
        }
    
        let mutations = [], allCharacterData = true, self = this;
        mutationsList.forEach(function (mutation, i) {
            if (mutation.type === "childList"
                && mutation.addedNodes.length === 1 // Added a single text node
                && mutation.addedNodes[0].nodeType === Node.TEXT_NODE
                && mutation.previousSibling // Previous node is a link
                && mutation.previousSibling.nodeType === Node.ELEMENT_NODE
                && mutation.previousSibling.nodeName === "A"
            ) {
                var n = mutation.previousSibling;
                while (n.nodeType !== Node.TEXT_NODE) {
                    n = n.childNodes[n.childNodes.length - 1];
                }
                n.nodeValue += mutation.addedNodes[0].nodeValue;
                mutationsList[i + 1] = {target: n, type: "characterData"};
                mutation.addedNodes[0].remove();
                return;
            }
            if (mutation.type !== "characterData") {
                allCharacterData = false;
                return;
            }
            mutations.push({
                path: getSelectionPath(mutation.target, self, 0),
                text: mutation.target.nodeValue
            });
        });
        return allCharacterData ? mutations : null;
    }

This problem does not occur on Firefox.

@mweiss
Copy link
Owner

mweiss commented Dec 20, 2020

Thanks for reporting this! I'm wary of adding special cases to the js code for browser specific bugs (although Android and mac have a few) since that can get out of hand really fast. Perhaps adding a new command is the way to go, or even waiting for Chrome to fix itself.

@matsjoyce
Copy link
Contributor Author

Judging from the issue I linked, Chrome considers this to be the desired behaviour. I suppose the best way of fixing this is to add a new command and a new field to marks, so that the command can determine if the mark is a link?

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

2 participants