|
1 | | -import { BlockEntity, SettingSchemaDesc } from '@logseq/libs/dist/LSPlugin.user' |
| 1 | +import { BlockEntity, PageEntity, SettingSchemaDesc } from '@logseq/libs/dist/LSPlugin.user' |
2 | 2 |
|
3 | 3 | import { splitByParagraphsCommand, toggleAutoHeadingCommand } from './commands' |
4 | | -import { getChosenBlocks, p } from './utils' |
| 4 | +import { getChosenBlocks, p, scrollToBlock, sleep } from './utils' |
5 | 5 | import { log } from 'console' |
6 | 6 |
|
7 | 7 |
|
@@ -207,6 +207,57 @@ async function main() { |
207 | 207 | await logseq.Editor.editBlock((nextBlock as BlockEntity).uuid, {pos: 0}) |
208 | 208 | } ) |
209 | 209 |
|
| 210 | + |
| 211 | + // Movements |
| 212 | + logseq.App.registerCommandPalette({ |
| 213 | + label: '🪚 Move block (⤒) on top of siblings', key: 'move-block-1-on-top', |
| 214 | + keybinding: {mac: 'mod+alt+shift+up', binding: 'ctrl+alt+shift+up', mode: 'global'}, |
| 215 | + }, async (e) => { |
| 216 | + const [blocks] = await getChosenBlocks() |
| 217 | + const [first] = blocks |
| 218 | + if (!first) |
| 219 | + return |
| 220 | + |
| 221 | + // already on top |
| 222 | + if (first.parent.id === first.left.id || first.left.id === first.page.id) |
| 223 | + return |
| 224 | + |
| 225 | + let topmost = first |
| 226 | + while (true) { |
| 227 | + const prev = await logseq.Editor.getPreviousSiblingBlock(topmost.uuid) |
| 228 | + if (!prev) |
| 229 | + break |
| 230 | + topmost = prev |
| 231 | + } |
| 232 | + |
| 233 | + await logseq.Editor.moveBlock(first.uuid, topmost.uuid, {before: true, children: false}) |
| 234 | + await scrollToBlock(first) |
| 235 | + } ) |
| 236 | + |
| 237 | + logseq.App.registerCommandPalette({ |
| 238 | + label: '🪚 Move block (⤓) on bottom of siblings', key: 'move-block-2-on-bottom', |
| 239 | + keybinding: {mac: 'mod+alt+shift+down', binding: 'ctrl+alt+shift+down', mode: 'global'}, |
| 240 | + }, async (e) => { |
| 241 | + const [blocks] = await getChosenBlocks() |
| 242 | + const [first] = blocks |
| 243 | + if (!first) |
| 244 | + return |
| 245 | + |
| 246 | + let bottommost = first |
| 247 | + while (true) { |
| 248 | + const next = await logseq.Editor.getNextSiblingBlock(bottommost.uuid) |
| 249 | + if (!next) |
| 250 | + break |
| 251 | + bottommost = next |
| 252 | + } |
| 253 | + |
| 254 | + // already on bottom |
| 255 | + if (first.id === bottommost.id) |
| 256 | + return |
| 257 | + |
| 258 | + await logseq.Editor.moveBlock(first.uuid, bottommost.uuid, {before: false, children: false}) |
| 259 | + await scrollToBlock(first) |
| 260 | + } ) |
210 | 261 | await postInit() |
211 | 262 | } |
212 | 263 |
|
|
0 commit comments