Skip to content

Commit

Permalink
Enable actions for highlights in the note editor. Fix #570
Browse files Browse the repository at this point in the history
  • Loading branch information
tnajdek committed Nov 27, 2024
1 parent 77df0a2 commit 34a0be6
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
2 changes: 1 addition & 1 deletion modules/note-editor
6 changes: 4 additions & 2 deletions src/js/common/navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,10 @@ const makePath = (config, { library = null, collection = null,
}

if (location && ['pageNumber', 'annotationID', 'position', 'href'].includes(Object.keys(location)[0])) {
path.push(Object.keys(location)[0])
path.push(location[Object.keys(location)[0]])
const locationType = Object.keys(location)[0];
const locationValue = location[locationType];
path.push(locationType);
path.push(locationType === 'position' ? JSON.stringify(locationValue) : locationValue);
}

return '/' + path.join('/');
Expand Down
6 changes: 6 additions & 0 deletions src/js/component/rich-editor.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,12 @@ const RichEditor = memo(forwardRef((props, ref) => {
}
break;
}
case 'openAnnotation': {
let { attachmentURI, position } = event.data?.message ?? {};
const { libraryKey, itemKey } = getItemFromCanonicalUrl(attachmentURI) ?? {};
dispatch(openInReader({ items: itemKey, library: libraryKey, location: { position } }));
break;
}
default:
break;
}
Expand Down
10 changes: 9 additions & 1 deletion src/js/reducers/current.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ const getLibraryKey = (params, config) => {
return config.defaultLibraryKey;
}

const tryParse = (value) => {
try {
return JSON.parse(value);
} catch(e) {
return null;
}
};


const current = (state = stateDefault, action, { config = {}, device = {}, preferences = {} } = {}) => {
switch(action.type) {
Expand Down Expand Up @@ -91,7 +99,7 @@ const current = (state = stateDefault, action, { config = {}, device = {}, prefe
var searchState = state.searchState;
var itemKey = itemKeys && itemKeys.length === 1 ? itemKeys[0] : null
var location = params.locationType && params.locationValue ? {
[params.locationType]: params.locationValue
[params.locationType]: params.locationType === 'position' ? tryParse(params.locationValue) : params.locationValue
} : null;

if(tags.length || search.length) {
Expand Down

0 comments on commit 34a0be6

Please sign in to comment.