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

连续插入多个列表,控制台报错 #1343

Closed
terry8650 opened this issue Dec 27, 2022 · 1 comment
Closed

连续插入多个列表,控制台报错 #1343

terry8650 opened this issue Dec 27, 2022 · 1 comment
Assignees
Milestone

Comments

@terry8650
Copy link

terry8650 commented Dec 27, 2022

编辑模式

  • wysiwyg 所见即所得模式
  • ir 即时渲染模式

描述问题

段落输入或无序和有序列表连续输入回车后,控制台会报错Uncaught TypeError: Cannot read properties of null (reading 'replace')

1. sdsdf
2. ds
3. fdf
4. s
5. f

报错对应的代码是这里fixbrowserBehavior.ts

// https://github.com/Vanessa219/vditor/issues/361 代码块后输入中文
export const fixCJKPosition = (range: Range, vditor: IVditor, event: KeyboardEvent) => {
    if (event.key === "Enter" || event.key === "Tab" || event.key === "Backspace" || event.key.indexOf("Arrow") > -1
        || isCtrl(event) || event.key === "Escape" || event.shiftKey || event.altKey) {
        return;
    }
    const pLiElement = hasClosestByMatchTag(range.startContainer, "P") ||
        hasClosestByMatchTag(range.startContainer, "LI");
    if (pLiElement && getSelectPosition(pLiElement, vditor[vditor.currentMode].element, range).start === 0) {

        // https://github.com/Vanessa219/vditor/issues/1289 WKWebView切换输入法产生六分之一空格,造成光标错位
        pLiElement.nodeValue = pLiElement.nodeValue.replace(/\u2006/g, '');//**这个地方报错,这个地方不应该是pLiElement.childNodes[0].nodeValue?如果不是,也该判断一下xxx.nodeValue是否存在或是否为null**

        const zwspNode = document.createTextNode(Constants.ZWSP);
        range.insertNode(zwspNode);
        range.setStartAfter(zwspNode);
    }
};

期待的结果

不要报错

版本信息

  • 版本:vditor-3.8.18和最新版
  • 操作系统:
  • 浏览器:
    vivaldi,chrome,360

其他信息

@left0ver
Copy link

我也遇到了,现在的解决方法是加了一层判断

@Vanessa219 Vanessa219 changed the title 连续插入多个li列表,控制台会报错 连续插入多个列表,控制台会报错 Feb 14, 2023
@Vanessa219 Vanessa219 self-assigned this Feb 14, 2023
Vanessa219 added a commit that referenced this issue Feb 14, 2023
@Vanessa219 Vanessa219 added this to the 3.9 milestone Feb 14, 2023
@Vanessa219 Vanessa219 changed the title 连续插入多个列表,控制台会报错 连续插入多个列表,控制台报错 Feb 14, 2023
Vanessa219 added a commit that referenced this issue Feb 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants