Skip to content

Commit 5536844

Browse files
committed
Merge branch 'release/v1.5.0'
2 parents fe31ee3 + 3553ff5 commit 5536844

File tree

6 files changed

+64
-16
lines changed

6 files changed

+64
-16
lines changed

changelog.md

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

3+
## 1.5.0
4+
### Added
5+
- "Headings-only" mode will only list headings (#18)
6+
37
## 1.4.0
48
### Added
59
- Setting for whether the first item should be selected when opening the palette or not (#12)
6-
- Setting configuring the max. depth of the displayed items (#14)
10+
- Setting for configuring the max. depth of the displayed items (#14)
711

812

913
## 1.3.1

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.4.0",
3+
"version": "1.5.0",
44
"main": "dist/index.html",
55
"logseq": {
66
"id": "logseq-plugin-jump-to-block"

src/components/App.tsx

+32-7
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
11
/* eslint-disable @typescript-eslint/ban-ts-comment */
22
import type { BlockEntity } from '@logseq/libs/dist/LSPlugin.user';
3-
import type { InitalSelectionOption } from '../types';
3+
import type { InitalSelectionOption, ModeOption } from '../types';
44

55
import React, { useEffect, useState, Fragment } from 'react';
66
import CommandPalette, { Command } from 'react-command-palette';
77
import * as R from 'ramda';
88
import { Global, css } from '@emotion/react';
99

1010
import { prepareLabel } from '../utils';
11+
import {
12+
defaultMaxDepth,
13+
headingRegex,
14+
initialSelectionDefault,
15+
modeDefault
16+
} from '../constants';
1117

1218
// @ts-ignore
1319
import theme from '../../node_modules/react-command-palette/dist/themes/sublime-theme';
1420
import '../../node_modules/react-command-palette/dist/themes/sublime.css';
15-
import { defaultMaxDepth, initialSelectionOptionDefault } from '../constants';
1621

1722

1823
type PathItem = {
@@ -59,6 +64,7 @@ const selectionHandler = async (
5964

6065
const makeCommands = (
6166
blocks: BlockEntity[],
67+
mode: ModeOption,
6268
maxDepth = Infinity
6369
) => {
6470
const items: Command[] = [];
@@ -67,11 +73,28 @@ const makeCommands = (
6773
depth: number,
6874
path: Array<PathItem>
6975
) => {
70-
if (depth > maxDepth) {
71-
return;
76+
if (mode === 'Default') {
77+
if (depth > maxDepth) {
78+
return;
79+
}
7280
}
81+
7382
const blockContent = (block.content || '').trim();
7483

84+
if (mode === 'Headings-only') {
85+
// ignore non-headings
86+
if (!headingRegex.test(blockContent)) {
87+
return;
88+
}
89+
const level = R.takeWhile(
90+
(c) => c === '#',
91+
blockContent.split('')
92+
).length;
93+
if (level > maxDepth) {
94+
return;
95+
}
96+
}
97+
7598
// ignore empty blocks
7699
if (blockContent === '') { return; }
77100

@@ -155,6 +178,8 @@ const makeStyles = () => {
155178

156179

157180
function App() {
181+
const mode: ModeOption = logseq.settings?.mode || modeDefault;
182+
158183
const [open, setOpen] = useState(false);
159184
const [items, setItems] = useState<Command[]>([]);
160185

@@ -194,7 +219,7 @@ function App() {
194219
0,
195220
logseq.settings?.maxDepth || defaultMaxDepth
196221
);
197-
const items = makeCommands(blocks, maxDepth);
222+
const items = makeCommands(blocks, mode, maxDepth);
198223
setItems(items);
199224
setOpen(true);
200225
} else {
@@ -207,10 +232,10 @@ function App() {
207232
logseq.off('ui:visible:changed', visibilityHandler);
208233
};
209234
},
210-
[]
235+
[mode]
211236
);
212237

213-
const initialSelection: InitalSelectionOption = logseq.settings?.initialSelection || initialSelectionOptionDefault;
238+
const initialSelection: InitalSelectionOption = logseq.settings?.initialSelection || initialSelectionDefault;
214239
const highlightFirstSuggestion = initialSelection === 'First block';
215240
// TODO: implement 'Current block'
216241
const defaultInputValue = '';

src/constants.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
import type { InitalSelectionOption } from './types';
1+
import type { InitalSelectionOption, ModeOption } from './types';
22

3-
export const initialSelectionOptionDefault: InitalSelectionOption = 'Nothing';
3+
export const initialSelectionDefault: InitalSelectionOption = 'Nothing';
44
export const defaultMaxDepth = 3;
5+
export const modeDefault: ModeOption = 'Headings-only';
6+
7+
export const headingRegex = /^#{1,6} (.*)/gi;

src/main.tsx

+20-5
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,31 @@ import type {
22
SettingSchemaDesc,
33
SimpleCommandKeybinding
44
} from '@logseq/libs/dist/LSPlugin';
5-
import type { InitalSelectionOption } from './types';
5+
import type { InitalSelectionOption, ModeOption } from './types';
66

77
import React from 'react';
88
import ReactDOM from 'react-dom/client';
99
import '@logseq/libs';
1010

1111
import { makeToolbarIcon } from './toolbar';
12-
import { defaultMaxDepth, initialSelectionOptionDefault } from './constants';
12+
import {
13+
defaultMaxDepth,
14+
initialSelectionDefault,
15+
modeDefault
16+
} from './constants';
1317
import App from './components/App';
1418

1519

16-
1720
const cmdKey = 'jumpToBlock';
1821
const cmdLabel = 'Jump to block…';
1922
const settingsKey = cmdKey;
2023
const settingsLabel = cmdLabel;
2124
const initialSelectionOptions: InitalSelectionOption[] = [
2225
/* 'Current block', */ 'First block', 'Nothing'
2326
];
27+
const modeOptions: ModeOption[] = [
28+
'Default', 'Headings-only'
29+
];
2430
const settings: SettingSchemaDesc[] = [
2531
{
2632
key: settingsKey,
@@ -29,6 +35,15 @@ const settings: SettingSchemaDesc[] = [
2935
default: 'mod+t',
3036
type: 'string',
3137
},
38+
{
39+
key: 'mode',
40+
title: 'Mode',
41+
description: '',
42+
default: modeDefault,
43+
type: 'enum',
44+
enumChoices: modeOptions as string[],
45+
enumPicker: 'radio',
46+
},
3247
{
3348
key: 'autoOpen',
3449
title: 'Auto-open palette',
@@ -40,15 +55,15 @@ const settings: SettingSchemaDesc[] = [
4055
key: 'initialSelection',
4156
title: 'What to select when opening the palette',
4257
description: '',
43-
default: initialSelectionOptionDefault,
58+
default: initialSelectionDefault,
4459
type: 'enum',
4560
enumChoices: initialSelectionOptions as string[],
4661
enumPicker: 'radio',
4762
},
4863
{
4964
key: 'maxDepth',
5065
title: 'Maximum block depth',
51-
description: 'Limits the depth of blocks to be shown in the palette (0 = root-level)',
66+
description: 'Limits the depth of blocks to be shown in the palette.',
5267
default: defaultMaxDepth,
5368
type: 'number',
5469
},

src/types/index.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
// TODO: 'Current block'
22
export type InitalSelectionOption = 'First block' | 'Nothing';
3+
export type ModeOption = 'Default' | 'Headings-only';

0 commit comments

Comments
 (0)