Skip to content

Commit

Permalink
feat: 1.增加剪切当前行的命令(可以用于手机端,不需要长按选中当前行所有内容)
Browse files Browse the repository at this point in the history
  • Loading branch information
JuckZ committed Apr 18, 2023
1 parent 920917c commit 389db89
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/locale/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export default {
'remove-check-in': 'Remove Habit Check In',
'query-openai': 'Query openAI',
'open-emoji-picker': 'Open emoji picker',
'cut-line': 'Cut current line',
},
setting: {
cursorEffect: {
Expand Down
1 change: 1 addition & 0 deletions src/locale/zh-cn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export default {
'remove-check-in': '移除习惯打卡',
'query-openai': '询问OpenAI',
'open-emoji-picker': '输入表情',
'cut-line': '剪切当前行',
},
setting: {
cursorEffect: {
Expand Down
11 changes: 11 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,17 @@ export default class AwesomeBrainManagerPlugin extends Plugin {
}

private setupCommands() {
this.addCommand({
id: 'cut-line',
icon: 'scissors',
name: t.command['cut-line'],
callback: () => {
const editor = this.app.workspace.activeEditor?.editor;
if (editor) {
EditorUtils.cutLine(editor);
}
},
});
this.addCommand({
id: 'check-in',
name: t.command['check-in'],
Expand Down
16 changes: 15 additions & 1 deletion src/utils/editor.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Editor } from 'obsidian';
import { type Editor } from 'obsidian';
import { type App, createApp } from 'vue';
import type AwesomeBrainManagerPlugin from '../main';
import AppVue from '../ui/App.vue';
Expand Down Expand Up @@ -85,6 +85,20 @@ export class EditorUtils {
});
this.plugin.updateSnippet();
};

static cutLine(editor: Editor) {
const cursorPos = editor.getCursor();
const line = editor.getLine(cursorPos.line);
editor.replaceRange('', { line: cursorPos.line, ch: 0 }, { line: cursorPos.line, ch: line.length });
navigator.clipboard.writeText(line).then(
() => {
console.log('Line cut and copied: ' + line);
},
err => {
console.error('Failed to copy text: ', err);
},
);
}
}

export const EditorUtil = new EditorUtils();

0 comments on commit 389db89

Please sign in to comment.