Skip to content

Commit 22d5102

Browse files
author
HugoFara
committed
feat(multi-word): now based on selection, not click & hold.
1 parent 54e2c9e commit 22d5102

File tree

4 files changed

+322
-1170
lines changed

4 files changed

+322
-1170
lines changed

src/frontend/js/reading/components/text_reader.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import Alpine from 'alpinejs';
1212
import type { WordStoreState } from '../stores/word_store';
1313
import { renderText, updateWordStatusInDOM, type RenderSettings } from '../text_renderer';
14+
import { setupMultiWordSelection } from '../text_multiword_selection';
1415
// speechDispatcher available when TTS is implemented
1516

1617
/**
@@ -154,6 +155,10 @@ export function textReaderData(): TextReaderData {
154155

155156
// Keyboard navigation
156157
document.addEventListener('keydown', (e) => this.handleKeydown(e));
158+
159+
// Multi-word selection via native text selection
160+
// When user selects multiple words, the multi-word modal opens
161+
setupMultiWordSelection(container);
157162
},
158163

159164
handleWordClick(event: MouseEvent): void {

src/frontend/js/reading/text_events.ts

Lines changed: 7 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import {
2020
mword_each_do_text_text
2121
} from './text_annotations';
2222
import { keydown_event_do_text_text } from './text_keyboard';
23-
import { mword_drag_n_drop_select, mword_touch_select } from './text_multiword_selection';
23+
import { setupMultiWordSelection, mword_drag_n_drop_select, mword_touch_select } from './text_multiword_selection';
2424
import { loadModalFrame } from './frame_management';
2525
import { removeAllTooltips } from '../ui/native_tooltip';
2626
import {
@@ -45,7 +45,9 @@ export { keydown_event_do_text_text } from './text_keyboard';
4545
export {
4646
mwordDragNDrop,
4747
mword_drag_n_drop_select,
48-
mword_touch_select
48+
mword_touch_select,
49+
setupMultiWordSelection,
50+
handleTextSelection
4951
} from './text_multiword_selection';
5052

5153
// Re-export word actions for external use
@@ -413,34 +415,9 @@ export function prepareTextInteractions(): void {
413415

414416
const thetext = document.getElementById('thetext');
415417
if (thetext) {
416-
// Prevent text selection on spans
417-
thetext.addEventListener('selectstart', (e) => {
418-
if ((e.target as HTMLElement).tagName === 'SPAN') {
419-
e.preventDefault();
420-
}
421-
});
422-
423-
// Multi-word drag and drop selection (mouse)
424-
thetext.addEventListener('mousedown', (e) => {
425-
const target = e.target as HTMLElement;
426-
if (target.classList.contains('wsty')) {
427-
// Create a synthetic event object with annotation data
428-
const eventWithData = e as MouseEvent & { data?: { annotation: number } };
429-
eventWithData.data = { annotation: LWT_DATA.settings.annotations_mode };
430-
mword_drag_n_drop_select.call(target, eventWithData);
431-
}
432-
});
433-
434-
// Multi-word selection for touch devices
435-
thetext.addEventListener('touchstart', (e) => {
436-
const target = e.target as HTMLElement;
437-
if (target.classList.contains('wsty')) {
438-
// Create a synthetic event object with annotation data
439-
const eventWithData = e as TouchEvent & { data?: { annotation: number } };
440-
eventWithData.data = { annotation: LWT_DATA.settings.annotations_mode };
441-
mword_touch_select.call(target, eventWithData);
442-
}
443-
}, { passive: true });
418+
// Multi-word selection via native text selection
419+
// When user selects multiple words, the multi-word modal opens
420+
setupMultiWordSelection(thetext);
444421

445422
// Multi-word click events (delegated)
446423
thetext.addEventListener('click', (e) => {

0 commit comments

Comments
 (0)