Skip to content

textWidth ignores leading and trailing spaces #8067

Merged
perminder-17 merged 5 commits into
processing:dev-2.0from
nitin-rajpoot:fix/textwidth-spaces
Sep 5, 2025
Merged

textWidth ignores leading and trailing spaces #8067
perminder-17 merged 5 commits into
processing:dev-2.0from
nitin-rajpoot:fix/textwidth-spaces

Conversation

@nitin-rajpoot
Copy link
Copy Markdown
Contributor

@nitin-rajpoot nitin-rajpoot commented Sep 4, 2025

Resolves #8052

PR Checklist

@perminder-17
Copy link
Copy Markdown
Collaborator

Hi, Thanks again for opening a PR on dev-2.0 branch. Actuallly, the reference looks something like this :
Screenshot from 2025-09-04 09-06-45

Can you please replace your code with this sketch : https://editor.p5js.org/aman12345/sketches/E0wMMg6ha which shows how trailing spaces are ignored.?

Copy link
Copy Markdown
Collaborator

@perminder-17 perminder-17 left a comment

Choose a reason for hiding this comment

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

Just some minor suggestion.

Comment thread src/type/textCore.js Outdated
Comment thread src/type/textCore.js Outdated
test('should return a number for number input', function() {
assert.isNumber(myp5.textWidth(100));
});
test('should ignore leading and trailing spaces', function() {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for adding tests.

Nitin2332 and others added 3 commits September 4, 2025 09:20
Co-authored-by: Perminder Singh <127239756+perminder-17@users.noreply.github.com>
Co-authored-by: Perminder Singh <127239756+perminder-17@users.noreply.github.com>
Comment thread src/type/textCore.js Outdated
Comment on lines +820 to +821
* **Note:** In p5.js 2.0+, leading and trailing spaces are ignored.
* `textWidth(" Hello ")` returns the same width as `textWidth("Hello")`.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Just last suggestion, I think you cannot add a note between two example sketches. If you want to add this, you should move it to line number - 758.

Copy link
Copy Markdown
Collaborator

@perminder-17 perminder-17 left a comment

Choose a reason for hiding this comment

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

Looks good!

@perminder-17 perminder-17 merged commit ca016c3 into processing:dev-2.0 Sep 5, 2025
2 checks passed
@nitin-rajpoot nitin-rajpoot deleted the fix/textwidth-spaces branch September 8, 2025 12:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants