Skip to content

Commit 97df487

Browse files
author
王一帆
committed
支持添加文本到canvas
1 parent 91dccf9 commit 97df487

12 files changed

+247
-39
lines changed

httpData/.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
openApiHistory/
2+
request/
3+
db.json
4+
httpHistory.json
5+
log.err.txt
6+
store.json

httpData/apiWeb.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"paths": {},
3+
"disable": []
4+
}

manifest.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"id": "obsidian-file-cooker",
33
"name": "File Cooker",
4-
"version": "1.7.5",
5-
"minAppVersion": "0.12.0",
4+
"version": "1.7.6",
5+
"minAppVersion": "1.2.0",
66
"description": "Deal multi notes from Search results、current file、Dataview query string...",
77
"author": "iuian",
88
"authorUrl": "https://mp.weixin.qq.com/mp/profile_ext?action=home&__biz=MzA4MjQ1ODIzMA==&scene=124#wechat_redirect",

package-lock.json

Lines changed: 31 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "obsidian-file-cooker",
3-
"version": "1.7.5",
3+
"version": "1.7.6",
44
"description": "Deal batch notes from Search results、current file、Dataview query string...",
55
"main": "main.js",
66
"scripts": {
@@ -18,7 +18,7 @@
1818
"@typescript-eslint/parser": "^5.2.0",
1919
"builtin-modules": "^3.2.0",
2020
"esbuild": "0.13.12",
21-
"obsidian": "1.1.1",
21+
"obsidian": "^1.3.5",
2222
"obsidian-dataview": "^0.5.38",
2323
"tslib": "2.3.1",
2424
"typescript": "4.4.4"

src/action/add-to-canvas-action.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { App, Notice, TAbstractFile } from "obsidian";
1+
import { App, Notice } from "obsidian";
22
import { AddToCanvasConfirmModal } from "src/modal/add-to-canvas-confirm-modal";
33
import { Action, ActionModel } from "./action";
44

@@ -7,16 +7,15 @@ export class AddToCanvasAction implements Action {
77
app: App;
88
targetFilePath: string;
99

10-
constructor(app: App, targetFilePath: string) {
10+
constructor(app: App, targetFilePath?: string) {
1111
this.app = app;
1212
this.targetFilePath = targetFilePath;
1313
}
1414

1515
async act(actionModels: ActionModel[]) {
1616

1717
if (actionModels.length > 0) {
18-
let files = actionModels.map(model => model.file);
19-
new AddToCanvasConfirmModal(this.app, files, this.targetFilePath).open();
18+
new AddToCanvasConfirmModal(this.app, actionModels, this.targetFilePath).open();
2019
} else {
2120
new Notice("No Files Found!");
2221
}

src/command/clipboard-command.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { ChooseFileModal } from 'src/modal/choose-file-modal';
1111
import { ChooseFolderModal } from 'src/modal/choose-folder-modal';
1212
import { ClipboardReader } from 'src/reader/clipboard-reader';
1313
import { Command } from './command';
14+
import { ClipboardContentReader } from 'src/reader/clipboard-content-reader';
1415

1516
export class ClipboardCommand implements Command {
1617

@@ -29,6 +30,7 @@ export class ClipboardCommand implements Command {
2930
this.registRenameFile();
3031
// Canvas
3132
this.registAddFile2Canvas();
33+
this.registAddContToCanvas();
3234
}
3335

3436
private registRenameFile() {
@@ -101,6 +103,17 @@ export class ClipboardCommand implements Command {
101103
});
102104
}
103105

106+
private registAddContToCanvas() {
107+
this.plugin.addCommand({
108+
id: "Add-content-to",
109+
name: "Add content in clipboard to canvas ...",
110+
callback: () => {
111+
let actionFunc = (path: string): Action => { return new AddToCanvasAction(this.plugin.app, path); };
112+
new ChooseCanvasModal(this.plugin.app, new ClipboardContentReader(this.plugin, actionFunc)).open();
113+
}
114+
});
115+
}
116+
104117
private registAddFile2Canvas() {
105118
this.plugin.addCommand({
106119
id: "add-files-in-clipboard-to-canvas",

src/command/current-file-command.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { ChooseFileModal } from 'src/modal/choose-file-modal';
1212
import { ChooseFolderModal } from 'src/modal/choose-folder-modal';
1313
import { CurrentFileReader, ReadType } from 'src/reader/current-file-reader';
1414
import { Command } from './command';
15+
import { AddToCanvasAction } from 'src/action/add-to-canvas-action';
1516

1617
export class CurrentFileCommand implements Command {
1718

@@ -33,6 +34,7 @@ export class CurrentFileCommand implements Command {
3334
this.registRenameFile();
3435
// Canvas
3536
this.registAddFile2Canvas();
37+
this.registAddSelectionToCanvas();
3638
}
3739

3840
private registRenameFile() {
@@ -128,6 +130,19 @@ export class CurrentFileCommand implements Command {
128130
});
129131
}
130132

133+
private registAddSelectionToCanvas() {
134+
this.plugin.addCommand({
135+
id: "Add-selection-to",
136+
name: "Add selection in current file to canvas ...",
137+
editorCheckCallback: (checking: boolean, editor: Editor, view: MarkdownView) => {
138+
if (!checking) {
139+
new ChooseCanvasModal(this.plugin.app, new CurrentFileReader(this.plugin, ReadType.SELECTION, editor.getSelection())).open();
140+
}
141+
return editor.getSelection() != "";
142+
}
143+
});
144+
}
145+
131146
private registMoveFile() {
132147
this.plugin.addCommand({
133148
id: "move-links-to",

0 commit comments

Comments
 (0)