diff --git a/src/TextEditMode.ts b/src/TextEditMode.ts index e533b2171..a4749ddc7 100644 --- a/src/TextEditMode.ts +++ b/src/TextEditMode.ts @@ -1,4 +1,4 @@ -import { selectBBox, unselect } from './utils/SelectTools'; +import { unselect } from './utils/SelectTools'; import DragHandler from './utils/DragHandler'; import NeonView from './NeonView'; import { setSelectHelperObjects, dragSelect, clickSelect } from './utils/Select'; @@ -45,19 +45,6 @@ function selByBBoxListener (): void { this.addBBoxListeners(); } -export function updateSelectedBBox (span: HTMLSpanElement, dragHandler: DragHandler, neonView: NeonView): void { - unselect(); - - const bboxId = Array.from(span.classList).find(e => e !== 'text-select' && e !== 'selected-to-edit'); - - if ((document.getElementById('displayBBox') as HTMLInputElement).checked) { - if (document.getElementById(bboxId)) { - const displayRect = document.getElementById(bboxId).querySelector('.sylTextRect-display') as SVGGraphicsElement; - selectBBox(displayRect, dragHandler, neonView); - } - } -} - /** * A Text editing module that works with the SingleView and DivaView modules */ @@ -74,24 +61,6 @@ export default class TextEditMode implements TextEditInterface { this.initTextEdit(); } - - /** - * Update the bounding box selected when the edit text modal has been clicked - */ - updateSelectedBBox (span: HTMLSpanElement): void { - unselect(); - - const bboxId = Array.from(span.classList).find(e => e !== 'text-select' && e !== 'selected-to-edit'); - - if ((document.getElementById('displayBBox') as HTMLInputElement).checked) { - if (document.getElementById(bboxId)) { - const displayRect = document.getElementById(bboxId).querySelector('.sylTextRect-display') as SVGGraphicsElement; - selectBBox(displayRect, this.dragHandler, this.neonView); - } - } - } - - /** * Set text to edit mode */ @@ -103,7 +72,6 @@ export default class TextEditMode implements TextEditInterface { span.classList.add('selected-to-edit'); modal.setModalWindowView(ModalWindowView.EDIT_TEXT); modal.openModalWindow(); - updateSelectedBBox(span, this.dragHandler, this.neonView); } span.removeEventListener('click', selectSylText); diff --git a/src/utils/ModalWindow.ts b/src/utils/ModalWindow.ts index 40fe38b8a..a15111eb9 100644 --- a/src/utils/ModalWindow.ts +++ b/src/utils/ModalWindow.ts @@ -3,7 +3,8 @@ import { SetTextAction } from '../Types'; import { ModalWindowInterface } from '../Interfaces'; import { hotkeysModal, editTextModal } from '../SquareEdit/Contents'; import { uploadAreaHTML } from '../Dashboard/dashboard_components'; -import { updateSelectedBBox } from '../TextEditMode'; +import DragHandler from './DragHandler'; +import { selectBBox, unselect } from './SelectTools'; /** @@ -228,15 +229,34 @@ export class ModalWindow implements ModalWindowInterface { // An update to the page will reload the entire svg; // We would like to then reselect the same selected syllable // if bboxes are enabled - updateSelectedBBox(span, this.dragHandler, this.neonView); + this.updateSelectedBBox(span, this.dragHandler, this.neonView); }); } }); + } else { + // reselect if no change is made + this.updateSelectedBBox(span, this.dragHandler, this.neonView); } // close modal window this.hideModalWindow(); }; + /** + * Update the bounding box selected when the edit text modal has been clicked + */ + updateSelectedBBox (span: HTMLSpanElement, dragHandler: DragHandler, neonView: NeonView): void { + unselect(); + + const bboxId = Array.from(span.classList).find(e => e !== 'text-select' && e !== 'selected-to-edit'); + + if ((document.getElementById('displayBBox') as HTMLInputElement).checked) { + if (document.getElementById(bboxId)) { + const displayRect = document.getElementById(bboxId).querySelector('.sylTextRect-display') as SVGGraphicsElement; + selectBBox(displayRect, dragHandler, neonView); + } + } + } + /** * Fill modal window with hotkey info content diff --git a/src/utils/Select.ts b/src/utils/Select.ts index 69212f51a..a0ab6132c 100644 --- a/src/utils/Select.ts +++ b/src/utils/Select.ts @@ -85,6 +85,12 @@ function arrowKeyListener (evt: KeyboardEvent): void { const bbox = bboxSyllables[ind + 1].querySelector('.sylTextRect-display'); selectAll([bbox as SVGGraphicsElement], neonView, dragHandler); } + + // Auto scroll to highlighted text + const selectedSylText = document.querySelector('.text-select'); + if (selectedSylText) { + selectedSylText.scrollIntoView({ behavior: 'smooth' }); + } } function isSelByBBox (): boolean {