Skip to content

Commit

Permalink
Fix page label popup opening from PDF view popup context menu
Browse files Browse the repository at this point in the history
  • Loading branch information
mrtcode committed Aug 22, 2023
1 parent e805413 commit acf2929
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 40 deletions.
18 changes: 2 additions & 16 deletions src/common/components/common/preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,7 @@ export function PopupPreview(props) {
if (props.type !== 'pdf' || props.readOnly) {
return;
}
let rect = event.currentTarget.querySelector('.label').getBoundingClientRect();
rect = [
rect.left,
rect.top,
rect.right,
rect.bottom
];
props.onDoubleClickPageLabel(props.annotation.id, rect);
props.onOpenPageLabelPopup(props.annotation.id);
}

function handleTagsClick(event) {
Expand Down Expand Up @@ -138,14 +131,7 @@ export function SidebarPreview(props) {
if (props.type !== 'pdf' || props.readOnly) {
return;
}
let rect = event.currentTarget.querySelector('.label').getBoundingClientRect();
rect = [
rect.left,
rect.top,
rect.right,
rect.bottom
];
props.onDoubleClickPageLabel(props.annotation.id, rect);
props.onOpenPageLabelPopup(props.annotation.id);
}

function handleSectionClick(event, section) {
Expand Down
1 change: 0 additions & 1 deletion src/common/components/reader-ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ const ReaderUI = React.forwardRef((props, ref) => {
setState,
sidebarScrollAnnotationIntoView: (id) => annotationsViewRef.current?.scrollAnnotationIntoView(id),
sidebarEditAnnotationText: (id) => annotationsViewRef.current?.editAnnotationText(id),
sidebarOpenPageLabelPopup: (id) => annotationsViewRef.current?.openPageLabelPopup(id)
}));

let findState = state.primary ? state.primaryViewFindState : state.secondaryViewFindState;
Expand Down
15 changes: 3 additions & 12 deletions src/common/components/sidebar/annotations-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ const Annotation = React.memo((props) => {
onSetDataTransferAnnotations={props.onSetDataTransferAnnotations}
onClickSection={props.onClickAnnotationSection}
onDoubleClickText={props.onDoubleClickText}
onDoubleClickPageLabel={props.onDoubleClickPageLabel}
onOpenPageLabelPopup={props.onOpenPageLabelPopup}
onOpenContextMenu={props.onOpenContextMenu}
onChange={props.onChange}
/>
Expand Down Expand Up @@ -173,18 +173,9 @@ const AnnotationsView = memo(React.forwardRef((props, ref) => {
}, 50);
}

function openPageLabelPopup(id) {
let node = document.querySelector(`[data-sidebar-annotation-id="${id}"] .page`);
var clickEvent = document.createEvent('MouseEvents');
clickEvent.initEvent('dblclick', true, true);
node.dispatchEvent(clickEvent);
node.focus();
}

useImperativeHandle(ref, () => ({
scrollAnnotationIntoView,
editAnnotationText,
openPageLabelPopup
editAnnotationText
}));

useEffect(() => {
Expand Down Expand Up @@ -467,7 +458,7 @@ const AnnotationsView = memo(React.forwardRef((props, ref) => {
onChange={props.onChange}
onClickAnnotationSection={handleSidebarAnnotationSectionClick}
onDoubleClickText={handleSidebarAnnotationDoubleClick}
onDoubleClickPageLabel={props.onOpenPageLabelPopup}
onOpenPageLabelPopup={props.onOpenPageLabelPopup}
onOpenContextMenu={handleContextMenuOpen}
onSetDataTransferAnnotations={props.onSetDataTransferAnnotations}
/>
Expand Down
1 change: 0 additions & 1 deletion src/common/components/view/annotation-popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ function AnnotationPopup(props) {
onColorChange={(color) => {
props.onChange({ id: popupAnnotation.id, color });
}}
onDoubleClickPageLabel={props.onOpenPageLabelPopup}
onOpenTagsPopup={props.onOpenTagsPopup}
onChange={props.onChange}
onOpenPageLabelPopup={props.onOpenPageLabelPopup}
Expand Down
2 changes: 1 addition & 1 deletion src/common/context-menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ export function createAnnotationContextMenu(reader, params) {
label: reader._getString('pdfReader.editPageNumber'),
disabled: readOnly || reader._type !== 'pdf',
persistent: reader._type === 'pdf',
onCommand: () => reader._sidebarOpenPageLabelPopup(params.currentID)
onCommand: () => reader._handleOpenPageLabelPopup(params.currentID)
},
!params.view && {
label: reader._getString('pdfReader.editAnnotationText'),
Expand Down
14 changes: 5 additions & 9 deletions src/common/reader.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,10 +265,6 @@ class Reader {
onToggleFindPopup={this.toggleFindPopup.bind(this)}

onSetPortal={this._setPortal.bind(this)}

onDoubleClickPageLabel={options.onDoubleClickPageLabel}
onFocusSplitButton={options.onFocusSplitButton}
onFocusContextPane={options.onFocusContextPane}
ref={this._readerRef}
/>
</ReaderContext.Provider>
Expand Down Expand Up @@ -601,10 +597,6 @@ class Reader {
this._readerRef.current.sidebarEditAnnotationText(id);
}

_sidebarOpenPageLabelPopup(id) {
this._readerRef.current.sidebarOpenPageLabelPopup(id);
}

_getString(name) {
return this._localizedStrings[name] || name;
}
Expand Down Expand Up @@ -1288,13 +1280,17 @@ class Reader {
this._onSetDataTransferAnnotations(dataTransfer, annotations, fromText);
}

_handleOpenPageLabelPopup(id, rect) {
_handleOpenPageLabelPopup(id) {
this._ensureType('pdf');
let pageLabels = this._state.pageLabels;
let selectedIDs = this._state.selectedAnnotationIDs;
let currentAnnotation = this._annotationManager._getAnnotationByID(id);
let selectedAnnotations = this._annotationManager._annotations.filter(x => selectedIDs.includes(x.id));
let allAnnotations = this._annotationManager._annotations;
// Get target rect from preview component in the sidebar or a view popup
let labelNode = document.querySelector(`[data-sidebar-annotation-id="${id}"] header .label, .view-popup header .label`);
let { left, top, right, bottom } = labelNode.getBoundingClientRect();
let rect = [left, top, right, bottom];
this._updateState({ labelOverlay: { currentAnnotation, selectedAnnotations, allAnnotations, rect, selectedIDs, pageLabels } });
}

Expand Down

0 comments on commit acf2929

Please sign in to comment.