Skip to content

Commit

Permalink
Merge branch 'release/v1.3.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
freder committed Mar 27, 2023
2 parents 5d46f21 + 4372fde commit 5108813
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ node_modules
dist
_screen-capture
release-note.md
_assets
6 changes: 6 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# Changelog


## 1.3.0
### Added
- Toolbar button (#7, thanks to @YU000jp)
- Setting to autmatically open the palette on opening a page (#7, thanks to @YU000jp)


## 1.2.2

### Added
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "logseq-plugin-jump-to-block",
"version": "1.2.2",
"version": "1.3.0",
"main": "dist/index.html",
"logseq": {
"id": "logseq-plugin-jump-to-block"
Expand Down
42 changes: 40 additions & 2 deletions src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import React from 'react';
import ReactDOM from 'react-dom/client';
import '@logseq/libs';

import { makeToolbarIcon } from './toolbar';
import App from './components/App';


Expand All @@ -22,6 +23,13 @@ const settings: SettingSchemaDesc[] = [
default: 'mod+t',
type: 'string',
},
{
key: 'autoOpen',
title: 'Auto-open palette',
description: 'Autmatically open the palette on opening a page',
default: false,
type: 'boolean',
},
];


Expand All @@ -41,6 +49,31 @@ const main = async () => {
// </React.StrictMode>
);

// auto open
const PageSet = new Set();
logseq.App.onRouteChanged(async (event) => {
const autoOpen = logseq.settings?.autoOpen || '';
if (autoOpen === true) {
if (event && event.template === '/page/:name') {
if (!PageSet.has(event.path)) {
PageSet.clear();
logseq.showMainUI({ autoFocus: false });
}
await PageSet.add(event.path);
}
}
});

// toolbar icon
logseq.App.registerUIItem(
'toolbar',
{
key: 'jump-to-block',
// TODO: add icon
template: `${makeToolbarIcon(cmdLabel)}\n`,
}
);

const keyBinding: SimpleCommandKeybinding = {
// mode: 'editing', // 'global' | 'non-editing'
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
Expand All @@ -54,10 +87,15 @@ const main = async () => {
keybinding: keyBinding,
},
async () => {
logseq.showMainUI();
logseq.showMainUI({ autoFocus: false });
}
);
};

const model = {
toolbarJumpToBlock() {
logseq.showMainUI({ autoFocus: false });
}
};

logseq.ready(main).catch(console.error);
logseq.ready(model, main).catch(console.error);
48 changes: 48 additions & 0 deletions src/toolbar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
export const makeToolbarIcon = (cmdLabel: string) => {
return `
<div style="display: inline;">
<button
title="${cmdLabel}"
class="button icon inline"
data-on-click="toolbarJumpToBlock"
style="width:32px;height:32px;display:flex;align-items:center;justify-content:center;"
>
<span class="ui__icon" style="position:relative;left:1px;">
<svg
width="22"
height="22"
viewBox="0 0 24 24"
version="1.1"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
xml:space="preserve"
style="fill-rule:evenodd;clip-rule:evenodd;stroke-linejoin:round;stroke-miterlimit:2;"
>
<g transform="matrix(0.75,0,0,0.75,0,0)">
<g id="Layer1">
<rect x="0" y="0" width="32" height="32" style="fill-opacity:0;"/>
</g>
</g>
<g transform="matrix(1,0,0,1,-1.7,-0.00739822)">
<g transform="matrix(0.75,0,0,0.75,0.425,0.00184956)">
<path d="M26,6C26,4.903 25.097,4 24,4L8,4C6.903,4 6,4.903 6,6L6,26C6,27.097 6.903,28 8,28L16,28L16,26L8,26L8,6L24,6L24,12L26,12L26,6Z" style="fill:currentColor;"/>
</g>
<g transform="matrix(0.75,0,0,0.75,0.425,0.00184956)">
<rect x="10" y="18" width="6" height="2" style="fill:currentColor;"/>
</g>
<g transform="matrix(0.75,0,0,0.75,0.425,0.00184956)">
<rect x="10" y="14" width="12" height="2" style="fill:currentColor;"/>
</g>
<g transform="matrix(0.75,0,0,0.75,0.425,0.00184956)">
<rect x="10" y="10" width="12" height="2" style="fill:currentColor;"/>
</g>
<g transform="matrix(0.75,0,0,0.75,0.425,0.00184956)">
<path d="M25,23L30,25L30,23L25,20.5L25,18C25,17.451 24.549,17 24,17C23.451,17 23,17.451 23,18L23,20.5L18,23L18,25L23,23L23,26.5L21,28L21,29L24,28L27,29L27,28L25,26.5L25,23Z" style="fill:currentColor;"/>
</g>
</g>
</svg>
</span>
</button>
</div>
`;
};

0 comments on commit 5108813

Please sign in to comment.