Skip to content

Commit 7a57425

Browse files
committed
Merge branch 'release/v1.6.0'
2 parents 9919aa9 + 75c6535 commit 7a57425

File tree

5 files changed

+73
-65
lines changed

5 files changed

+73
-65
lines changed

changelog.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## 1.6.0
4+
### Fixed
5+
- Plugin works in zoomed in view (sub-trees) now!
6+
37
## 1.5.3
48
### Fixed
59
- Improved regular expressions for label rendering (to filter out keywords, properties, etc.)

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "logseq-plugin-jump-to-block",
3-
"version": "1.5.3",
3+
"version": "1.6.0",
44
"main": "dist/index.html",
55
"logseq": {
66
"id": "logseq-plugin-jump-to-block",

src/components/App.tsx

+20-63
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ import type { InitalSelectionOption, ModeOption } from '../types';
55
import React, { useEffect, useState, Fragment } from 'react';
66
import CommandPalette, { Command } from 'react-command-palette';
77
import * as R from 'ramda';
8-
import { Global, css } from '@emotion/react';
8+
import { Global } from '@emotion/react';
99

1010
import { prepareLabel } from '../utils';
11+
import { makeStyles } from '../utils/theme';
1112
import {
1213
defaultMaxDepth,
1314
headingRegex,
@@ -27,20 +28,21 @@ type PathItem = {
2728

2829

2930
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');
3445
}
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);
4446
};
4547

4648

@@ -59,6 +61,7 @@ const selectionHandler = async (
5961
}
6062
}
6163
scrollTo(item.id as string);
64+
// TODO: push state?
6265
};
6366

6467

@@ -135,52 +138,6 @@ const makeCommands = (
135138
};
136139

137140

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-
184141
function App() {
185142
const mode: ModeOption = logseq.settings?.mode || modeDefault;
186143

@@ -201,8 +158,8 @@ function App() {
201158
return closeHandler();
202159
}
203160

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.
206163
let blocks: BlockEntity[] = [];
207164
if ('content' in pageOrBlock) {
208165
const block = await logseq.Editor.getBlock(
@@ -245,7 +202,7 @@ function App() {
245202
const defaultInputValue = '';
246203

247204
return <Fragment>
248-
<Global styles={makeStyles} />
205+
<Global styles={makeStyles()} />
249206
<CommandPalette
250207
open={open}
251208
closeOnSelect

src/utils/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export const cleanLabel = (s: string) => {
1010
.replaceAll(/\{:.*\}/gi, '')
1111
.replaceAll(/^(TODO|DOING|DONE|NOW|LATER) /g, '')
1212
.trim();
13-
}
13+
};
1414

1515

1616
export const prepareLabel = (blockContent: string) => {

src/utils/theme.ts

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import { css } from '@emotion/react';
2+
3+
4+
export const makeStyles = () => {
5+
const computedStyles = getComputedStyle(
6+
window.parent.document.documentElement
7+
);
8+
const bg = computedStyles.getPropertyValue(
9+
'--ls-secondary-background-color'
10+
);
11+
const bgSelection = computedStyles.getPropertyValue(
12+
'--ls-a-chosen-bg'
13+
);
14+
const text = computedStyles.getPropertyValue(
15+
'--ls-primary-text-color'
16+
);
17+
const textSelection = computedStyles.getPropertyValue(
18+
'--ls-secondary-text-color'
19+
);
20+
const input = computedStyles.getPropertyValue(
21+
'--ls-primary-background-color'
22+
);
23+
return css`
24+
.sublime-modal, .sublime-suggestionsList .sublime-suggestion {
25+
background: ${bg} !important;
26+
color: ${text} !important;
27+
}
28+
.sublime-suggestionsList .sublime-suggestionHighlighted {
29+
background: ${bgSelection} !important;
30+
color: ${textSelection} !important;
31+
}
32+
.sublime-suggestion {
33+
background: ${bgSelection} !important;
34+
}
35+
.sublime-input {
36+
background: ${input} !important;
37+
color: ${text} !important;
38+
}
39+
*::-webkit-scrollbar-thumb {
40+
background-color: ${bgSelection} !important;
41+
border: solid 3px ${bg} !important;
42+
}
43+
.indentation {
44+
color: ${bgSelection} !important;
45+
}
46+
`;
47+
};

0 commit comments

Comments
 (0)