Skip to content
Open
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
5 changes: 4 additions & 1 deletion src/common/context-menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,10 @@ export function createViewContextMenu(reader, params) {
{
label: reader._getString('reader-read-aloud'),
disabled: !params.position || !reader._enableReadAloud,
onCommand: () => reader.startReadAloudAtPosition(params.position)
onCommand: () => reader.startReadAloudAtPosition({
behavior: 'move',
position: params.position,
})
}
],
[
Expand Down
2 changes: 1 addition & 1 deletion src/common/keyboard-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ export class KeyboardManager {
else if (code === `${pm}-Alt-KeyR` || code === `${pm}-Alt-KeyL`) {
event.preventDefault();
event.stopPropagation();
this._reader.startReadAloudAtPosition();
this._reader.startReadAloudAtPosition({ behavior: 'toggle' });
}
else if (['Delete', 'Backspace'].includes(key)) {
// Prevent the deletion of annotations when they are selected and the focus is within
Expand Down
17 changes: 14 additions & 3 deletions src/common/reader.js
Original file line number Diff line number Diff line change
Expand Up @@ -989,14 +989,25 @@ class Reader {
this._handleReadAloudStateChange({ paused });
}

startReadAloudAtPosition(position = null) {
/**
* @param {'move' | 'toggle'} behavior If 'move', always start Read Aloud, or move the reading position.
* If 'toggle', use smart toggle logic: when there's a selection, move to it; otherwise, close Read Aloud.
* @param {Position | null} position
*/
startReadAloudAtPosition({ behavior = 'move', position = null } = {}) {
if (!this._enableReadAloud) {
return;
}
if (!position && this._state[this._lastView + 'SelectionPopup']) {
position = this._state[this._lastView + 'SelectionPopup'].annotation?.position;
let selectionPosition = this._state[this._lastViewPrimary ? 'primaryViewSelectionPopup' : 'secondaryViewSelectionPopup']
?.annotation?.position;
if (!position && selectionPosition) {
position = selectionPosition;
}
position ??= null;
if (behavior === 'toggle' && !position && this._state.readAloudState.popupOpen) {
this.toggleReadAloudPopup(false);
return;
}
this._handleReadAloudStateChange({
popupOpen: true,
active: true,
Expand Down
Loading