File tree Expand file tree Collapse file tree 5 files changed +26
-14
lines changed Expand file tree Collapse file tree 5 files changed +26
-14
lines changed Original file line number Diff line number Diff line change @@ -12,12 +12,7 @@ type LogseqBlockProps = {
1212export const LogseqBlock = ( {
1313 graph,
1414 block,
15- isPopUp = false ,
1615} : LogseqBlockProps ) => {
17- const click = ( e : any ) => {
18- if ( isPopUp ) setTimeout ( window . close , 10 ) ;
19- } ;
20-
2116 if ( block . html ) {
2217 return (
2318 < div className = { `${ styles . block } ` } >
@@ -29,13 +24,11 @@ export const LogseqBlock = ({
2924 < a
3025 className = { styles . toBlock }
3126 href = { `logseq://graph/${ graph } ?block-id=${ block . uuid } ` }
32- onClick = { click }
3327 >
3428 < span className = { 'tie tie-block' } > </ span >
3529 To block
3630 </ a >
3731 < LogseqPageLink
38- isPopUp = { isPopUp }
3932 graph = { graph }
4033 page = { block . page }
4134 > </ LogseqPageLink >
Original file line number Diff line number Diff line change @@ -11,11 +11,7 @@ type LogseqPageLinkProps = {
1111const LogseqPageLink = ( {
1212 page,
1313 graph,
14- isPopUp = false ,
1514} : LogseqPageLinkProps ) => {
16- const click = ( e : any ) => {
17- if ( isPopUp ) setTimeout ( window . close , 10 ) ;
18- } ;
1915
2016 if ( page === undefined || page ?. name === undefined ) {
2117 return < > </ > ;
@@ -25,7 +21,6 @@ const LogseqPageLink = ({
2521 < a
2622 className = { styles . logseqPageLink }
2723 href = { `logseq://graph/${ graph } ?page=${ page ?. name } ` }
28- onClick = { click }
2924 >
3025 < span className = "tie tie-page" > </ span >
3126 { page ?. name }
Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ import Browser from 'webextension-polyfill';
33import { getLogseqCopliotConfig } from '../../config' ;
44import { removeUrlHash } from '@/utils' ;
55import { setExtensionBadge } from './utils' ;
6- import { debounce } from 'lodash' ;
6+ import { debounce , delay } from 'lodash' ;
77
88const logseqClient = new LogseqClient ( ) ;
99
@@ -20,12 +20,24 @@ Browser.runtime.onConnect.addListener((port) => {
2020 Browser . runtime . openOptionsPage ( ) ;
2121 } else if ( msg . type === 'quick-capture' ) {
2222 quickCapture ( msg . data ) ;
23+ } else if ( msg . type === 'open-page' ) {
24+ openPage ( msg . url ) ;
2325 } else {
2426 console . debug ( msg ) ;
2527 }
2628 } ) ;
2729} ) ;
2830
31+ const openPage = async ( url : string ) => {
32+ await delay ( ( ) => { } , 50 ) ; // delay 50 to back the active tab.
33+
34+ const tab = await Browser . tabs . query ( { active : true , currentWindow : true } ) ;
35+ if ( ! tab ) return ;
36+ const activeTab = tab [ 0 ] ;
37+ if ( activeTab . url !== url )
38+ await Browser . tabs . update ( activeTab . id , { url : url } ) ;
39+ } ;
40+
2941const quickCapture = async ( data : string ) => {
3042 const tab = await Browser . tabs . query ( { active : true , currentWindow : true } ) ;
3143 if ( ! tab ) return ;
Original file line number Diff line number Diff line change @@ -10,6 +10,8 @@ import { LogseqBlock } from '@components/LogseqBlock';
1010
1111import styles from './index.module.scss' ;
1212
13+ const connect = Browser . runtime . connect ( ) ;
14+
1315const client = new LogseqClient ( ) ;
1416
1517export default function Popup ( ) {
@@ -30,6 +32,17 @@ export default function Popup() {
3032 const result = await client . blockSearch ( url ) ;
3133 if ( result . status !== 200 ) return ;
3234 setLogseqSearchResult ( result . response ! ) ;
35+ setTimeout ( ( ) => {
36+ document . querySelectorAll ( 'a' ) . forEach ( ( e ) => {
37+ e . onclick = ( ) => {
38+ connect . postMessage ( {
39+ type : 'open-page' ,
40+ url : e . href ,
41+ } ) ;
42+ window . close ( ) ;
43+ } ;
44+ } ) ;
45+ } , 100 ) ;
3346 } ) ;
3447 } ) ;
3548
Original file line number Diff line number Diff line change 55 < meta name ="viewport " content ="width=device-width, initial-scale=1 " />
66 < title > Popups</ title >
77 < link rel ="stylesheet " href ="popup.css ">
8-
98 </ head >
109
1110 < body >
You can’t perform that action at this time.
0 commit comments