mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-09-06 07:48:38 +09:00
Issue #3059 - Implement Selection.setBaseAndExtent()
This commit is contained in:
parent
19e2f0fbf9
commit
602bb0a877
3 changed files with 59 additions and 0 deletions
|
|
@ -6435,6 +6435,55 @@ Selection::Modify(const nsAString& aAlter, const nsAString& aDirection,
|
|||
}
|
||||
}
|
||||
|
||||
void
|
||||
Selection::SetBaseAndExtent(nsINode& aAnchorNode, uint32_t aAnchorOffset,
|
||||
nsINode& aFocusNode, uint32_t aFocusOffset,
|
||||
ErrorResult& aRv)
|
||||
{
|
||||
if (!mFrameSelection) {
|
||||
return;
|
||||
}
|
||||
|
||||
SelectionBatcher batch(this);
|
||||
|
||||
int32_t relativePosition =
|
||||
nsContentUtils::ComparePoints(&aAnchorNode, aAnchorOffset,
|
||||
&aFocusNode, aFocusOffset);
|
||||
nsINode* start = &aAnchorNode;
|
||||
nsINode* end = &aFocusNode;
|
||||
uint32_t startOffset = aAnchorOffset;
|
||||
uint32_t endOffset = aFocusOffset;
|
||||
if (relativePosition > 0) {
|
||||
start = &aFocusNode;
|
||||
end = &aAnchorNode;
|
||||
startOffset = aFocusOffset;
|
||||
endOffset = aAnchorOffset;
|
||||
}
|
||||
|
||||
RefPtr<nsRange> newRange;
|
||||
nsresult rv = nsRange::CreateRange(start, startOffset, end, endOffset,
|
||||
getter_AddRefs(newRange));
|
||||
// CreateRange returns IndexSizeError if any offset is out of bounds.
|
||||
if (NS_FAILED(rv)) {
|
||||
aRv.Throw(rv);
|
||||
return;
|
||||
}
|
||||
|
||||
rv = RemoveAllRanges();
|
||||
if (NS_FAILED(rv)) {
|
||||
aRv.Throw(rv);
|
||||
return;
|
||||
}
|
||||
|
||||
rv = AddRange(newRange);
|
||||
if (NS_FAILED(rv)) {
|
||||
aRv.Throw(rv);
|
||||
return;
|
||||
}
|
||||
|
||||
SetDirection(relativePosition > 0 ? eDirPrevious : eDirNext);
|
||||
}
|
||||
|
||||
/** SelectionLanguageChange modifies the cursor Bidi level after a change in keyboard direction
|
||||
* @param aLangRTL is true if the new language is right-to-left or false if the new language is left-to-right
|
||||
*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue