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

feat(2d): code bounding box helpers #948

Merged
merged 1 commit into from
Feb 10, 2024

Conversation

aarthificial
Copy link
Contributor

No description provided.

@@ -368,7 +376,123 @@ export class Code extends Shape {
* @param pattern - Either a string or a regular expression to match.
*/
public findLastRange(pattern: string | RegExp): CodeRange {
return findAllCodeRanges(this.parsed(), pattern).at(-1) ?? [[0, 0], [0, 0]];
return (
findAllCodeRanges(this.parsed(), pattern).at(-1) ?? [
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there optimization we should worry about here? Normally findLast or findFirst are used to avoid a full string iteration if possible, although I'm not sure it's worth it here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't know how to do that while supporting regex tbh.
The function is mainly for convenience but I'm always open to optimization propositions.

@aarthificial aarthificial merged commit 0ffd56f into motion-canvas:main Feb 10, 2024
9 checks passed
@aarthificial aarthificial deleted the code-bbox-helpers branch February 10, 2024 14:11
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.

None yet

2 participants