Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug: SetContentContrlText for block level. #4752

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions tests/word/content-control/block-level/setContentControlText.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>

<title>Block-level content control test</title>

<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<link type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/qunit/2.16.0/qunit.css" rel="stylesheet"
media="screen"/>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/qunit/2.16.0/qunit.js"></script>
<script type="text/javascript"
src="https://cdnjs.cloudflare.com/ajax/libs/xregexp/3.2.0/xregexp-all.min.js"></script>


<script type="text/javascript" src="../../../../develop/sdkjs/word/scripts.js"></script>
<script type="text/javascript">
window.sdk_scripts.forEach(function(item)
{
document.write('<script type="text/javascript" src="../' + item + '"><\/script>');
});
</script>

<script type="text/javascript" src="../../common/common.js"></script>
<script type="text/javascript" src="../../common/editor.js"></script>
<script type="text/javascript" src="../../common/document.js"></script>
<script type="text/javascript" src="../../common/measurer.js"></script>

<script type="text/javascript" src="setContentControlText.js"></script>
</head>
<body>
<h1 id="qunit-header">Test the api of BlockLevel</h1>
<h2 id="qunit-banner"></h2>
<div id="qunit-testrunner-toolbar"></div>
<h2 id="qunit-userAgent"></h2>
<ol id="qunit-tests"></ol>
<div id="qunit-fixture">test SetContentControlText api</div>
</body>
</html>
53 changes: 53 additions & 0 deletions tests/word/content-control/block-level/setContentControlText.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* (c) Copyright Ascensio System SIA 2010-2023
*
* This program is a free software product. You can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License (AGPL)
* version 3 as published by the Free Software Foundation. In accordance with
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
* that Ascensio System SIA expressly excludes the warranty of non-infringement
* of any third-party rights.
*
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
*
* You can contact Ascensio System SIA at 20A-12 Ernesta Birznieka-Upisha
* street, Riga, Latvia, EU, LV-1050.
*
* The interactive user interfaces in modified source and object code versions
* of the Program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU AGPL version 3.
*
* Pursuant to Section 7(b) of the License you must retain the original Product
* logo when distributing the program. Pursuant to Section 7(e) we decline to
* grant you any rights under trademark law for use of our trademarks.
*
* All the Product's GUI elements, including illustrations and icon sets, as
* well as technical writing content are licensed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
*
*/

"use strict";

$(function ()
{
const logicDocument = AscTest.CreateLogicDocument()

QUnit.test("Test SetContentControlText api for BlockLevel", function (assert)
{
AscTest.ClearDocument();
let p = AscTest.CreateParagraph();
logicDocument.AddToContent(0, p);
AscTest.MoveCursorToParagraph(p);

let block = logicDocument.AddContentControl(Asc.c_oAscSdtLevelType.Block);
logicDocument.SetContentControlText("i am block level", block);

assert.strictEqual(block.IsUseInDocument(), true, "Check if block level is added to the document");
assert.strictEqual(AscTest.GetParagraphText(block.GetLastParagraph()), "i am block level");
});

});
2 changes: 1 addition & 1 deletion word/Editor/Document.js
Original file line number Diff line number Diff line change
Expand Up @@ -17025,7 +17025,7 @@ CDocument.prototype.SetContentControlText = function(sText, oCC)

var oRun;
if (oCC.IsBlockLevel())
oRun = this.Content.MakeSingleParagraphContent().MakeSingleRunParagraph(true);
oRun = oCC.Content.MakeSingleParagraphContent().MakeSingleRunParagraph(true);
else if (oCC.IsInlineLevel())
oRun = oCC.MakeSingleRunElement(true);

Expand Down