Skip to content

Commit

Permalink
Add ability to use option+l with unselected text to immediately go to…
Browse files Browse the repository at this point in the history
… the page share menu
  • Loading branch information
blackforestboi committed Feb 28, 2024
1 parent 6d91936 commit cbdea1c
Show file tree
Hide file tree
Showing 14 changed files with 57 additions and 24 deletions.
2 changes: 1 addition & 1 deletion external/@worldbrain/memex-common
4 changes: 4 additions & 0 deletions src/citations/PageCitations.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export interface Props {
annotationUrls: string[]
getRootElement: () => HTMLElement
syncSettingsBG?: RemoteSyncSettingsInterface
defaultOpenTab?: 'CopyToClipboard' | 'ShareViaLink'
}

interface State {
Expand All @@ -55,6 +56,9 @@ export default class PageCitations extends React.PureComponent<Props, State> {
}

componentDidMount() {
if (this.props.defaultOpenTab) {
this.setState({ optionSelected: this.props.defaultOpenTab })
}
document.addEventListener('keydown', this.handleKeyDown)
}

Expand Down
4 changes: 2 additions & 2 deletions src/in-page-ui/keyboard-shortcuts/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const KEYBOARDSHORTCUTS_DEFAULT_STATE: SyncSettingsByFeature['extension']
toggleSidebarShortcut: altKey + '+d',
toggleHighlightsShortcut: altKey + '+r',
createAnnotationShortcut: altKey + '+a',
copyHighlightLinkShortcut: altKey + '+l',
copyCurrentLinkShortcut: altKey + '+l',
createHighlightShortcut: altKey + '+w',
createBookmarkShortcut: altKey + '+q',
addToCollectionShortcut: altKey + '+s',
Expand All @@ -24,7 +24,7 @@ export const KEYBOARDSHORTCUTS_DEFAULT_STATE: SyncSettingsByFeature['extension']
createAnnotationShortcutEnabled: true,
createBookmarkShortcutEnabled: true,
createHighlightShortcutEnabled: true,
copyHighlightLinkShortcutEnabled: true,
copyCurrentLinkShortcutEnabled: true,
addToCollectionShortcutEnabled: true,
addCommentShortcutEnabled: true,
openDashboardShortcutEnabled: true,
Expand Down
27 changes: 17 additions & 10 deletions src/in-page-ui/keyboard-shortcuts/content_script/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ function getShortcutHandlers({
},
sharePage: () =>
inPageUI.showSidebar({
action: 'share_page',
action: 'cite_page',
}),
createSharedAnnotationAndAddToCollection: async () => {
if (userSelectedText()) {
Expand Down Expand Up @@ -137,14 +137,21 @@ function getShortcutHandlers({
false,
null,
),
copyHighlightLink: () =>
annotationFunctions.createHighlight(
window.getSelection(),
null,
true,
null,
undefined,
true,
),
copyCurrentLink: () => {
if (userSelectedText()) {
return annotationFunctions.createHighlight(
window.getSelection(),
null,
true,
null,
undefined,
true,
)
} else {
return inPageUI.showSidebar({
action: 'share_page_link',
})
}
},
}
}
2 changes: 1 addition & 1 deletion src/in-page-ui/keyboard-shortcuts/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export function shortcutStorageToState(storage): BaseKeyboardShortcuts {
'openDashboard',
'shortcutsEnabled',
'askAI',
'copyHighlightLink',
'copyCurrentLink',
]

const shortcuts: Partial<BaseKeyboardShortcuts> = {}
Expand Down
3 changes: 2 additions & 1 deletion src/in-page-ui/shared-state/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,14 @@ export type InPageUISidebarAction =
| 'show_page_summary'
| 'rabbit_hole_open'
| 'youtube_timestamp'
| 'share_page'
| 'set_focus_mode'
| 'show_transcript'
| 'create_youtube_timestamp_with_AI_summary'
| 'create_youtube_timestamp_with_screenshot'
| 'open_chapter_summary'
| 'save_image_as_new_note'
| 'cite_page'
| 'share_page_link'

export type InPageUIRibbonAction = 'comment' | 'tag' | 'list' | 'bookmark'
export type InPageUIComponent = ContentScriptComponent
Expand Down
2 changes: 1 addition & 1 deletion src/in-page-ui/tooltip/content_script/interactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export const insertTooltip = async (params: TooltipInsertDependencies) => {
createAnnotation: shortcutToKeyStrs(state.createAnnotation),
createHighlight: shortcutToKeyStrs(state.createHighlight),
addToCollection: shortcutToKeyStrs(state.addToCollection),
copyHighlightLink: shortcutToKeyStrs(state.copyHighlightLink),
copyCurrentLink: shortcutToKeyStrs(state.copyCurrentLink),
askAI: shortcutToKeyStrs(state.askAI),
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class KeyboardShortcutsContainer extends React.PureComponent<Props, State> {
toggleSidebar: { shortcut: 'r', enabled: true },
toggleHighlights: { shortcut: 'h', enabled: true },
createAnnotation: { shortcut: 'a', enabled: true },
copyHighlightLink: { shortcut: 'l', enabled: true },
copyCurrentLink: { shortcut: 'l', enabled: true },
createHighlight: { shortcut: 'n', enabled: true },
addTag: { shortcut: 't', enabled: true },
addComment: { shortcut: 'e', enabled: true },
Expand Down
15 changes: 13 additions & 2 deletions src/sidebar/annotations-sidebar/components/AnnotationsSidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1371,7 +1371,10 @@ export class AnnotationsSidebar extends React.Component<
}

private renderPageLinkMenu() {
if (!this.props.showPageLinkShareMenu) {
if (
!this.props.showPageLinkShareMenu &&
!this.props.showPageCitationMenu
) {
return null
}

Expand Down Expand Up @@ -1413,6 +1416,11 @@ export class AnnotationsSidebar extends React.Component<
this.props.sidebarContext === 'dashboard',
}}
getRootElement={this.props.getRootElement}
defaultOpenTab={
this.props.showPageCitationMenu
? 'CopyToClipboard'
: 'ShareViaLink'
}
/>
{this.props.renderPageLinkMenuForList()}
</PopoutBox>
Expand Down Expand Up @@ -3880,7 +3888,10 @@ export class AnnotationsSidebar extends React.Component<
icon="copy"
padding={'0px 12px 0 6px'}
height={'30px'}
hoverState={this.props.showPageLinkShareMenu}
hoverState={
this.props.showPageLinkShareMenu ||
this.props.showPageCitationMenu
}
/>
{this.state.pageLinkCreationLoading === 'running' && (
<LoadingBox2>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1176,7 +1176,7 @@ export class AnnotationsSidebarContainer<
this.processEvent('markFeedAsRead', null)
}
clickCreatePageLinkBtn={() =>
this.processEvent('openPageLinkShareMenu', null)
this.processEvent('openPageCitationMenu', null)
}
selectedListId={this.state.selectedListId}
currentUser={this.props.getCurrentUser()}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -388,9 +388,13 @@ export class AnnotationsSidebarInPage extends AnnotationsSidebarContainer<
await this.processEvent('setActiveSidebarTab', {
tab: this.state.selectedListId ? 'spaces' : 'annotations',
})
} else if (event.action === 'share_page') {
} else if (event.action === 'cite_page') {
await this.processEvent('setActiveSidebarTab', { tab: 'spaces' })
await sleepPromise(500)
await sleepPromise(300)
await this.processEvent('openPageCitationMenu', null)
} else if (event.action === 'share_page_link') {
await this.processEvent('setActiveSidebarTab', { tab: 'spaces' })
await sleepPromise(300)
await this.processEvent('openPageLinkShareMenu', null)
} else if (event.action === 'check_sidebar_status') {
return true
Expand Down
4 changes: 4 additions & 0 deletions src/sidebar/annotations-sidebar/containers/logic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1521,11 +1521,15 @@ export class SidebarContainerLogic extends UILogic<
> = async ({}) => {
this.emitMutation({ showPageLinkShareMenu: { $set: true } })
}
openPageCitationMenu: EventHandler<'openPageCitationMenu'> = async ({}) => {
this.emitMutation({ showPageCitationMenu: { $set: true } })
}

closePageLinkShareMenu: EventHandler<
'closePageLinkShareMenu'
> = async ({}) => {
this.emitMutation({ showPageLinkShareMenu: { $set: false } })
this.emitMutation({ showPageCitationMenu: { $set: false } })
}

processFileImportFeeds: EventHandler<'processFileImportFeeds'> = async ({
Expand Down
2 changes: 2 additions & 0 deletions src/sidebar/annotations-sidebar/containers/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ export interface SidebarContainerState extends AnnotationConversationsState {
pageHasNetworkAnnotations: boolean
hasFeedActivity?: boolean
showPageLinkShareMenu: boolean
showPageCitationMenu: boolean
/**
* In the case of a page being opened from the web UI for a page link, data
* may need to be manually pulled as sync might not have finished by the time the
Expand Down Expand Up @@ -498,6 +499,7 @@ interface SidebarEvents {
openEditMenuForList: { unifiedListId: UnifiedList['unifiedId'] }
closePageLinkShareMenu: null
openPageLinkShareMenu: null
openPageCitationMenu: null
editListName: {
unifiedListId: UnifiedList['unifiedId']
localId: number
Expand Down
4 changes: 2 additions & 2 deletions src/sync-settings/background/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export interface SyncSettingsByFeature {
addToCollectionShortcutEnabled: boolean
sharePageShortcutEnabled: boolean
toggleHighlightsShortcutEnabled: boolean
copyHighlightLinkShortcutEnabled: boolean
copyCurrentLinkShortcutEnabled: boolean
createAnnotationShortcutEnabled: boolean
askAIShortcutEnabled: boolean
addCommentShortcut: string
Expand All @@ -68,7 +68,7 @@ export interface SyncSettingsByFeature {
addToCollectionShortcut: string
toggleHighlightsShortcut: string
createAnnotationShortcut: string
copyHighlightLinkShortcut: string
copyCurrentLinkShortcut: string
askAIShortcut: string
sharePageShortcut: string
}
Expand Down

0 comments on commit cbdea1c

Please sign in to comment.