From 539c56b91f9d323d87323f735abf9a354a46c1e5 Mon Sep 17 00:00:00 2001 From: "kin%netscape.com" Date: Mon, 27 Jan 2003 15:25:38 +0000 Subject: [PATCH] Fix for bug 190382 (selectionEnd off by one when user selects text via CMD/CTRL-A) - Prevent DOMPointToOffset() from counting a br as a newline, if it is the last child of the anonymous div. - Fixed 3 compiler warnings in DOMPointToOffset(). r=jkeiser@netscape.com sr=sfraser@netscape.com a=asa@mozilla.org --- layout/forms/nsTextControlFrame.cpp | 13 ++++++++----- layout/html/forms/src/nsTextControlFrame.cpp | 13 ++++++++----- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/layout/forms/nsTextControlFrame.cpp b/layout/forms/nsTextControlFrame.cpp index ee4a13860546..e79085dd4c8a 100644 --- a/layout/forms/nsTextControlFrame.cpp +++ b/layout/forms/nsTextControlFrame.cpp @@ -2430,8 +2430,9 @@ nsTextControlFrame::DOMPointToOffset(nsIDOMNode* aNode, return NS_OK; PRInt32 i, textOffset = 0; + PRInt32 lastIndex = (PRInt32)length - 1; - for (i = 0; i < length; i++) { + for (i = 0; i < (PRInt32)length; i++) { if (rootNode == aNode && i == aNodeOffset) { *aResult = textOffset; return NS_OK; @@ -2451,7 +2452,7 @@ nsTextControlFrame::DOMPointToOffset(nsIDOMNode* aNode, NS_ENSURE_SUCCESS(rv, rv); if (item == aNode) { - NS_ASSERTION((aNodeOffset >= 0 && aNodeOffset <= textLength), + NS_ASSERTION((aNodeOffset >= 0 && aNodeOffset <= (PRInt32)textLength), "Invalid aNodeOffset!"); *aResult = textOffset + aNodeOffset; return NS_OK; @@ -2460,13 +2461,15 @@ nsTextControlFrame::DOMPointToOffset(nsIDOMNode* aNode, textOffset += textLength; } else { - // Must be a BR node, count it as a newline. + // Must be a BR node. If it's not the last BR node + // under the root, count it as a newline. - ++textOffset; + if (i != lastIndex) + ++textOffset; } } - NS_ASSERTION((aNode == rootNode && aNodeOffset == length), + NS_ASSERTION((aNode == rootNode && aNodeOffset == (PRInt32)length), "Invalide node offset!"); *aResult = textOffset; diff --git a/layout/html/forms/src/nsTextControlFrame.cpp b/layout/html/forms/src/nsTextControlFrame.cpp index ee4a13860546..e79085dd4c8a 100644 --- a/layout/html/forms/src/nsTextControlFrame.cpp +++ b/layout/html/forms/src/nsTextControlFrame.cpp @@ -2430,8 +2430,9 @@ nsTextControlFrame::DOMPointToOffset(nsIDOMNode* aNode, return NS_OK; PRInt32 i, textOffset = 0; + PRInt32 lastIndex = (PRInt32)length - 1; - for (i = 0; i < length; i++) { + for (i = 0; i < (PRInt32)length; i++) { if (rootNode == aNode && i == aNodeOffset) { *aResult = textOffset; return NS_OK; @@ -2451,7 +2452,7 @@ nsTextControlFrame::DOMPointToOffset(nsIDOMNode* aNode, NS_ENSURE_SUCCESS(rv, rv); if (item == aNode) { - NS_ASSERTION((aNodeOffset >= 0 && aNodeOffset <= textLength), + NS_ASSERTION((aNodeOffset >= 0 && aNodeOffset <= (PRInt32)textLength), "Invalid aNodeOffset!"); *aResult = textOffset + aNodeOffset; return NS_OK; @@ -2460,13 +2461,15 @@ nsTextControlFrame::DOMPointToOffset(nsIDOMNode* aNode, textOffset += textLength; } else { - // Must be a BR node, count it as a newline. + // Must be a BR node. If it's not the last BR node + // under the root, count it as a newline. - ++textOffset; + if (i != lastIndex) + ++textOffset; } } - NS_ASSERTION((aNode == rootNode && aNodeOffset == length), + NS_ASSERTION((aNode == rootNode && aNodeOffset == (PRInt32)length), "Invalide node offset!"); *aResult = textOffset;