RichText的bug文本缺了一行字

cocoscreator版本3.6.1


显示出来的少了一行字
“我们在收集、使用、存储和共享您个人信息的情”
发布出来运行后也是如此。

原文
亲爱的玩家,我们将依据隐私政策来帮助您了解我们在收集、使用、存储和共享您个人信息的情况以及您享有的相关权利。请您仔细阅读下方信息以了解详细信息。

目录:CocosDashboard_1.1.1\resources.editors\Creator\3.6.1\resources\resources\3d\engine\cocos\2d\components\rich-text.ts
这个方法:


这个部分改成我这样:

然后编辑器点击开发者:

把编译引擎和编译原生模拟器引擎点一下,就ok了

1赞

good

这个bug官方既然一直没修复,我也遇到了!

打包微信小游戏时,还不生效,在Build后的代码里找了半天找到了文件cocos/deprecated-75f8b6f7.js,果然是老代码。修改后,这个文件还有MD5验证,不给改。

搞了一晚上,蛋!疼!

有个pr修复,但是不知道为什么一直没有合到新版本中。3.5.2验证有效。rich-text.zip (10.1 KB)

你这个和楼上那个应该是一样的。

现在是微信环境不给改,估计是和「微信分离引擎」有关,我昨晚最后是把那个方法在外部重新改了一下:

this.richText[‘splitLongStringOver2048’] = (text: string, styleIndex: number)=>{

partStringArr.push(curString);
curString = leftString;
partStringArr.push(curString);

}

1赞

我也遇到了这个问题, 在项目内改了下



// fix engine bug:  cocos version 3.7.1
const LAST_ENGLISH_REG = /[a-zA-Z0-9ÄÖÜäöüßéèçàùêâîôûаíìÍÌïÁÀáàÉÈÒÓòóŐőÙÚŰúűñÑæÆœŒÃÂãÔõěščřžýáíéóúůťďňĚŠČŘŽÁÍÉÓÚŤżźśóńłęćąŻŹŚÓŃŁĘĆĄ-яА-ЯЁёáàảạãăắằẳẵặâấầẩẫậéèẻẽẹêếềểễệiíìỉĩịóòỏõọôốồổỗộơớờởỡợúùủũụưứừửữựýỳỷỹỵđÁÀẢẠÃĂẮẰẲẴẶÂẤẦẨẪẬÉÈẺẼẸÊẾỀỂỄỆIÍÌỈĨỊÓÒỎÕỌÔỐỒỔỖỘƠỚỜỞỠỢÚÙỦŨỤƯỨỪỬỮỰÝỲỶỸỴĐ]+$/;
const  FIRST_ENGLISH_REG = /^[a-zA-Z0-9ÄÖÜäöüßéèçàùêâîôûаíìÍÌïÁÀáàÉÈÒÓòóŐőÙÚŰúűñÑæÆœŒÃÂãÔõěščřžýáíéóúůťďňĚŠČŘŽÁÍÉÓÚŤżźśóńłęćąŻŹŚÓŃŁĘĆĄ-яА-ЯЁёáàảạãăắằẳẵặâấầẩẫậéèẻẽẹêếềểễệiíìỉĩịóòỏõọôốồổỗộơớờởỡợúùủũụưứừửữựýỳỷỹỵđÁÀẢẠÃĂẮẰẲẴẶÂẤẦẨẪẬÉÈẺẼẸÊẾỀỂỄỆIÍÌỈĨỊÓÒỎÕỌÔỐỒỔỖỘƠỚỜỞỠỢÚÙỦŨỤƯỨỪỬỮỰÝỲỶỸỴĐ]/;
function getEnglishWordPartAtFirst (stringToken: string) {
    const result = FIRST_ENGLISH_REG.exec(stringToken);
    return result;
}
export function getEnglishWordPartAtLast (stringToken: string) {
    const result = LAST_ENGLISH_REG.exec(stringToken);
    return result;
}
RichText.prototype["splitLongStringOver2048"] = function (text: string, styleIndex: number) {
    const partStringArr: string[] = [];
    const longStr = text;

    let curStart = 0;
    let curEnd = longStr.length / 2;
    let curString = longStr.substring(curStart, curEnd);
    let leftString = longStr.substring(curEnd);
    let curStringSize = this._calculateSize(styleIndex, curString);
    let leftStringSize = this._calculateSize(styleIndex, leftString);

    // a line should be an unit to split long string
    const lineCountForOnePart = 1;
    const sizeForOnePart = lineCountForOnePart * this.maxWidth;

    // divide text into some pieces of which the size is less than sizeForOnePart
    while (curStringSize.x > sizeForOnePart) {
        curEnd /= 2;
        // at least one char can be an entity, step back.
        if (curEnd < 1) {
            curEnd *= 2;
            break;
        }

        curString = curString.substring(curStart, curEnd);
        leftString = longStr.substring(curEnd);
        curStringSize = this._calculateSize(styleIndex, curString);
    }

    // avoid too many loops
    let leftTryTimes = 1000;
    // the minimum step of expansion or reduction
    let curWordStep = 1;
    while (leftTryTimes && curStart < text.length) {
        while (leftTryTimes && curStringSize.x < sizeForOnePart) {
            const nextPartExec = getEnglishWordPartAtFirst(leftString);
            // add a character, unless there is a complete word at the beginning of the next line
            if (nextPartExec && nextPartExec.length > 0) {
                curWordStep = nextPartExec[0].length;
            }
            curEnd += curWordStep;

            curString = longStr.substring(curStart, curEnd);
            leftString = longStr.substring(curEnd);
            curStringSize = this._calculateSize(styleIndex, curString);

            leftTryTimes--;
        }

        // reduce condition:size > maxwidth && curString.length >= 2
        while (leftTryTimes && curString.length >= 2 && curStringSize.x > sizeForOnePart) {
            curEnd -= curWordStep;
            curString = longStr.substring(curStart, curEnd);
            curStringSize = this._calculateSize(styleIndex, curString);
            // after the first reduction, the step should be 1.
            curWordStep = 1;

            leftTryTimes--;
        }

        // consider there is a part of a word at the end of this line, it should be moved to the next line
        if (curString.length >= 2) {
            const lastWordExec = getEnglishWordPartAtLast(curString);
            if (lastWordExec && lastWordExec.length > 0
                // to avoid endless loop when there is only one word in this line
                && curString !== lastWordExec[0]) {
                curEnd -= lastWordExec[0].length;
                curString = longStr.substring(curStart, curEnd);
            }
        }

        // curStart and curEnd can be float since they are like positions of pointer,
        // but step must be integer because we split the complete characters of which the unit is integer.
        // it is reasonable that using the length of this result to estimate the next result.
        partStringArr.push(curString);
        const partStep = curString.length;
        curStart = curEnd;
        curEnd += partStep;

        curString = longStr.substring(curStart, curEnd);
        leftString = longStr.substring(curEnd);
        leftStringSize = this._calculateSize(styleIndex, leftString);

        leftTryTimes--;

        // Exit: If the left part string size is less than 2048, the method will finish.
        if (leftStringSize.x < 2048) {
            curStart = text.length;
            curEnd = text.length;
            partStringArr.push(curString);  //FIX 主要是改了这个bug, 不然richtext会漏文字
            curString = leftString;
            partStringArr.push(curString);
            break;
        } else {
            curStringSize = this._calculateSize(styleIndex, curString);
        }
    }

    return partStringArr;
}


不错一会儿试试