单击伪元素时可以设置光标/插入符号吗?

发布于 2024-11-30 03:34:38 字数 259 浏览 1 评论 0原文

我使用此 css 将 Pilcrow 字符(无关紧要)设置为段落的后元素

body.p:after {
    content:'\00b6'; // the used char or image does not matter
}

当我在正文内的后元素之后单击时,光标/插入符号将按需要放置在段落末尾。但是,当我单击后元素时,不会显示光标,并且输入某些字母不起作用。

有解决方法吗?

I am setting a Pilcrow character (does not matter) as after element to a paragraph using this css

body.p:after {
    content:'\00b6'; // the used char or image does not matter
}

When i click after the after element inside the body the cursor/caret gets placed at the end of the paragraph as wished. But when i click on the after element no cursor is shown and typing in some letters does not work.

Is there a workaround for this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

生来就爱笑 2024-12-07 03:34:38

这是我对问题的解决方案。
OnClick 我检查单击事件的偏移量是否等于最大文本节点长度,以便决定是否需要设置插入符号。
这里的目标是当单击 after 元素时将光标设置到实际段落的末尾。

ed.onClick.add(function(ed, evt){

  var node = ed.selection.getNode();

  // need to set Cursor onClick on after element?
  if (ed.controlManager.get('irhiddenchars') && ed.controlManager.get('irhiddenchars').isActive() &&
  evt.target.nodeName.toLowerCase() == 'p'){
    if (node != evt.target) {
        ed.selection.setCursorLocation(evt.target, 0);
    }
    else {
        if (evt.rangeParent.nodeType == 3 && evt.rangeParent.textContent.length == evt.rangeOffset)
        {
            ed.selection.setCursorLocation(evt.rangeParent, evt.rangeOffset);
        }
    }
    // show Caret
    ed.focus();
  }
});

Here is my solution to the problem.
OnClick i check if the offset of the click event equals the maximum textnodelength in order to decide if the caret needs to get set or not.
Goal here was to set the cursor to the end of the actual paragraph when clicked on the after element.

ed.onClick.add(function(ed, evt){

  var node = ed.selection.getNode();

  // need to set Cursor onClick on after element?
  if (ed.controlManager.get('irhiddenchars') && ed.controlManager.get('irhiddenchars').isActive() &&
  evt.target.nodeName.toLowerCase() == 'p'){
    if (node != evt.target) {
        ed.selection.setCursorLocation(evt.target, 0);
    }
    else {
        if (evt.rangeParent.nodeType == 3 && evt.rangeParent.textContent.length == evt.rangeOffset)
        {
            ed.selection.setCursorLocation(evt.rangeParent, evt.rangeOffset);
        }
    }
    // show Caret
    ed.focus();
  }
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文