-
Notifications
You must be signed in to change notification settings - Fork 117
feat: input_code_editor()
#2128
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
Open
gadenbuie
wants to merge
15
commits into
main
Choose a base branch
from
feat/input-code
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
+7,111
−36
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Ports the `input_code_editor()` component from bslib PR #1274 to py-shiny. ## Overview `input_code_editor()` is a lightweight code editor input with syntax highlighting powered by prism-code-editor. It supports 20+ languages, multiple themes, and automatic light/dark mode switching. ## Added - `input_code_editor()` - Create a code editor input - `update_code_editor()` - Update editor from server - `code_editor_themes()` - List available themes ## Key decisions for human review 1. **Dependency structure**: The code editor uses two HTML dependencies: - `prism-code-editor` (vendored library for syntax highlighting) - `bslib-code-editor-js` (the Shiny input binding) 2. **Themes list**: Manually hardcoded the theme list to match the vendored CSS files. The R version discovers these dynamically, but Python doesn't have easy access to the vendored directory at runtime. 3. **Language validation**: Using a hardcoded tuple of supported languages instead of dynamic discovery, matching the R implementation's approach. 4. **Manual vendoring**: Due to issues with the automated vendoring script (ionRangeSlider CSS step fails), assets were manually copied from the bslib feat/input-code branch. Updated htmlDependencies.R to include the prism-code-editor copy for future runs once bslib PR is merged. 5. **Value handling**: The `value` parameter accepts either a string or a sequence of strings (lines), matching Python idioms. 6. **Fill behavior**: Added `html-fill-container` and `html-fill-item` classes for fillable layout support, similar to other fill components. Related: rstudio/bslib#1274 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Phase 2 (continued): - Create API examples for input_code_editor and update_code_editor - Add InputCodeEditor Playwright controller with methods for: - set(), submit() for setting values and submitting via Ctrl/Cmd+Enter - expect_value(), expect_language(), expect_theme_light(), expect_theme_dark() - expect_read_only(), expect_line_numbers(), expect_word_wrap() - expect_tab_size(), expect_height() Phase 3: - Port unit tests from bslib (35 pytest tests covering validation, HTML structure, parameters, values, indentation, labels, languages, and warnings) - Create Playwright end-to-end tests (11 tests covering initial state, updates, read-only mode, language switching, and server-side updates) - Update CHANGELOG with new feature description - Run quality checks (format, type-check) - Update API reference configuration (core, express, and testing docs) Technical decisions: - Validation in update_code_editor happens BEFORE requiring active session to enable testing without session - InputCodeEditor controller uses bslib-code-editor as loc_container (not div.shiny-input-container) since the custom element is its own container - Platform detection for Ctrl/Cmd key uses navigator.platform evaluation 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
cpsievert
reviewed
Jan 6, 2026
cpsievert
reviewed
Jan 6, 2026
2c3e2db to
1d36380
Compare
1d36380 to
5848066
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Adds
input_code_editor(), a lightweight code editor input with syntax highlighting, ported from rstudio/bslib#1274.Features
API