Skip to content

Commit

Permalink
improve(plugin): api of editing cursor position & types
Browse files Browse the repository at this point in the history
  • Loading branch information
xyhp915 committed Jun 2, 2021
1 parent 5df7051 commit fd998d2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
2 changes: 2 additions & 0 deletions libs/src/LSPlugin.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ type SlashCommandActionCmd =
| 'editor/restore-saved-cursor'
type SlashCommandAction = [cmd: SlashCommandActionCmd, ...args: any]
type BlockCommandCallback = (e: IHookEvent & { uuid: BlockUUID }) => Promise<void>
type BlockCursorPosition = { left: number, top: number, height: number, pos: number, react: DOMRect }

interface IAppProxy {
getUserInfo: () => Promise<any>
Expand Down Expand Up @@ -135,6 +136,7 @@ interface IEditorProxy {
// block related APIs
checkEditing: () => Promise<BlockUUID | boolean>
insertAtEditingCursor: (content: string) => Promise<void>
getEditingCursorPosition: () => Promise<BlockCursorPosition | null>
getCurrentPage: () => Promise<Partial<BlockEntity> | null>
getCurrentBlock: () => Promise<BlockEntity | null>
getCurrentBlockContent: () => Promise<string>
Expand Down
6 changes: 6 additions & 0 deletions src/main/logseq/api.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
[frontend.util :as util]
[electron.ipc :as ipc]
[promesa.core :as p]
[goog.dom :as gdom]
[sci.core :as sci]
[lambdaisland.glogi :as log]
[camel-snake-kebab.core :as csk]
Expand Down Expand Up @@ -162,6 +163,11 @@
(when-let [input-id (state/get-edit-input-id)]
(commands/simple-insert! input-id content {}))))

(def ^:export get_editing_cursor_position
(fn []
(when-let [input-id (state/get-edit-input-id)]
(bean/->js (normalize-keyword-for-json (util/get-caret-pos (gdom/getElement input-id)))))))

(def ^:export get_current_block
(fn []
(let [block (state/get-edit-block)
Expand Down

0 comments on commit fd998d2

Please sign in to comment.