mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-22 01:35:35 +00:00
Bug 240933 - Part 4: Remove the code responsible for handling non-preformatted text in WillInsertText; r=roc a=dbaron
--HG-- extra : rebase_source : cb4457edb5716727801fad0152eff55d3f4d9b09
This commit is contained in:
parent
262d16a6c3
commit
f4fa8fbaff
@ -748,70 +748,12 @@ nsTextEditRules::WillInsertText(PRInt32 aAction,
|
||||
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)
|
||||
{
|
||||
|
@ -287,13 +287,23 @@ function runTests()
|
||||
synthesizeKey("VK_TAB", { });
|
||||
check(aDescription + "Tab",
|
||||
true, true, !aIsTabbable && !aIsReadonly);
|
||||
// The tab char is converted to 4 space characters because textarea/input
|
||||
// elements are not preformatted editor.
|
||||
is(aElement.value, !aIsTabbable && !aIsReadonly ? "a " : "a",
|
||||
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);
|
||||
|
Loading…
Reference in New Issue
Block a user