When copy from a nested list (such as the following) from macOS Notes app to VisualEditor, the paste won't work and it would throw the following error in the console.
- Level 1
- Level 2
Uncaught DOMException: Failed to execute 'appendChild' on 'Node': This node type does not support this method. at HTMLUListElement.<anonymous> (https://zh.wikipedia.org/w/load.php?debug=false&lang=zh&modules=ext.CodeMirror.lib%7Cext.visualEditor.core%2Cdata%7Coojs-ui-core%2Coojs-ui-widgets%7Coojs-ui.styles.icons-editing-advanced&skin=vector&version=05g9o3l:700:736) at Function.each (https://zh.wikipedia.org/w/load.php?debug=false&lang=zh&modules=ext.centralNotice.choiceData%2Cdisplay%2CimpressionDiet%2CkvStore%2CkvStoreMaintenance%2CstartUp%7Cjquery&skin=vector&version=1lf1v71:39:868) at jQuery.fn.init.each (https://zh.wikipedia.org/w/load.php?debug=false&lang=zh&modules=ext.centralNotice.choiceData%2Cdisplay%2CimpressionDiet%2CkvStore%2CkvStoreMaintenance%2CstartUp%7Cjquery&skin=vector&version=1lf1v71:37:932) at VeCeSurface.ve.ce.Surface.afterPasteAddToFragmentFromExternal (https://zh.wikipedia.org/w/load.php?debug=false&lang=zh&modules=ext.CodeMirror.lib%7Cext.visualEditor.core%2Cdata%7Coojs-ui-core%2Coojs-ui-widgets%7Coojs-ui.styles.icons-editing-advanced&skin=vector&version=05g9o3l:700:674) at VeCeSurface.ve.ce.Surface.afterPaste (https://zh.wikipedia.org/w/load.php?debug=false&lang=zh&modules=ext.CodeMirror.lib%7Cext.visualEditor.core%2Cdata%7Coojs-ui-core%2Coojs-ui-widgets%7Coojs-ui.styles.icons-editing-advanced&skin=vector&version=05g9o3l:695:924) at https://zh.wikipedia.org/w/load.php?debug=false&lang=zh&modules=ext.CodeMirror.lib%7Cext.visualEditor.core%2Cdata%7Coojs-ui-core%2Coojs-ui-widgets%7Coojs-ui.styles.icons-editing-advanced&skin=vector&version=05g9o3l:692:96
Nested list from macOS Notes creates HTML like Google Doc (similar to T98100)
<ul><li>Level 1</li><ul><li>Level 2</li></ul></ul>
However, the nested ul tag's previousSibling method returns a text node with newline as its only content, and VisualEditor's fix would try to call appendChild to the text node, which generates the error.
To resolve the issue, I think we can replace the two calls of previousSibling to previousElementSibling, which would only return the element node (skipping text/comment nodes).