|
461 | 461 | }); |
462 | 462 | } |
463 | 463 |
|
| 464 | + // Check if user is editing text content - if so, allow normal text cut |
| 465 | + const activeElement = document.activeElement; |
| 466 | + const isEditingText = activeElement && |
| 467 | + activeElement.hasAttribute("contenteditable") && |
| 468 | + activeElement.hasAttribute("data-brackets-id"); |
| 469 | + const isInEditMode = window._LD && window._LD.getMode && window._LD.getMode() === 'edit'; |
464 | 470 | // Cut: Ctrl+X / Cmd+X - operates on selected element |
465 | 471 | if ((e.ctrlKey || e.metaKey) && e.key.toLowerCase() === "x") { |
466 | | - // Check if user is editing text content - if so, allow normal text cut |
467 | | - const activeElement = document.activeElement; |
468 | | - const isEditingText = activeElement && |
469 | | - activeElement.hasAttribute("contenteditable") && |
470 | | - activeElement.hasAttribute("data-brackets-id"); |
471 | 472 |
|
472 | 473 | // Only handle element cut if not editing text and in edit mode |
473 | | - if (!isEditingText && |
474 | | - window._LD && |
475 | | - window._LD.handleCutElement && |
476 | | - window._LD.getMode && |
477 | | - window._LD.getMode() === 'edit') { |
| 474 | + if (!isEditingText && isInEditMode && window._LD.handleCutElement) { |
478 | 475 | e.preventDefault(); |
479 | 476 | window._LD.handleCutElement(); |
480 | 477 | } |
481 | 478 | } |
482 | 479 |
|
483 | 480 | // Copy: Ctrl+C / Cmd+C - operates on selected element |
484 | 481 | if ((e.ctrlKey || e.metaKey) && e.key.toLowerCase() === "c") { |
485 | | - // Check if user is editing text content - if so, allow normal text copy |
486 | | - const activeElement = document.activeElement; |
487 | | - const isEditingText = activeElement && |
488 | | - activeElement.hasAttribute("contenteditable") && |
489 | | - activeElement.hasAttribute("data-brackets-id"); |
490 | 482 |
|
491 | 483 | // Only handle element copy if not editing text and in edit mode |
492 | | - if (!isEditingText && |
493 | | - window._LD && |
494 | | - window._LD.handleCopyElement && |
495 | | - window._LD.getMode && |
496 | | - window._LD.getMode() === 'edit') { |
| 484 | + if (!isEditingText && isInEditMode && window._LD.handleCopyElement) { |
497 | 485 | e.preventDefault(); |
498 | 486 | window._LD.handleCopyElement(); |
499 | 487 | } |
500 | 488 | } |
501 | 489 |
|
502 | 490 | // Paste: Ctrl+V / Cmd+V - operates on selected element |
503 | 491 | if ((e.ctrlKey || e.metaKey) && e.key.toLowerCase() === "v") { |
504 | | - // Check if user is editing text content - if so, allow normal text paste |
505 | | - const activeElement = document.activeElement; |
506 | | - const isEditingText = activeElement && |
507 | | - activeElement.hasAttribute("contenteditable") && |
508 | | - activeElement.hasAttribute("data-brackets-id"); |
509 | 492 |
|
510 | 493 | // Only handle element paste if not editing text and in edit mode |
511 | | - if (!isEditingText && |
512 | | - window._LD && |
513 | | - window._LD.handlePasteElement && |
514 | | - window._LD.getMode && |
515 | | - window._LD.getMode() === 'edit') { |
| 494 | + if (!isEditingText && isInEditMode && window._LD.handlePasteElement) { |
516 | 495 | e.preventDefault(); |
517 | 496 | window._LD.handlePasteElement(); |
518 | 497 | } |
|
524 | 503 |
|
525 | 504 | // to check if user was in between editing text |
526 | 505 | // in such cases we first finish the editing and then save |
527 | | - const activeElement = document.activeElement; |
528 | | - if (activeElement && |
529 | | - activeElement.hasAttribute("contenteditable") && |
530 | | - activeElement.hasAttribute("data-brackets-id") && |
531 | | - window._LD && |
532 | | - window._LD.finishEditing) { |
| 506 | + if (isEditingText && window._LD && window._LD.finishEditing) { |
533 | 507 |
|
534 | 508 | window._LD.finishEditing(activeElement); |
535 | 509 | } |
|
0 commit comments