Skip to content

Commit 1bb55d2

Browse files
Remove selection tracking and update textarea handler
Removed selection tracking logic and updated textarea change handler.
1 parent 06503e2 commit 1bb55d2

1 file changed

Lines changed: 5 additions & 35 deletions

File tree

src/JavaCodeVisualizer.jsx

Lines changed: 5 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1998,30 +1998,6 @@ export default function JavaCodeVisualizer() {
19981998

19991999
const displayFileName = activeFileName || derivedFileName;
20002000

2001-
// Selection tracking for custom highlight
2002-
const [selRange, setSelRange] = useState({ start: -1, end: -1 });
2003-
2004-
const handleSelect = useCallback(() => {
2005-
const ta = textareaRef.current;
2006-
if (!ta) return;
2007-
const { selectionStart, selectionEnd } = ta;
2008-
if (selectionStart === selectionEnd) {
2009-
setSelRange({ start: -1, end: -1 });
2010-
} else {
2011-
// Convert char offsets to line numbers
2012-
const text = ta.value;
2013-
let startLine = 0, endLine = 0, pos = 0;
2014-
const allLines = text.split('\n');
2015-
for (let i = 0; i < allLines.length; i++) {
2016-
const lineEnd = pos + allLines[i].length;
2017-
if (pos <= selectionStart && selectionStart <= lineEnd) startLine = i;
2018-
if (pos <= selectionEnd - 1 && selectionEnd - 1 <= lineEnd) { endLine = i; break; }
2019-
pos = lineEnd + 1; // +1 for newline
2020-
}
2021-
setSelRange({ start: startLine, end: endLine });
2022-
}
2023-
}, []);
2024-
20252001
// Handle keyboard in textarea
20262002
const handleKeyDown = (e) => {
20272003
if (e.key === 'Tab') {
@@ -2310,11 +2286,11 @@ export default function JavaCodeVisualizer() {
23102286
text-rendering: auto;
23112287
}
23122288
.editor-textarea::selection {
2313-
background: transparent;
2289+
background: rgba(56,139,253,0.3);
23142290
color: transparent;
23152291
}
23162292
.editor-textarea::-moz-selection {
2317-
background: transparent;
2293+
background: rgba(56,139,253,0.3);
23182294
color: transparent;
23192295
}
23202296
@@ -2574,7 +2550,6 @@ export default function JavaCodeVisualizer() {
25742550
const isExecuted = executedLines.has(lineNum);
25752551
const isError = lineNum === errorLine;
25762552
const hasBreakpoint = breakpoints.has(lineNum);
2577-
const isSelected = selRange.start >= 0 && idx >= selRange.start && idx <= selRange.end;
25782553

25792554
return (
25802555
<div
@@ -2583,9 +2558,7 @@ export default function JavaCodeVisualizer() {
25832558
display: 'flex',
25842559
minHeight: 28,
25852560
lineHeight: '28px',
2586-
background: isSelected
2587-
? (isDark ? 'rgba(56,139,253,0.25)' : 'rgba(9,105,218,0.15)')
2588-
: isCurrentLine
2561+
background: isCurrentLine
25892562
? t.currentLineBg
25902563
: isError
25912564
? t.errorLineBg
@@ -2597,7 +2570,7 @@ export default function JavaCodeVisualizer() {
25972570
<div
25982571
className="line-gutter"
25992572
onClick={() => toggleBreakpoint(lineNum)}
2600-
style={{ lineHeight: '28px', fontSize: 12, color: isSelected ? t.accent : isCurrentLine ? t.accent : t.textDim, pointerEvents: 'auto' }}
2573+
style={{ lineHeight: '28px', fontSize: 12, color: isCurrentLine ? t.accent : t.textDim, pointerEvents: 'auto' }}
26012574
>
26022575
{hasBreakpoint && <div className="breakpoint-dot" />}
26032576
{!hasBreakpoint && isExecuted && !isCurrentLine && <div className="executed-dot" />}
@@ -2629,11 +2602,8 @@ export default function JavaCodeVisualizer() {
26292602
ref={textareaRef}
26302603
className="editor-textarea"
26312604
value={code}
2632-
onChange={(e) => { setCode(e.target.value); if (isRunning) handleReset(); setSelRange({ start: -1, end: -1 }); }}
2605+
onChange={(e) => { setCode(e.target.value); if (isRunning) handleReset(); }}
26332606
onKeyDown={handleKeyDown}
2634-
onSelect={handleSelect}
2635-
onMouseUp={handleSelect}
2636-
onKeyUp={handleSelect}
26372607
onScroll={(e) => {
26382608
if (overlayScrollRef.current) {
26392609
overlayScrollRef.current.scrollTop = e.target.scrollTop;

0 commit comments

Comments
 (0)