From 076d5c3a00bdfe5e2d416851e3ca74fd13d8425e Mon Sep 17 00:00:00 2001 From: C Jack Date: Fri, 5 Apr 2024 17:24:14 +0800 Subject: [PATCH] fix issue 7 --- manifest.json | 2 +- package.json | 2 +- src/main.ts | 11 ++++++----- versions.json | 3 ++- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/manifest.json b/manifest.json index 1759551..595566d 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "id": "ai-zhipu", "name": "AI Zhipu", - "version": "2.0.0", + "version": "2.0.1", "minAppVersion": "1.0.0", "description": "Generate text using the ZhipuAI API.", "author": "Tarslab", diff --git a/package.json b/package.json index f972909..a133728 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "obsidian-ai-zhipu", - "version": "2.0.0", + "version": "2.0.1", "description": "Generate text using the ZhipuAI API.", "main": "main.js", "scripts": { diff --git a/src/main.ts b/src/main.ts index bdcfb57..e68fcf6 100644 --- a/src/main.ts +++ b/src/main.ts @@ -173,15 +173,15 @@ export default class AIZhipuPlugin extends Plugin { return client } - createBlockFromSelection(editor: Editor): UserMsgBlock { + createBlockFromSelection(editor: Editor, selection: string): UserMsgBlock { const block: UserMsgBlock = { _tag: 'user', - content: origin, + content: selection, start: editor.getCursor('from').line + 1, end: editor.getCursor('to').line + 3 } editor.replaceSelection( - LINE_BREAK + USER_MARK_START + LINE_BREAK + origin.trimEnd() + LINE_BREAK + USER_MARK_END + LINE_BREAK + LINE_BREAK + USER_MARK_START + LINE_BREAK + selection.trimEnd() + LINE_BREAK + USER_MARK_END + LINE_BREAK ) return block } @@ -208,8 +208,9 @@ export default class AIZhipuPlugin extends Plugin { let block = findBlockByCurrentLine(editor.getValue().split('\n'), editor.getCursor('to').line) if (!block) { - if (editor.getSelection().trim().length > 0) { - block = this.createBlockFromSelection(editor) + const selection = editor.getSelection() + if (selection.trim().length > 0) { + block = this.createBlockFromSelection(editor, selection) } else { const current = editor.getCursor('to').line if (editor.getLine(current).trim().length === 0) { diff --git a/versions.json b/versions.json index a5aad1f..fe50e07 100644 --- a/versions.json +++ b/versions.json @@ -3,5 +3,6 @@ "1.0.2": "1.0.0", "1.0.3": "1.0.0", "1.0.4": "1.0.0", - "2.0.0": "1.0.0" + "2.0.0": "1.0.0", + "2.0.1": "1.0.0" } \ No newline at end of file