Add auto indentation to the current code editor - #59
CX330Blake wants to merge 1 commit into
Conversation
2fd3c0f to
34af192
Compare
76f3fc3 to
7ccb3eb
Compare
jserv
left a comment
There was a problem hiding this comment.
Read https://chris.beams.io/git-commit carefully and enforce the rules.
ColtenOuO
left a comment
There was a problem hiding this comment.
Overall, I think this is heading in the right direction, just left a few small suggestions and minor issues to address.
| const lineStart = start === 0 ? 0 : value.lastIndexOf("\n", start - 1) + 1; | ||
| const before = value.slice(lineStart, start); | ||
| const indentation = before.match(/^[ \t]*/)[0]; | ||
| const opener = before.trimEnd().slice(-1); |
There was a problem hiding this comment.
This is fine to handle as a follow-up, but I'd suggest mentioning it in the PR description for future reference.
| const indentation = before.match(/^[ \t]*/)[0]; | ||
| const opener = before.trimEnd().slice(-1); | ||
| const closer = { "{": "}", "[": "]", "(": ")" }[opener]; | ||
| const comment = /^[ \t]*(#|\/\/|\/\*)/.test(before); |
There was a problem hiding this comment.
Moving forward, it might be better to have a dedicated helper that detects the programming language first, rather than trying to cover every edge case with a single regex.
Otherwise, if we also need to account for C++, #define might trigger a false positive.
| ); | ||
| } | ||
| }); | ||
|
|
There was a problem hiding this comment.
I'd suggest adding some tests for the newly added comment handling.
ex.
[" # Steps:", "python"]
[" // setup {", "javascript"]
["if ready: # explain", "python"]
["run(); // setup {", "javascript"]
ColtenOuO
left a comment
There was a problem hiding this comment.
By the way, some of the intermediate review commits can be squashed together.
Reduce manual formatting during interviews by preserving the current line indentation and adding one level after opening delimiters and Python block statements. Keep delimiter pairs readable by moving matching closing delimiters onto a separate line when appropriate. Avoid treating comment-only lines as block openers so comments do not introduce unexpected indentation. Add regression tests to cover indentation behavior, comments, and C++ preprocessor directives.
7ccb3eb to
0164ead
Compare
ColtenOuO
left a comment
There was a problem hiding this comment.
Would it be worth adding a browser integration test (actually interact with the textarea via Playwright)? Right now, we can only verify whether individual methods work correctly, but we can't validate if the full end-to-end user behavior in the browser matches our expectations.
It might be worth adding because the entire flow actually involves multiple steps. Testing just one part of those steps might not give us comprehensive coverage.
Summary
Reduce manual formatting during interviews by preserving the current
line indentation and adding one level after opening delimiters and
Python block statements.
Keep delimiter pairs readable by moving matching closing delimiters onto
a separate line when appropriate. Avoid treating comment-only lines as
block openers so comments do not introduce unexpected indentation.
Add regression tests to cover indentation behavior, comments, and C++
preprocessor directives.
Known Limitations
a trailing comment like
int func() { //may not trigger the expectedindentation.
as comment-only lines.
These cases are intentionally left for a follow-up to keep this change
lightweight.