无法删除图像在Android上CONTENTEDITABLE DIV图像、Android、DIV、CONTENTEDITABLE

2023-09-05 06:02:29 作者:孤独为友

我建立在Android的富文本编辑器。要做到这一点,我使用的是 web视图 CONTENTEDITABLE股利。

I am building a rich text editor in android. To do so, I am using a webView with a contentEditable div.

要添加的样式,我调用的JavaScript 。这一切工作正常,除非我调用JavaScript插入任何图像或水平线。当我使用JavaScript插入这些东西,如果我再尝试preSS后退按钮来删除任何图像或水平线,这是行不通的。

To add styles, I invoke JavaScript. This all works fine, except when I invoke JavaScript to insert either an image or a horizontal rule. When I use JavaScript to insert these things, if I then try to press the back button to delete either the image or the horizontal rule, it doesn't work.

奇怪的是,当我第一次进入任何其它字符,然后将图像或水平线,我可以删除图像/水平线就好了,但不能删除我的图像/水平规则之前,立即进入了角色。

Oddly enough, if I first enter any other character, and then insert the image or horizontal rule, I can delete the image/horizontal rule just fine, but cannot delete the character I entered immediately before the image/horizontal rule.

我试着打印出HTML在每一个国家,检查选择/范围等,并似乎无法找到任何有关的国家不同这或许可以解释为什么我不能删除图像等。

I've tried printing out the HTML in every state, checking the selection/range, etc, and can't seem to find anything that's different about the state that might explain why I can't delete the image, etc.

推荐答案

Android:退格在web视图/ BaseInputConnection

子类web视图并重写方法,如通过这个家伙的问题。

Subclass Webview and override the method as shown by this guy's question.

在一些手机,只有那家伙的问题将满足要求。链接的答案将完成$ C $下与其他手机的兼容性。虽然,你继承一个InputConnectionWrapper。不inputconnection。然后回到您的自定义的WebView内包装。

On some phones, only the guy's question will satisfy the requirements. The link's answer will complete the code for compatibility with other phones. Though, you subclass a InputConnectionWrapper. not inputconnection. and then return that wrapper within your custom webview.

只是一个仅供参考,这个环节有更详细的解释的情况,但是我试图快速实现自己的想法,并没有奏效。也许太复杂了,我的目的。我想什么,而不是我上面提到的解决方案的原因是因为我上面提到的解决方案,使语音到文本功能无法正常工作。 Android - 无法捕捉退格键/删除preSS软。键盘

Just a FYI, this link has a much more detailed explanation of the situation, however I tried quickly implementing their ideas and it didn't work. Maybe too complicated for my purposes. The reason I tried their solution instead of what I mentioned above is because the solution I mentioned above causes the voice-to-text function to not work correctly. Android - cannot capture backspace/delete press in soft. keyboard