getcaretpos

Get current word on caret position

落爺英雄遲暮 提交于 2020-01-13 02:11:59
问题 How can I get a word in textarrea by its current caret position? I tried something like this, however this returns just the words first letter upto the character at caret position. For example: if the cursor is between fo and o it returns fo and not foo as excpected. Fo | o bar is not equal to bar foo. => Fo expects Foo Foo bar is not equ | al to bar foo. => equ expects equal . Here's what I've done so far: function getCaretPosition(ctrl) { var start, end; if (ctrl.setSelectionRange) { start

Get current word on caret position

删除回忆录丶 提交于 2020-01-13 02:11:26
问题 How can I get a word in textarrea by its current caret position? I tried something like this, however this returns just the words first letter upto the character at caret position. For example: if the cursor is between fo and o it returns fo and not foo as excpected. Fo | o bar is not equal to bar foo. => Fo expects Foo Foo bar is not equ | al to bar foo. => equ expects equal . Here's what I've done so far: function getCaretPosition(ctrl) { var start, end; if (ctrl.setSelectionRange) { start

Left and right button misbehaving when trying to add an empty span to contenteditable div

夙愿已清 提交于 2019-12-12 18:54:02
问题 In my project, I am trying to add a span wherever the caret is in the contenteditable div. This span element will be used as getting the offset position of the caret indirectly. var _spanElem = "<span class='spanPos'></span>"; Now , I can get the care position in the contenteditable div and also I know how to remove and add the span element at the caret position. But the thing is that while I am doing this operation, Left and Right buttons are misbehaving. Please have a look at this link

how to get the caret position of a contenteditable div which contains images

ぃ、小莉子 提交于 2019-12-05 00:11:11
问题 I have this contentedittable div <div contenteditable="true" id="text">minubyv<img src="images/smiley/Emoji Smiley-01.png" class="emojiText" />iubyvt</div> Here is an image description of the code output so I want to get the caret position of the div and lets assume that the cursor is after the last character. And this is my code for getting the caret position function getCaretPosition(editableDiv) { var caretPos = 0, sel, range; if (window.getSelection) { sel = window.getSelection(); if (sel

Get current word on caret position

两盒软妹~` 提交于 2019-12-04 08:36:01
How can I get a word in textarrea by its current caret position? I tried something like this, however this returns just the words first letter upto the character at caret position. For example: if the cursor is between fo and o it returns fo and not foo as excpected. Fo | o bar is not equal to bar foo. => Fo expects Foo Foo bar is not equ | al to bar foo. => equ expects equal . Here's what I've done so far: function getCaretPosition(ctrl) { var start, end; if (ctrl.setSelectionRange) { start = ctrl.selectionStart; end = ctrl.selectionEnd; } else if (document.selection && document.selection

JavaScript: get cursor position in contenteditable div

天大地大妈咪最大 提交于 2019-12-01 11:34:04
问题 I am pretty new to JavaScript and hope someone here can help me with the following: Primarily looking for a solution in IE 8 - if it can cover other browsers / versions even better. I have a page with only one contenteditable div that is created dynamically and contains both text and HTML tags. On the page I want to add a button that inserts certain text at the cursor position into this div. So far I have the following code which works fine as long as I select a text in the div but if I just

Get caret position in contenteditable div including tags

好久不见. 提交于 2019-11-26 20:33:16
I have a contenteditable div in which I have multiple tags (br, b, u, i) and text and I need to get the caret position relative to the div, including all the tags. For example: <div id="h" contenteditable="true">abc<b>def<br>ghi</b>jkl</div> If the cursor is between g and h, I need the caret position to be 14. The problem is that the found methods that use a treeWalker do not work in this case. The bold tag is not found... probably because it isn't closed. Also I have tried several methods but still no luck. I need it to work in Firefox. Thank you. Have you tried this? Get a range's start and

Get caret index in contenteditable div including tags

不问归期 提交于 2019-11-26 07:38:12
问题 I have a contentEditable div in which I have multiple tags ( br , b , u , i ) and text. I need to get the caret index position relative to the div, including all the tags. For example: <div id=\"h\" contenteditable=\"true\">abc<b>def<br>ghi</b>jkl</div> If the cursor is between g and h , I need the caret index position to be 14 . The problem is that the found methods that use a treeWalker do not work in this case. The bold tag is not found... probably because it isn\'t closed. Also I have