import { useRef } from 'react' import { LangBadge } from './primitives' // Osnovna syntax tinting za čitljivost (nije full highlighter) function SyntaxTinted({ code }) { const tokens = code.split( /(\b(?:def|return|if|else|elif|for|while|import|from|class|in|not|and|or|True|False|None|self|function|const|let|var|public|private|static|void|int|string|bool|unsigned|include|struct|typedef)\b|"[^"]*"|'[^']*'|`[^`]*`|\/\/[^\n]*|#[^\n]*|\b\d+\b)/g ) return tokens.map((t, i) => { if (/^(def|return|if|else|elif|for|while|import|from|class|in|not|and|or|True|False|None|self|function|const|let|var|public|private|static|void|int|string|bool|unsigned|struct|typedef)$/.test(t)) return {t} if (/^["'`].*["'`]$/.test(t)) return {t} if (/^(#|\/\/)/.test(t)) return {t} if (/^\d+$/.test(t)) return {t} return {t} }) } export default function CodeEditor({ code, onChange, lang = 'Python', readOnly = false, height = 360, annotations = [], filename, }) { const scrollRef = useRef(null) const lines = (code || '').split('\n') const displayName = filename || ('submission.' + ( lang === 'Python' ? 'py' : lang === 'Java' ? 'java' : lang === 'JavaScript' ? 'js' : lang === 'C++' ? 'cpp' : lang === 'C' ? 'c' : 'txt' )) // Mapa linija na anotacije za brzo traženje const annotMap = {} for (const a of annotations) { annotMap[a.line] = a } return (
| {lineNum} | {/* Ikona oznake (samo za označene linije) */}{ann ? '⚠' : ''} | {/* Kod */}
|
{/* Tooltip poruka (prikazuje se desno ako postoji anotacija) */}
{ann && (
{ann.note} | )}