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 missing spaces in RichText #5116

Merged
merged 8 commits into from Aug 16, 2019
Merged

fix missing spaces in RichText #5116

merged 8 commits into from Aug 16, 2019

Conversation

@Marssssssss
Copy link

@Marssssssss Marssssssss commented Aug 7, 2019

Re: cocos-creator/2d-tasks#1646

Changes:

  • delete values which are got by trim() on variables 'text' and 'sText'
  • change functions substr() to substring() in function fragmentText
cocos2d/core/utils/text-utils.js Outdated Show resolved Hide resolved
add code comments before using substring
@Marssssssss
Copy link
Author

@Marssssssss Marssssssss commented Aug 15, 2019

因为单词换行需要向前缩进,左边的空格需要去除,同时因为在处理带标签文本的时候会单独提取出来,导致带标签文本前面的空格会算在之前的字符串段内,在执行 trim() 的时候会删除掉空格串,所以这里将 trim() 改为了 trimLeft() ,并在 polyfill 中添加了某些不兼容该方法的浏览器对该方法的兼容。

has made code style better
PPpro
PPpro approved these changes Aug 15, 2019

if (!String.prototype.trimLeft) {
String.prototype.trimLeft = function () {
return this.replace(/^\s+/g, '');
Copy link
Member

@jareguo jareguo Aug 16, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里不需要 /g 吧?

Copy link
Author

@Marssssssss Marssssssss Aug 16, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里不需要 /g 吧?

这里的语义只匹配一次确实不需要 /g

Copy link
Author

@Marssssssss Marssssssss Aug 16, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里不需要 /g 吧?

已修改

@jareguo jareguo merged commit 69e3b3b into cocos-creator:v2.1.3 Aug 16, 2019
1 check passed
jareguo added a commit that referenced this issue Aug 16, 2019
* commit 'aa5ddf4e74f014c2b5f066539136f8c25e7f8326':
  optimize bezier calculation (#5155)
  fix missing spaces in RichText (#5116)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants