Overview
You are tasked with building a core component for an internal developer tool: a custom Code Editor. This editor will be used by engineers to view and modify code snippets directly within the application, enhancing code review workflows and quick edits. A robust and user-friendly code editor is critical for improving developer productivity and ensuring a smooth experience.
What you need to do / Task
Your goal is to create a CodeEditor React component that displays code, provides line numbers, and applies basic syntax highlighting.
- Render Code Content: The component should accept
code (string) as a prop and display it in an editable area.
- Line Numbers: Display dynamic line numbers alongside the code. These numbers should correspond to the current lines of code and update automatically as the code changes.
- Syntax Highlighting: Integrate a basic syntax highlighting solution to visually distinguish keywords, comments, strings, etc. You can use the provided
react-syntax-highlighter library for this purpose.
- User Input: Allow users to type and paste content into the code area. The displayed code, line numbers, and highlighting should update in real-time.
- Scroll Synchronization: Ensure that scrolling in the code display area also scrolls the line number area, and vice-versa, maintaining alignment.
UI/UX expectations
- The editor should have two main vertical sections: line numbers on the left and the code editing area on the right.
- Line numbers should be clearly visible and aligned with their corresponding code lines.
- The code editing area should behave like a standard text editor, allowing text input and selection.
- Both sections should scroll together horizontally and vertically.
- A monospace font should be used for the code and line numbers.
Acceptance criteria
- The
CodeEditor component renders with initial code content.
- Line numbers are correctly displayed and update dynamically based on the number of lines in the code.
- Typing or pasting new content into the editor updates the displayed code and its line numbers.
- Syntax highlighting is visibly applied to the code content.
- Scrolling the code area vertically or horizontally also scrolls the line number area, keeping them aligned.
- The component is responsive to changes in its
code prop.