Bug 240933 - Part 4: Remove the code responsible for handling non-preformatted text in WillInsertText; r=roc a=dbaron
--- a/editor/libeditor/text/nsTextEditRules.cpp
+++ b/editor/libeditor/text/nsTextEditRules.cpp
@@ -743,80 +743,22 @@ nsTextEditRules::WillInsertText(PRInt32
NS_ENSURE_SUCCESS(res, res);
}
else // aAction == kInsertText
{
// find where we are
nsCOMPtr<nsIDOMNode> curNode = selNode;
PRInt32 curOffset = selOffset;
- // is our text going to be PREformatted?
- // We remember this so that we know how to handle tabs.
- PRBool isPRE;
- res = mEditor->IsPreformatted(selNode, &isPRE);
- NS_ENSURE_SUCCESS(res, res);
-
// don't spaz my selection in subtransactions
nsAutoTxnsConserveSelection dontSpazMySelection(mEditor);
- if (isPRE)
- {
- res = mEditor->InsertTextImpl(*outString, address_of(curNode),
- &curOffset, doc);
- NS_ENSURE_SUCCESS(res, res);
- }
- else
- {
- const nsString& tString = PromiseFlatString(*outString);
- const PRUnichar *unicodeBuf = tString.get();
- nsCOMPtr<nsIDOMNode> unused;
- PRInt32 pos = 0;
-
- char specialChars[] = {TAB, nsCRT::LF, 0};
- while (unicodeBuf && (pos != -1) && ((PRUint32)pos < tString.Length()))
- {
- PRInt32 oldPos = pos;
- PRInt32 subStrLen;
- pos = tString.FindCharInSet(specialChars, oldPos);
-
- if (pos != -1)
- {
- subStrLen = pos - oldPos;
- // if first char is newline, then use just it
- if (subStrLen == 0)
- subStrLen = 1;
- }
- else
- {
- subStrLen = tString.Length() - oldPos;
- pos = tString.Length();
- }
-
- nsDependentSubstring subStr(tString, oldPos, subStrLen);
-
- // is it a tab?
- if (subStr.EqualsLiteral("\t"))
- {
- res = mEditor->InsertTextImpl(NS_LITERAL_STRING(" "), address_of(curNode), &curOffset, doc);
- pos++;
- }
- // is it a return?
- else if (subStr.EqualsLiteral(LFSTR))
- {
- res = mEditor->CreateBRImpl(address_of(curNode), &curOffset, address_of(unused), nsIEditor::eNone);
- pos++;
- }
- else
- {
- res = mEditor->InsertTextImpl(subStr, address_of(curNode), &curOffset, doc);
- }
- NS_ENSURE_SUCCESS(res, res);
- }
- outString->Assign(tString);
- }
+ res = mEditor->InsertTextImpl(*outString, address_of(curNode),
+ &curOffset, doc);
+ NS_ENSURE_SUCCESS(res, res);
if (curNode)
{
// Make the caret attach to the inserted text, unless this text ends with a LF,
// in which case make the caret attach to the next line.
PRBool endsWithLF =
!outString->IsEmpty() && outString->Last() == nsCRT::LF;
nsCOMPtr<nsISelectionPrivate>selPrivate(do_QueryInterface(aSelection));
--- a/editor/libeditor/text/tests/test_texteditor_keyevent_handling.html
+++ b/editor/libeditor/text/tests/test_texteditor_keyevent_handling.html
@@ -287,16 +287,28 @@ function runTests()
synthesizeKey("VK_TAB", { });
check(aDescription + "Tab",
true, true, !aIsTabbable && !aIsReadonly);
is(aElement.value, !aIsTabbable && !aIsReadonly ? "a\t" : "a",
aDescription + "Tab");
is(fm.focusedElement, aElement,
aDescription + "focus moved unexpectedly (Tab)");
+ // If the editor is not tabbable, make sure that it accepts tab characters
+ // even if it's empty.
+ if (!aIsTabbable && !aIsReadonly) {
+ reset("");
+ synthesizeKey("VK_TAB", {});
+ check(aDescription + "Tab on empty textarea",
+ true, true, !aIsReadonly);
+ is(aElement.value, "\t", aDescription + "Tab on empty textarea");
+ is(fm.focusedElement, aElement,
+ aDescription + "focus moved unexpectedly (Tab on empty textarea");
+ }
+
reset("a");
synthesizeKey("VK_TAB", { shiftKey: true });
check(aDescription + "Shift+Tab", true, true, false);
is(aElement.value, "a", aDescription + "Shift+Tab");
is(fm.focusedElement, aElement,
aDescription + "focus moved unexpectedly (Shift+Tab)");
// Ctrl+Tab may be consumed by tabbrowser but editor shouldn't consume this.