feat: implement file editor with syntax highlighting and editing

- Install react-simple-code-editor and prismjs dependencies
- Create language detection utility with 50+ file extensions
- Create SyntaxHighlighter component with Prism.js highlighting
- Create CodeEditor component with syntax-highlighted editing
- Create CommitDialog with diff preview and commit message
- Create FileEditor component integrating view/edit/commit flow
- Replace FileViewer with FileEditor in RepoWorkspace
- Add comprehensive CSS styles for editor, highlighter, and dialog
- Support keyboard shortcuts: Ctrl+E (toggle edit), Ctrl+S (save)
- Quality gates: typecheck ✓ lint ✓ build ✓
This commit is contained in:
Fusion
2026-05-19 16:04:48 +02:00
parent 84bf7e4aeb
commit 7261c75bb2
14 changed files with 1533 additions and 90 deletions
+365
View File
@@ -1377,3 +1377,368 @@ a {
background: rgba(107, 114, 128, 0.1);
color: #4b5563;
}
/* File Editor */
.file-editor {
display: flex;
flex-direction: column;
height: 100%;
overflow: hidden;
}
.file-editor-toolbar {
display: flex;
justify-content: space-between;
align-items: center;
padding: 0.75rem 1rem;
background: var(--panel);
border-bottom: 1px solid var(--border);
}
.file-actions {
display: flex;
gap: 0.5rem;
}
.file-editor-content {
flex: 1;
overflow: auto;
background: var(--bg);
}
/* Syntax Highlighter */
.syntax-highlighter {
display: flex;
flex-direction: column;
height: 100%;
}
.highlighter-toolbar {
display: flex;
justify-content: space-between;
align-items: center;
padding: 0.5rem 1rem;
background: var(--panel);
border-bottom: 1px solid var(--border);
}
.language-badge {
font-size: 0.8rem;
padding: 0.2rem 0.5rem;
background: var(--bg);
border-radius: 4px;
color: var(--muted);
}
.copy-button {
font-size: 0.8rem;
padding: 0.25rem 0.5rem;
background: var(--bg);
border: 1px solid var(--border);
border-radius: 4px;
cursor: pointer;
color: var(--ink);
}
.copy-button:hover {
background: var(--brand);
color: white;
border-color: var(--brand);
}
.code-container {
display: flex;
flex: 1;
overflow: auto;
font-family: 'Fira Code', 'Monaco', 'Courier New', monospace;
font-size: 14px;
line-height: 1.5;
}
.line-numbers {
display: flex;
flex-direction: column;
padding: 1rem 0.5rem;
background: var(--panel);
border-right: 1px solid var(--border);
color: var(--muted);
text-align: right;
user-select: none;
min-width: 3rem;
}
.line-number {
padding: 0 0.5rem;
}
.code-block {
flex: 1;
margin: 0;
padding: 1rem;
overflow: auto;
background: transparent;
}
.code-block code {
display: block;
background: transparent;
}
/* Code Editor */
.code-editor {
height: 100%;
overflow: auto;
}
.editor-textarea {
font-family: 'Fira Code', 'Monaco', 'Courier New', monospace;
font-size: 14px;
line-height: 1.5;
min-height: 100%;
}
.editor-textarea-input {
background: transparent;
color: var(--ink);
caret-color: var(--ink);
}
.editor-line {
display: flex;
}
.editor-line-number {
display: inline-block;
width: 3rem;
padding: 0 0.5rem;
text-align: right;
color: var(--muted);
user-select: none;
background: var(--panel);
border-right: 1px solid var(--border);
}
.editor-line-content {
flex: 1;
padding: 0 0.5rem;
white-space: pre;
}
/* Commit Dialog */
.dialog-overlay {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: rgba(0, 0, 0, 0.5);
display: flex;
align-items: center;
justify-content: center;
z-index: 1000;
padding: 1rem;
}
.commit-dialog {
background: var(--panel);
border-radius: 14px;
width: 100%;
max-width: 600px;
max-height: 90vh;
overflow: auto;
box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
}
.dialog-header {
display: flex;
justify-content: space-between;
align-items: center;
padding: 1rem 1.5rem;
border-bottom: 1px solid var(--border);
}
.dialog-header h3 {
margin: 0;
font-size: 1.1rem;
}
.dialog-close {
background: none;
border: none;
font-size: 1.5rem;
cursor: pointer;
color: var(--muted);
padding: 0;
width: 2rem;
height: 2rem;
display: flex;
align-items: center;
justify-content: center;
border-radius: 6px;
}
.dialog-close:hover {
background: var(--bg);
color: var(--ink);
}
.dialog-body {
padding: 1.5rem;
}
.file-info {
margin: 0 0 1rem;
color: var(--muted);
}
.diff-preview {
margin-bottom: 1.5rem;
}
.diff-preview h4 {
margin: 0 0 0.75rem;
font-size: 0.9rem;
color: var(--muted);
}
.diff-content {
background: var(--bg);
border: 1px solid var(--border);
border-radius: 8px;
overflow: auto;
max-height: 300px;
font-family: 'Fira Code', 'Monaco', 'Courier New', monospace;
font-size: 13px;
}
.diff-line {
display: flex;
padding: 0.15rem 0.5rem;
gap: 0.5rem;
}
.diff-line-number {
color: var(--muted);
min-width: 2rem;
text-align: right;
user-select: none;
}
.diff-marker {
width: 1rem;
text-align: center;
font-weight: bold;
}
.diff-added {
background: rgba(16, 185, 129, 0.1);
}
.diff-added .diff-marker {
color: #059669;
}
.diff-removed {
background: rgba(239, 68, 68, 0.1);
}
.diff-removed .diff-marker {
color: #dc2626;
}
.diff-same {
background: transparent;
}
.warning-message {
padding: 0.75rem;
background: rgba(245, 158, 11, 0.1);
color: #d97706;
border-radius: 8px;
margin-bottom: 1rem;
}
.dialog-footer {
display: flex;
justify-content: flex-end;
gap: 0.75rem;
padding: 1rem 1.5rem;
border-top: 1px solid var(--border);
}
/* Prism.js Theme Integration */
code[class*="language-"],
pre[class*="language-"] {
color: var(--ink);
text-shadow: none;
font-family: 'Fira Code', 'Monaco', 'Courier New', monospace;
font-size: 14px;
text-align: left;
white-space: pre;
word-spacing: normal;
word-break: normal;
word-wrap: normal;
line-height: 1.5;
tab-size: 2;
hyphens: none;
}
/* Syntax Highlighting Colors */
.token.comment,
.token.prolog,
.token.doctype,
.token.cdata {
color: var(--muted);
}
.token.punctuation {
color: var(--ink);
}
.token.namespace {
opacity: 0.7;
}
.token.property,
.token.tag,
.token.boolean,
.token.number,
.token.constant,
.token.symbol,
.token.deleted {
color: #f59e0b;
}
.token.selector,
.token.attr-name,
.token.string,
.token.char,
.token.builtin,
.token.inserted {
color: #10b981;
}
.token.operator,
.token.entity,
.token.url,
.language-css .token.string,
.style .token.string {
color: #f43f5e;
}
.token.atrule,
.token.attr-value,
.token.keyword {
color: #3b82f6;
}
.token.function,
.token.class-name {
color: #8b5cf6;
}
.token.regex,
.token.important,
.token.variable {
color: #ec4899;
}