adobe-photoshop / generator-core

Core Node.js library for Adobe Photoshop CC's Generator extensibility layer

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Text length for last paragraph

shalanah opened this issue · comments

Looks like the last paragraph is one character longer than the string provided. Just wondering if this is a bug, or intentional. Are we just missing the last character of the paragraph?

{
  "textKey": "testing",
  "textStyleRange": [
    {
      "from": 0,
      "to": 8, // should be 7 unless an assumed end of paragraph character
      "textStyle": {}
    }
  ],
  "paragraphStyleRange": [
    {
      "from": 0,
      "to": 8, // should be 7 unless an assumed end of paragraph character
      "paragraphStyle": {}
    }
  ]
}

@shalanah could you please provide a little more context? What are the simple steps to reproduce the data you included in the bug description?

Sure, no problem!

Example 1:

  • Create a textbox with the text "Lorem\rIpsum"
Paragraph 1: "Lorem\r"

Looking at the first paragraphStyleRange we have from: 0 and to: 6 which works perfectly. It also gives us an accurate length of 6 characters ( 6 - 0 ).

Paragraph 2: "Ipsum"

Here we have from: 6 and end with to: 12. This gives us an inaccurate length of 6 characters ( 12 - 6 ) when "Ipsum" is only 5 characters long.

"text": {
    "textKey": "Lorem\rIpsum",
    "paragraphStyleRange": [
        {
            "from": 0, // good
            "to": 6, // good
            "paragraphStyle": '...'
        },
        {
            "from": 6, // good
            "to": 12, // one character too long
            "paragraphStyle": '...'
        }
    ]
}

Example 2:

  • Create a text box with just the text "Lorem"
Paragraph 1: "Lorem"

Looking at the paragraphStyleRange we have from: 0 and to: 6. This gives us the inaccurate length of 6 characters when "Lorem" is only 5 characters long.

"text": {
    "textKey": "Lorem",
    "paragraphStyleRange": [
        {
            "from": 0, // good
            "to": 6, // one character too long
            "paragraphStyle": '...'
        }
    ]
}

I was able to reproduce this, and I can't see how this would be considered correct. But I also can't make a strong case for trying to change it.

Another way to look at it... If you don't factor \r in the paragraph text then they're both off by one!
lorem = 5
ipsum = 5

cc: @timothynoel in case you feel that this could/should be addressed in photoshop proper.