Closed
Bug 852121
Opened 13 years ago
Closed 13 years ago
Provide a way to move the location of the selection caret
Categories
(Firefox for Metro Graveyard :: Input, defect)
Tracking
(Not tracked)
RESOLVED
WORKSFORME
People
(Reporter: jimm, Unassigned)
References
Details
(Whiteboard: [selection])
We need a way to move the caret location without the use of simulated mouse events. AFAICT no such controlling interface exists. I've looked at the following:
http://mxr.mozilla.org/mozilla-central/source/content/base/public/nsISelectionDisplay.idl
http://mxr.mozilla.org/mozilla-central/source/content/base/public/nsISelectionListener.idl
http://mxr.mozilla.org/mozilla-central/source/content/base/public/nsISelectionPrivate.idl
http://mxr.mozilla.org/mozilla-central/source/content/base/public/nsISelectionController.idl
http://mxr.mozilla.org/mozilla-central/source/content/base/public/nsISelection.idl
http://mxr.mozilla.org/mozilla-central/source/editor/idl/nsIEditor.idl
http://mxr.mozilla.org/mozilla-central/source/dom/interfaces/base/nsIFocusManager.idl
I've also experimented around with ranges. I was hoping something like this might work in a text input:
let cp = document.caretPositionFromPoint(aX, aY);
let selection = document.getSelection();
selection.removeAllRanges();
let range = content.document.createRange();
range.setStart(cp.offsetNode.firstChild, cp.offset);
selection.addRange(range);
which adds the range but clears the focus caret from the editor.
Thus far I haven't found any way to do this.
| Reporter | ||
Comment 1•13 years ago
|
||
Ehsan, you seem to be the go to guy for selection. Curious if you can tell me if I've missed an interface that allows us to do this, or if my guess is right and we currently don't support it. Android gets around this by simulating mouse clicks which I do not want to do here unless absolutely necessary.
The immediate need only applies to nsIEditor elements like text areas or boxes. Although it would be cool if we could do it in generic content as well.
Flags: needinfo?(ehsan)
| Reporter | ||
Comment 2•13 years ago
|
||
Hmm, when you call caretPositionFromPoint with coordinates that are located within a text area, you would expect to get the offset within the input. However in the result 'offsetNode' is set to the text area and 'offset' is the offset within the document of offsetNode.
If this is the case and by design, this api isn't of any use if you want to get caret positions within input elements.
Comment 3•13 years ago
|
||
For input type=text and textarea, you want HTML{Input,TextArea}Element.selectionStart/End.
For regular selections, you should use nsISelection to change the position of a collapsed selection.
(In reply to Jim Mathies [:jimm] from comment #2)
> Hmm, when you call caretPositionFromPoint with coordinates that are located
> within a text area, you would expect to get the offset within the input.
> However in the result 'offsetNode' is set to the text area and 'offset' is
> the offset within the document of offsetNode.
Yes, that is by design.
Flags: needinfo?(ehsan)
| Reporter | ||
Comment 4•13 years ago
|
||
(In reply to :Ehsan Akhgari (needinfo? me!) from comment #3)
> For input type=text and textarea, you want
> HTML{Input,TextArea}Element.selectionStart/End.
>
> For regular selections, you should use nsISelection to change the position
> of a collapsed selection.
>
I will try that, thanks.
| Reporter | ||
Updated•13 years ago
|
Status: NEW → RESOLVED
Closed: 13 years ago
Resolution: --- → WORKSFORME
| Assignee | ||
Updated•12 years ago
|
OS: Windows 8 Metro → Windows 8.1
You need to log in
before you can comment on or make changes to this bug.
Description
•