From 88f276e98aa4d30093b19878349cbdb56f5d965b Mon Sep 17 00:00:00 2001 From: Ehsan Akhgari Date: Wed, 1 Sep 2010 18:06:52 -0400 Subject: [PATCH] Bug 240933 - Part 7: Collapse the selection in textarea's to the trailing BR if needed after every edit operation; r,a=roc --HG-- extra : rebase_source : def2e0da4f32e9e50231b250075c45766bb00819 --- editor/libeditor/text/nsTextEditRules.cpp | 9 +++++++++ editor/libeditor/text/nsTextEditRules.h | 2 ++ layout/base/tests/Makefile.in | 3 +++ layout/base/tests/bug240933-1-ref.html | 10 ++++++++++ layout/base/tests/bug240933-1.html | 14 ++++++++++++++ layout/base/tests/bug240933-2.html | 16 ++++++++++++++++ layout/base/tests/test_reftests_with_caret.html | 2 ++ 7 files changed, 56 insertions(+) create mode 100644 layout/base/tests/bug240933-1-ref.html create mode 100644 layout/base/tests/bug240933-1.html create mode 100644 layout/base/tests/bug240933-2.html diff --git a/editor/libeditor/text/nsTextEditRules.cpp b/editor/libeditor/text/nsTextEditRules.cpp index 1c703630265..26eb907d51f 100644 --- a/editor/libeditor/text/nsTextEditRules.cpp +++ b/editor/libeditor/text/nsTextEditRules.cpp @@ -267,6 +267,9 @@ nsTextEditRules::AfterEdit(PRInt32 action, nsIEditor::EDirection aDirection) // insure trailing br node res = CreateTrailingBRIfNeeded(); NS_ENSURE_SUCCESS(res, res); + + // collapse the selection to the trailing BR if it's at the end of our text node + CollapseSelectionToTrailingBRIfNeeded(selection); /* After inserting text the cursor Bidi level must be set to the level of the inserted text. * This is difficult, because we cannot know what the level is until after the Bidi algorithm @@ -455,6 +458,12 @@ nsTextEditRules::WillInsertBreak(nsISelection *aSelection, PRBool *aCancel, PRBo nsresult nsTextEditRules::DidInsertBreak(nsISelection *aSelection, nsresult aResult) +{ + return NS_OK; +} + +nsresult +nsTextEditRules::CollapseSelectionToTrailingBRIfNeeded(nsISelection* aSelection) { // we only need to execute the stuff below if we are a plaintext editor. // html editors have a different mechanism for putting in mozBR's diff --git a/editor/libeditor/text/nsTextEditRules.h b/editor/libeditor/text/nsTextEditRules.h index ba1eadb4a5e..48d1b3fe882 100644 --- a/editor/libeditor/text/nsTextEditRules.h +++ b/editor/libeditor/text/nsTextEditRules.h @@ -233,6 +233,8 @@ protected: nsresult HideLastPWInput(); + nsresult CollapseSelectionToTrailingBRIfNeeded(nsISelection *aSelection); + PRBool IsPasswordEditor() const { return mEditor ? mEditor->IsPasswordEditor() : PR_FALSE; diff --git a/layout/base/tests/Makefile.in b/layout/base/tests/Makefile.in index 821204a6fe1..fd9a1f8217a 100644 --- a/layout/base/tests/Makefile.in +++ b/layout/base/tests/Makefile.in @@ -92,6 +92,9 @@ _TEST_FILES = \ bug106855-1.html \ bug106855-2.html \ bug106855-1-ref.html \ + bug240933-1.html \ + bug240933-2.html \ + bug240933-1-ref.html \ bug482484.html \ bug482484-ref.html \ bug512295-1.html \ diff --git a/layout/base/tests/bug240933-1-ref.html b/layout/base/tests/bug240933-1-ref.html new file mode 100644 index 00000000000..c3aa0a57e9c --- /dev/null +++ b/layout/base/tests/bug240933-1-ref.html @@ -0,0 +1,10 @@ + + + + + + diff --git a/layout/base/tests/bug240933-1.html b/layout/base/tests/bug240933-1.html new file mode 100644 index 00000000000..c64ea3ac4a5 --- /dev/null +++ b/layout/base/tests/bug240933-1.html @@ -0,0 +1,14 @@ + + + + + + + + + diff --git a/layout/base/tests/bug240933-2.html b/layout/base/tests/bug240933-2.html new file mode 100644 index 00000000000..789b2854258 --- /dev/null +++ b/layout/base/tests/bug240933-2.html @@ -0,0 +1,16 @@ + + + + + + + + + diff --git a/layout/base/tests/test_reftests_with_caret.html b/layout/base/tests/test_reftests_with_caret.html index e129684ebbc..2b54805ebbd 100644 --- a/layout/base/tests/test_reftests_with_caret.html +++ b/layout/base/tests/test_reftests_with_caret.html @@ -88,6 +88,8 @@ function endTest() { var tests = [ [ 'bug106855-1.html' , 'bug106855-1-ref.html' ] , [ 'bug106855-2.html' , 'bug106855-1-ref.html' ] , + [ 'bug240933-1.html' , 'bug240933-1-ref.html' ] , + [ 'bug240933-2.html' , 'bug240933-1-ref.html' ] , [ 'bug482484.html' , 'bug482484-ref.html' ] , [ 'bug512295-1.html' , 'bug512295-1-ref.html' ] , [ 'bug512295-2.html' , 'bug512295-2-ref.html' ] ,