@@ -5,9 +5,10 @@ import type { InitalSelectionOption, ModeOption } from '../types';
5
5
import React , { useEffect , useState , Fragment } from 'react' ;
6
6
import CommandPalette , { Command } from 'react-command-palette' ;
7
7
import * as R from 'ramda' ;
8
- import { Global , css } from '@emotion/react' ;
8
+ import { Global } from '@emotion/react' ;
9
9
10
10
import { prepareLabel } from '../utils' ;
11
+ import { makeStyles } from '../utils/theme' ;
11
12
import {
12
13
defaultMaxDepth ,
13
14
headingRegex ,
@@ -27,20 +28,21 @@ type PathItem = {
27
28
28
29
29
30
const scrollTo = async ( blockUuid : string ) => {
30
- const pageOrBlock = ( await logseq . Editor . getCurrentPage ( ) ) ;
31
- const isBlock = ( 'content' in ( pageOrBlock || { } ) ) ;
32
- if ( ! pageOrBlock ) {
33
- return console . error ( 'failed to get page or block' ) ;
31
+ // we're not using `logseq.Editor.scrollToBlockInPage`
32
+ // as it only works on pages and not in zoomed in views.
33
+ // custom solution: scroll to the block and select it.
34
+
35
+ // for reference: https://github.com/logseq/logseq/blob/0.9.4/libs/src/LSPlugin.user.ts#L368
36
+ const id = 'block-content-' + blockUuid ;
37
+ const elem = window . parent . document . getElementById ( id ) ;
38
+ if ( elem ) {
39
+ elem . scrollIntoView ( { behavior : 'smooth' } ) ;
40
+ // @ts -expect-error
41
+ window . parent . logseq . api . select_block ( blockUuid ) ;
42
+ } else {
43
+ // this happens for children of collapsed blocks
44
+ // console.error('failed to find block element');
34
45
}
35
- const page = isBlock
36
- ? await logseq . Editor . getPage ( pageOrBlock . page . id )
37
- : pageOrBlock ;
38
- if ( ! page ) {
39
- return console . error ( 'failed to get page' ) ;
40
- }
41
- // TODO: how to scroll to block in sub-tree without leaving the sub-tree?
42
- // `scrollToBlockInPage()` will open the entire page
43
- logseq . Editor . scrollToBlockInPage ( page . name , blockUuid ) ;
44
46
} ;
45
47
46
48
@@ -59,6 +61,7 @@ const selectionHandler = async (
59
61
}
60
62
}
61
63
scrollTo ( item . id as string ) ;
64
+ // TODO: push state?
62
65
} ;
63
66
64
67
@@ -135,52 +138,6 @@ const makeCommands = (
135
138
} ;
136
139
137
140
138
- const makeStyles = ( ) => {
139
- const computedStyles = getComputedStyle (
140
- window . parent . document . documentElement
141
- ) ;
142
- const bg = computedStyles . getPropertyValue (
143
- '--ls-secondary-background-color'
144
- ) ;
145
- const bgSelection = computedStyles . getPropertyValue (
146
- '--ls-a-chosen-bg'
147
- ) ;
148
- const text = computedStyles . getPropertyValue (
149
- '--ls-primary-text-color'
150
- ) ;
151
- const textSelection = computedStyles . getPropertyValue (
152
- '--ls-secondary-text-color'
153
- ) ;
154
- const input = computedStyles . getPropertyValue (
155
- '--ls-primary-background-color'
156
- ) ;
157
- return css `
158
- .sublime-modal , .sublime-suggestionsList .sublime-suggestion {
159
- background : ${ bg } !important ;
160
- color : ${ text } !important ;
161
- }
162
- .sublime-suggestionsList .sublime-suggestionHighlighted {
163
- background : ${ bgSelection } !important ;
164
- color : ${ textSelection } !important ;
165
- }
166
- .sublime-suggestion {
167
- background : ${ bgSelection } !important ;
168
- }
169
- .sublime-input {
170
- background : ${ input } !important ;
171
- color : ${ text } !important ;
172
- }
173
- * ::-webkit-scrollbar-thumb {
174
- background-color : ${ bgSelection } !important ;
175
- border : solid 3px ${ bg } !important ;
176
- }
177
- .indentation {
178
- color : ${ bgSelection } !important ;
179
- }
180
- ` ;
181
- } ;
182
-
183
-
184
141
function App ( ) {
185
142
const mode : ModeOption = logseq . settings ?. mode || modeDefault ;
186
143
@@ -201,8 +158,8 @@ function App() {
201
158
return closeHandler ( ) ;
202
159
}
203
160
204
- // NOTE: `logseq.Editor. getCurrentPageBlocksTree()` won't return anything if
205
- // we're in a sub-tree rather than a full page.
161
+ // ` getCurrentPageBlocksTree()` won't return anything
162
+ // if we're in a sub-tree rather than a full page.
206
163
let blocks : BlockEntity [ ] = [ ] ;
207
164
if ( 'content' in pageOrBlock ) {
208
165
const block = await logseq . Editor . getBlock (
@@ -245,7 +202,7 @@ function App() {
245
202
const defaultInputValue = '' ;
246
203
247
204
return < Fragment >
248
- < Global styles = { makeStyles } />
205
+ < Global styles = { makeStyles ( ) } />
249
206
< CommandPalette
250
207
open = { open }
251
208
closeOnSelect
0 commit comments