Ver Fonte

fix(plugin): update block for editing mode

charlie há 4 anos atrás
pai
commit
4208a94e72
3 ficheiros alterados com 14 adições e 8 exclusões
  1. 4 3
      libs/src/LSPlugin.core.ts
  2. 2 2
      libs/src/LSPlugin.d.ts
  3. 8 3
      src/main/logseq/api.cljs

+ 4 - 3
libs/src/LSPlugin.core.ts

@@ -690,7 +690,8 @@ class PluginLocal
   }
 
   get debugTag () {
-    return `#${this._id} [${this._options?.name}]`
+    const name = this._options?.name
+    return `#${this._id} ${name ?? ''}`
   }
 
   get localRoot (): string {
@@ -802,7 +803,7 @@ class LSPluginCore
         const { url } = pluginOptions as PluginLocalOptions
         const pluginLocal = new PluginLocal(pluginOptions as PluginLocalOptions, this, this)
 
-        const timeLabel = `Load plugin #${pluginLocal.id}`
+        const timeLabel = `[LOAD Plugin] ${pluginLocal.debugTag}`
         console.time(timeLabel)
 
         await pluginLocal.load(readyIndicator)
@@ -810,7 +811,7 @@ class LSPluginCore
         const { loadErr } = pluginLocal
 
         if (loadErr) {
-          debug(`Failed load plugin #`, pluginOptions)
+          debug(`[Failed LOAD Plugin] #`, pluginOptions)
 
           this.emit('error', loadErr)
 

+ 2 - 2
libs/src/LSPlugin.d.ts

@@ -125,8 +125,8 @@ interface IAppProxy {
 }
 
 interface IEditorProxy {
-  registerSlashCommand: (this: LSPluginUser, tag: string, actions: Array<SlashCommandAction>) => boolean
-  registerBlockContextMenu: (this: LSPluginUser, tag: string, action: () => void) => boolean
+  registerSlashCommand: (tag: string, actions: Array<SlashCommandAction>) => boolean
+  registerBlockContextMenu: (tag: string, action: () => void) => boolean
 
   // block related APIs
   getCurrentPage: () => Promise<Partial<BlockEntity>>

+ 8 - 3
src/main/logseq/api.cljs

@@ -154,7 +154,8 @@
 (def ^:export get_current_block
   (fn []
     (let [block (state/get-edit-block)
-          block (or block (state/get-last-edit-block))]
+          block (or block (state/get-last-edit-block))
+          block (and block (db-utils/pull (:db/id block)))]
       (bean/->js (normalize-keyword-for-json block)))))
 
 (def ^:export get_current_page
@@ -183,8 +184,12 @@
 (def ^:export update_block
   (fn [block-uuid content ^js opts]
     (let [opts (and opts (bean/->clj opts))
-          repo (state/get-current-repo)]
-      (editor-handler/save-block! repo (medley/uuid block-uuid) content))))
+          repo (state/get-current-repo)
+          editing? (string/ends-with? (state/get-edit-input-id) block-uuid)]
+
+      (if editing?
+        (state/set-edit-content! (state/get-edit-input-id) content)
+        (editor-handler/save-block! repo (medley/uuid block-uuid) content)))))
 
 (def ^:export move_block
   (fn [src-block-uuid target-block-uuid ^js opts]