From a56c445ea72890b4976f11eecf341ff34ce9eb86 Mon Sep 17 00:00:00 2001 From: Sergey Kolesnik Date: Fri, 3 Nov 2023 23:39:57 +0300 Subject: [PATCH] feat(ui): replace old insert command --- src/app.tsx | 48 ++++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/src/app.tsx b/src/app.tsx index 86a3ea6..c990215 100644 --- a/src/app.tsx +++ b/src/app.tsx @@ -15,6 +15,7 @@ import { escapeForRegExp, getCSSVars, loadThemeVars, + getChosenBlock, } from './utils' import { RenderError, StateError, StateMessage } from './errors' import { isOldSyntax } from './extensions/customized_eta' @@ -162,39 +163,38 @@ async function main() { const commandTemplate = RendererMacro.command('template') { const commandLabel = 'Insert 🏛template' - const commandGuide = commandTemplate - .arg('TEMPLATE NAME') - .toString() - logseq.App.registerCommandPalette( - { key: 'insert-template', label: commandLabel }, async (e) => { - const inserted = await insertContent(commandGuide, { positionOnArg: 1 }) - if (!inserted) { - logseq.UI.showMsg( - `[:p "Start editing block or select one to insert " - [:code ":template"]]`, - 'warning', - {timeout: 5000}, - ) - return - } - }) - - logseq.App.registerCommandPalette({ - key: 'insert-template2', - label: 'Insert 🏛️template2', - keybinding: { binding: 'mod+u', mode: 'global' } - }, async (e) => { + function showInsertUI(uuid: string, needToReplaceContent = false) { render( - , + , document.getElementById('app')! ) logseq.showMainUI() + } + + logseq.App.registerCommandPalette({ + key: 'insert-template', + label: commandLabel, + keybinding: { binding: 'mod+u', mode: 'global' } + }, async (e) => { + const chosenBlock = await getChosenBlock() + if (!chosenBlock) { + logseq.UI.showMsg( + `[:p "Start editing block or select one to insert " + [:code ":template"]]`, + 'warning', + {timeout: 5000}, + ) + return + } + + const [ uuid, isSelectedState ] = chosenBlock + showInsertUI(uuid, isSelectedState) }) logseq.Editor.registerSlashCommand(commandLabel, async (e) => { // here user always in editing mode, so no need to check insertion - await insertContent(commandGuide, { positionOnArg: 1 }) + showInsertUI(e.uuid) }) registerBlockContextCopyCommand('Copy as 🏛template', commandTemplate)