Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add autoscroll to highlighted text when using arrow key #1053

Merged
merged 3 commits into from
Jul 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 1 addition & 33 deletions src/TextEditMode.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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
*/
Expand All @@ -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
*/
Expand All @@ -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);
Expand Down
24 changes: 22 additions & 2 deletions src/utils/ModalWindow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';


/**
Expand Down Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions src/utils/Select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down