MCPcopy
hub / github.com/marktext/marktext / _handleClickInlineImage

Method _handleClickInlineImage

packages/muya/src/selection/index.ts:521–615  ·  view source on GitHub ↗
(event: Event, imageWrapper: HTMLElement)

Source from the content-addressed store, hash-verified

519
520 // Handle click inline image.
521 private _handleClickInlineImage(event: Event, imageWrapper: HTMLElement) {
522 event.preventDefault();
523 event.stopPropagation();
524 const { eventCenter } = this.muya;
525 const imageInfo = getImageInfo(imageWrapper);
526 const { target } = event;
527 if (!(target instanceof Node))
528 return;
529 const deleteContainer = isHTMLElement(target)
530 ? target.closest('.mu-image-icon-close')
531 : null;
532 const contentDom = findContentDOM(target);
533
534 if (!contentDom)
535 return;
536
537 const contentBlock = contentDom[BLOCK_DOM_PROPERTY] as Format;
538
539 if (deleteContainer) {
540 contentBlock.deleteImage(imageInfo);
541
542 return;
543 }
544
545 // Handle image click, to select the current image
546 if (isHTMLElement(target) && target.tagName === 'IMG') {
547 // Handle show image toolbar
548 const rect = imageWrapper
549 .querySelector(`.${CLASS_NAMES.MU_IMAGE_CONTAINER}`)
550 ?.getBoundingClientRect();
551 const reference = {
552 getBoundingClientRect: () => rect,
553 width: imageWrapper.offsetWidth,
554 height: imageWrapper.offsetHeight,
555 };
556
557 // Show image edit tool bar.
558 eventCenter.emit('muya-image-toolbar', {
559 block: contentBlock,
560 reference,
561 imageInfo,
562 });
563
564 // Handle show image transformer.
565 // marktext d26f5092 (#1335): the resize bar should only appear for
566 // block-aligned images. Inline images flow with surrounding text
567 // and dragging their edges has no meaningful resize semantics.
568 if (shouldShowImageResizeBar(imageInfo.token)) {
569 const imageSelector = `#${imageInfo.imageId}`;
570
571 const imageContainer = document.querySelector(
572 `${imageSelector} .${CLASS_NAMES.MU_IMAGE_CONTAINER}`,
573 );
574
575 eventCenter.emit('muya-transformer', {
576 block: contentBlock,
577 reference: imageContainer,
578 imageInfo,

Callers 1

handleClickMethod · 0.95

Calls 10

setSelectionMethod · 0.95
getImageInfoFunction · 0.90
isHTMLElementFunction · 0.90
findContentDOMFunction · 0.90
shouldShowImageResizeBarFunction · 0.90
closestMethod · 0.80
deleteImageMethod · 0.80
emitMethod · 0.80
containsMethod · 0.80
getBoundingClientRectMethod · 0.45

Tested by

no test coverage detected