@happy-nut/monacori 0.1.17 → 0.1.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3345,25 +3345,35 @@ function updateSourceCaret(prev, lines, language) {
3345
3345
  // Restore the line the caret left: drop the caret span, re-highlight the full line.
3346
3346
  if (prev && prev.lineIndex !== viewerCursor.lineIndex) {
3347
3347
  const prevRow = rowFor(prev.lineIndex);
3348
- if (prevRow) {
3349
- prevRow.classList.remove('cursor-line');
3350
- if (!rendered) {
3351
- const prevCell = prevRow.querySelector('.source-code');
3352
- if (prevCell) prevCell.innerHTML = highlightLine(lines[prev.lineIndex] || '', language);
3353
- }
3354
- }
3348
+ if (prevRow) prevRow.classList.remove('cursor-line');
3355
3349
  }
3350
+ // Drop the old caret span WITHOUT re-highlighting the line — re-tokenizing a line on every caret move is
3351
+ // what made holding an arrow key stutter. (The diff caret already works this way: insert/remove a span.)
3352
+ if (!rendered) body.querySelectorAll('.code-cursor').forEach((s) => { const p = s.parentNode; if (p) { p.removeChild(s); if (p.normalize) p.normalize(); } });
3356
3353
  // Reconcile the go-to-definition highlight (set only on symbol jumps, cleared on plain moves).
3357
3354
  body.querySelectorAll('.source-row.symbol-target').forEach((r) => r.classList.remove('symbol-target'));
3358
3355
  if (viewerCursor.targetLine >= 0) rowFor(viewerCursor.targetLine)?.classList.add('symbol-target');
3359
- // Rebuild the new caret line with the caret span.
3360
3356
  const row = rowFor(viewerCursor.lineIndex);
3361
3357
  if (!row) { if (!rendered) openSourceFile(viewerCursor.path, false); return; } // line not in the DOM — full re-render (eager source only)
3362
3358
  row.classList.add('cursor-line');
3363
- if (!rendered) {
3364
- const cell = row.querySelector('.source-code');
3365
- if (cell) cell.innerHTML = renderLineWithCursor(lines[viewerCursor.lineIndex] || '', language, viewerCursor.column);
3366
- }
3359
+ if (!rendered) insertSourceCaret(row, viewerCursor.column);
3360
+ }
3361
+ // Insert the caret span at `column` of `row` via a real DOM range into the already-highlighted line — the
3362
+ // same cheap technique the diff caret uses, so holding an arrow key never re-tokenizes a line.
3363
+ function insertSourceCaret(row, column) {
3364
+ var cell = row.querySelector('.source-code');
3365
+ if (!cell || (cell.textContent || '').length === 0) return; // empty line: the cursor-line background marks it
3366
+ var pos = diffCaretDomPosition(cell, column);
3367
+ if (!pos) return;
3368
+ var span = document.createElement('span');
3369
+ span.className = 'code-cursor';
3370
+ span.setAttribute('aria-hidden', 'true');
3371
+ try {
3372
+ var off = pos.node.nodeType === 3 ? Math.min(pos.offset, (pos.node.textContent || '').length) : pos.offset;
3373
+ var range = document.createRange();
3374
+ range.setStart(pos.node, off); range.collapse(true);
3375
+ range.insertNode(span);
3376
+ } catch (e) {}
3367
3377
  }
3368
3378
 
3369
3379
  function openSourceAt(path, lineIndex, column) {
@@ -3992,6 +4002,7 @@ function openSourceFile(path, shouldSwitch = true) {
3992
4002
  } else {
3993
4003
  body.innerHTML = renderSourceTable(file, '');
3994
4004
  if (httpEnvSelect) httpEnvSelect.classList.add('hidden');
4005
+ if (viewerCursor && viewerCursor.path === path) { var ccr = body.querySelector('.source-row.cursor-line'); if (ccr) insertSourceCaret(ccr, viewerCursor.column); }
3995
4006
  }
3996
4007
  updateRenderToggle(path);
3997
4008
  renderSourceComments();
@@ -4527,7 +4538,7 @@ function renderSourceTable(file, query) {
4527
4538
  return [
4528
4539
  '<tr class="' + classes + '" data-line-index="' + index + '">',
4529
4540
  '<td class="num">' + String(index + 1) + '</td>',
4530
- '<td class="source-code">' + (isCursorLine ? renderLineWithCursor(line, file.language || 'text', cursor.column) : highlightLine(line, file.language || 'text')) + '</td>',
4541
+ '<td class="source-code">' + highlightLine(line, file.language || 'text') + '</td>',
4531
4542
  '</tr>',
4532
4543
  ].join('');
4533
4544
  }).join('');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@happy-nut/monacori",
3
- "version": "0.1.17",
3
+ "version": "0.1.18",
4
4
  "description": "Validation control plane for AI-generated code changes.",
5
5
  "type": "module",
6
6
  "repository": {