From 843942f7d23371881deeb262bfe23e387d87b254 Mon Sep 17 00:00:00 2001 From: "cmanske%netscape.com" Date: Sat, 30 Nov 2002 18:59:34 +0000 Subject: [PATCH] Move caret to text position with rt click. b=181547, r=rods, sr=sfraser --- .../html/nsHTMLEditorMouseListener.cpp | 30 +++++++++++++------ 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/editor/libeditor/html/nsHTMLEditorMouseListener.cpp b/editor/libeditor/html/nsHTMLEditorMouseListener.cpp index 730d87936be..61c37907f21 100644 --- a/editor/libeditor/html/nsHTMLEditorMouseListener.cpp +++ b/editor/libeditor/html/nsHTMLEditorMouseListener.cpp @@ -179,15 +179,27 @@ nsHTMLEditorMouseListener::MouseDown(nsIDOMEvent* aMouseEvent) PRBool elementIsLink = PR_FALSE; if (!element) { - // Get enclosing link if in text so we can select the link - //XXX Although I'd prefer to not select a link on context click, - // logic to place caret within a textnode is complicated and hidden - // in nsFrame code which is never reached during context-click processing - nsCOMPtr linkElement; - res = htmlEditor->GetElementOrParentByTagName(NS_LITERAL_STRING("href"), node, getter_AddRefs(linkElement)); - if (NS_FAILED(res)) return res; - if (linkElement) - element = linkElement; + if (isContextClick) + { + // Set the selection to the point under the mouse cursor: + nsCOMPtr parent; + if (NS_FAILED(uiEvent->GetRangeParent(getter_AddRefs(parent)))) + return NS_ERROR_NULL_POINTER; + PRInt32 offset = 0; + if (NS_FAILED(uiEvent->GetRangeOffset(&offset))) + return NS_ERROR_NULL_POINTER; + + selection->Collapse(parent, offset); + } + else + { + // Get enclosing link if in text so we can select the link + nsCOMPtr linkElement; + res = htmlEditor->GetElementOrParentByTagName(NS_LITERAL_STRING("href"), node, getter_AddRefs(linkElement)); + if (NS_FAILED(res)) return res; + if (linkElement) + element = linkElement; + } } // Select entire element clicked on if NOT within an existing selection // and not the entire body, or table-related elements