简体   繁体   English

不带HTML的光标位置需要转换为带HTML的位置

[英]Position of cursor without HTML needs to be converted to position with HTML

Say I have the following text: 说我有以下文字:

this is some example c|ode

The pipe symbol is where the cursor is in a nicEditor div. 管道符号是光​​标在nicEditor div中的位置。 nicEditor has a function to get the position of the cursor "getRng()". nicEditor具有获取光标“ getRng()”的位置的功能。

However getRng() doesn't get the position of the cursor including HTML, and as far as I can see no such function exists (correct me if I'm wrong). 但是getRng()无法获取包括HTML在内的光标的位置,据我所知,不存在这样的函数(如果我错了,请纠正我)。

The code in the nicEditor div might actually be: nicEditor div中的代码实际上可能是:

<span style='font-weig|ht: bold;'>this i</span>s some example code

You can see my problem. 你可以看到我的问题。 I'm trying to insert something into the nicEditor div and it gets inserted into the middle of a HTML tag. 我正在尝试将某些内容插入nicEditor div,并将其插入HTML标记的中间。

My question is this: Is there a way to convert the position of the cursor with the HTML tags included? 我的问题是:有没有一种方法可以用包含的HTML标记转换光标的位置? Or is there any other alternative solution? 还是有其他替代解决方案?

I worked it out in the end, it wasn't an easy solution. 我最终解决了,这不是一个简单的解决方案。 I had to write a state machine which has four states "Text"=>"HTML"=>"String"=>"Character". 我必须编写一个具有四个状态的状态机:“文本” =>“ HTML” =>“字符串” =>“字符”。 Basically I wrote jQuery plugin which takes the string and the position and shifts accordingly. 基本上我写了jQuery插件,该插件接受字符串和位置并相应地移动。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM