Skip to content

Commit

Permalink
Merge pull request #8 from TarsLab/fix-issue-7
Browse files Browse the repository at this point in the history
fix issue 7
  • Loading branch information
ae86jack committed Apr 5, 2024
2 parents 0db11e0 + 076d5c3 commit b801e7a
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
11 changes: 6 additions & 5 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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) {
Expand Down
3 changes: 2 additions & 1 deletion versions.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}

0 comments on commit b801e7a

Please sign in to comment.