MCPcopy Create free account
hub / github.com/donghaxkim/react-rewrite / commitAndExit

Function commitAndExit

packages/overlay/src/inline-text-edit.ts:484–576  ·  view source on GitHub ↗
(options?: {
  nextSelection?: HTMLElement | null;
  clearSelection?: boolean;
  reselectEditedElement?: boolean;
})

Source from the content-addressed store, hash-verified

482}
483
484function commitAndExit(options?: {
485 nextSelection?: HTMLElement | null;
486 clearSelection?: boolean;
487 reselectEditedElement?: boolean;
488}): void {
489 if (!editingElement) return;
490
491 const newText = lastKnownText;
492 const cursorOffset = getCaretOffsetWithin(editingElement);
493 const changed = newText !== originalTextContent;
494 const textAnchor = changed ? buildTextEditAnchor(originalTextContent, newText) : undefined;
495
496 console.log("[ReactRewrite:textEdit] commitAndExit changed:", changed, "componentInfo:", componentInfo?.componentName, "filePath:", componentInfo?.filePath);
497
498 if (changed && componentInfo) {
499 // If filePath is empty, try file discovery (grep-based lookup by component name)
500 if (!componentInfo.filePath && componentInfo.componentName) {
501 const cached = getCachedFilePath(componentInfo.componentName);
502 if (cached) {
503 componentInfo = { ...componentInfo, filePath: cached };
504 } else {
505 // Fire async discovery — won't block, annotation created with empty path for now
506 requestFileDiscovery(componentInfo.componentName).then((discovered) => {
507 if (discovered) setCachedFilePath(componentInfo!.componentName, discovered);
508 });
509 }
510 }
511
512 // All text edits create annotations — committed via confirm button
513 {
514 const ann: TextEditAnnotation = {
515 type: "textEdit",
516 id: `text-edit-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`,
517 componentName: componentInfo.componentName,
518 filePath: componentInfo.filePath || "",
519 lineNumber: componentInfo.lineNumber || 0,
520 columnNumber: componentInfo.columnNumber || 0,
521 originalText: originalTextContent,
522 newText,
523 cursorOffset,
524 textAnchor,
525 };
526 const identity: ElementIdentity = {
527 componentName: componentInfo.componentName,
528 filePath: componentInfo.filePath || "",
529 lineNumber: componentInfo.lineNumber || 0,
530 columnNumber: componentInfo.columnNumber || 0,
531 tagName: componentInfo.tagName,
532 };
533 addTextEditAnnotation(ann, identity, originalInnerHTML, {
534 tagName: editingElement?.tagName.toLowerCase() || componentInfo.tagName,
535 className: editingElement?.className || undefined,
536 parentTagName: editingElement?.parentElement?.tagName.toLowerCase(),
537 parentClassName: editingElement?.parentElement?.className || undefined,
538 nthOfType: editingElement ? computeNthOfType(editingElement) : undefined,
539 elementId: editingElement?.id || undefined,
540 jsxPath: componentInfo.jsxPath,
541 });

Callers 4

handleDblClickFunction · 0.85
handleBlurFunction · 0.85
handleOutsidePointerDownFunction · 0.85
handleKeydownFunction · 0.85

Calls 12

getCaretOffsetWithinFunction · 0.85
getCachedFilePathFunction · 0.85
requestFileDiscoveryFunction · 0.85
setCachedFilePathFunction · 0.85
addTextEditAnnotationFunction · 0.85
addChangeEntryFunction · 0.85
truncateFunction · 0.85
exitEditModeFunction · 0.85
selectElementFunction · 0.85
clearSelectionFunction · 0.85
buildTextEditAnchorFunction · 0.70
computeNthOfTypeFunction · 0.70

Tested by

no test coverage detected