Skip to content

fix(playground): handle trailing newlines correctly - #37

Closed
ohnishant wants to merge 2 commits into
mainfrom
t3code/e440db81
Closed

ohnishant wants to merge 2 commits into
mainfrom
t3code/e440db81

Conversation

@ohnishant

Copy link
Copy Markdown
Owner

Summary

  • insert one source newline for each plain Enter keypress
  • allow the editor to return to an empty source after deleting all content
  • preserve autocomplete Enter behavior and Ctrl+Enter run behavior

Issues

Closes #35
Closes #36

Verification

  • go test ./...
  • go vet ./...
  • gofmt -l .
  • Chromium browser checks at desktop and iPhone 12 Pro viewports

The two fixes are separate commits so each issue can be reviewed independently.

@ohnishant ohnishant left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Two things I want to flag before this lands.

First, the Enter handler does not check e.isComposing. When someone uses an IME, pressing Enter confirms the composition, and our preventDefault() plus newline insert would break that. I think we should add an early return for e.isComposing.

Second, the empty-editor sentinel in editorSource is tightly scoped. It only catches a single <br> or a single <div><br></div>. That is enough for the browser behavior I saw in testing, but if a browser leaves multiple empty block elements, we would still read a stray newline. Since we rebuild the DOM with buildEditorFragment on every edit, this is probably fine, but it is a narrow guard.

I will push a small follow-up for the IME case.

@ohnishant

Copy link
Copy Markdown
Owner Author

Superseded by #38. I had to rename the branch to follow the repo convention, so GitHub required a new PR.

@ohnishant ohnishant closed this Aug 29, 2026
@ohnishant
ohnishant deleted the t3code/e440db81 branch August 29, 2026 08:49
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.

playground: final empty line cannot be deleted playground: Enter at end inserts two newlines

1 participant