mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-08 10:44:56 +00:00
Bug 1768057 - Make nsIEditorMailSupport::insertTextWithQuotations available to JS callers. r=masayuki
Differential Revision: https://phabricator.services.mozilla.com/D145646
This commit is contained in:
parent
9f2d7d7379
commit
53018c71f0
@ -667,19 +667,6 @@ class HTMLEditor final : public EditorBase,
|
||||
nsresult
|
||||
InsertAsQuotation(const nsAString& aQuotedText, nsINode** aNodeInserted);
|
||||
|
||||
/**
|
||||
* Inserts a plaintext string at the current location,
|
||||
* with special processing for lines beginning with ">",
|
||||
* which will be treated as mail quotes and inserted
|
||||
* as plaintext quoted blocks.
|
||||
* If the selection is not collapsed, the selection is deleted
|
||||
* and the insertion takes place at the resulting collapsed selection.
|
||||
*
|
||||
* @param aString the string to be inserted
|
||||
*/
|
||||
MOZ_CAN_RUN_SCRIPT nsresult
|
||||
InsertTextWithQuotations(const nsAString& aStringToInsert);
|
||||
|
||||
MOZ_CAN_RUN_SCRIPT nsresult InsertHTMLAsAction(
|
||||
const nsAString& aInString, nsIPrincipal* aPrincipal = nullptr);
|
||||
|
||||
|
@ -2814,7 +2814,7 @@ nsresult HTMLEditor::InsertWithQuotationsAsSubAction(
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult HTMLEditor::InsertTextWithQuotations(
|
||||
NS_IMETHODIMP HTMLEditor::InsertTextWithQuotations(
|
||||
const nsAString& aStringToInsert) {
|
||||
AutoEditActionDataSetter editActionData(*this, EditAction::eInsertText);
|
||||
MOZ_ASSERT(!aStringToInsert.IsVoid());
|
||||
|
@ -259,6 +259,7 @@ skip-if = headless
|
||||
[test_nsIEditor_isSelectionEditable.html]
|
||||
[test_nsIEditor_outputToString.html]
|
||||
[test_nsIEditorMailSupport_insertAsCitedQuotation.html]
|
||||
[test_nsIEditorMailSupport_insertTextWithQuotations.html]
|
||||
[test_nsIHTMLEditor_getElementOrParentByTagName.html]
|
||||
[test_nsIHTMLEditor_getParagraphState.html]
|
||||
[test_nsIHTMLEditor_getSelectedElement.html]
|
||||
|
@ -0,0 +1,89 @@
|
||||
<!DOCTYPE>
|
||||
<html>
|
||||
<head>
|
||||
<title>Test for nsIEditorMailSupport.insertTextWithQuotations()</title>
|
||||
<script src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" href="/tests/SimpleTest/test.css">
|
||||
</head>
|
||||
<body>
|
||||
<div contenteditable></div>
|
||||
<script>
|
||||
"use strict";
|
||||
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
SimpleTest.waitForFocus(() => {
|
||||
(function testStyleOfPlaintextMode() {
|
||||
getEditor().flags |= SpecialPowers.Ci.nsIEditor.eEditorPlaintextMask;
|
||||
|
||||
(function testInDiv() {
|
||||
const editor = document.querySelector("div[contenteditable]");
|
||||
editor.innerHTML = "";
|
||||
editor.focus();
|
||||
getEditorMailSupport().insertTextWithQuotations(
|
||||
"This is Text\n\n> This is a quote."
|
||||
);
|
||||
verify(editor, "TestInDiv");
|
||||
})();
|
||||
|
||||
try {
|
||||
document.body.contentEditable = true;
|
||||
(function testInBody() {
|
||||
getSelection().collapse(document.body, 0);
|
||||
getEditorMailSupport().insertTextWithQuotations(
|
||||
"This is Text\n\n> This is a quote."
|
||||
);
|
||||
verify(document.body, "TestInBody");
|
||||
})();
|
||||
} finally {
|
||||
document.body.contentEditable = false;
|
||||
}
|
||||
})();
|
||||
|
||||
SimpleTest.finish();
|
||||
});
|
||||
|
||||
function getEditor() {
|
||||
var editingSession = SpecialPowers.wrap(window).docShell.editingSession;
|
||||
return editingSession.getEditorForWindow(window);
|
||||
}
|
||||
|
||||
function getEditorMailSupport() {
|
||||
return getEditor().QueryInterface(SpecialPowers.Ci.nsIEditorMailSupport);
|
||||
}
|
||||
|
||||
function verify(editor, logHint) {
|
||||
is(
|
||||
editor.childNodes[0].textContent,
|
||||
"This is Text",
|
||||
`${logHint}: insertTextWithQuotations should insert the text directly`
|
||||
);
|
||||
is(
|
||||
editor.childNodes[1].tagName,
|
||||
"BR",
|
||||
`${logHint}: insertTextWithQuotations should insert a BR tag`
|
||||
);
|
||||
is(
|
||||
editor.childNodes[2].tagName,
|
||||
"BR",
|
||||
`${logHint}: insertTextWithQuotations should insert a second BR tag`
|
||||
);
|
||||
is(
|
||||
editor.childNodes[3].tagName,
|
||||
"SPAN",
|
||||
`${logHint}: insertTextWithQuotations should insert a SPAN tag`
|
||||
);
|
||||
is(
|
||||
editor.childNodes[3].getAttribute("_moz_quote"),
|
||||
"true",
|
||||
`${logHint}: insertTextWithQuotations should insert SPAN tag with _moz_quote = true`
|
||||
)
|
||||
is(
|
||||
editor.childNodes[3].textContent,
|
||||
"> This is a quote.",
|
||||
`${logHint}: insertTextWithQuotations should insert SPAN tag with the quoted text`
|
||||
)
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
@ -32,5 +32,18 @@ interface nsIEditorMailSupport : nsISupports
|
||||
*/
|
||||
[can_run_script]
|
||||
void rewrap(in boolean aRespectNewlines);
|
||||
|
||||
/**
|
||||
* Inserts a plaintext string at the current location,
|
||||
* with special processing for lines beginning with ">",
|
||||
* which will be treated as mail quotes and inserted
|
||||
* as plaintext quoted blocks.
|
||||
* If the selection is not collapsed, the selection is deleted
|
||||
* and the insertion takes place at the resulting collapsed selection.
|
||||
*
|
||||
* @param aString the string to be inserted
|
||||
*/
|
||||
[can_run_script]
|
||||
void insertTextWithQuotations(in AString aStringToInsert);
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user