Skip to content

Commit

Permalink
2.4.7
Browse files Browse the repository at this point in the history
修复thino中无法使用命令的问题
  • Loading branch information
cumany committed Apr 3, 2024
1 parent 1934364 commit 116b4c1
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 34 deletions.
2 changes: 1 addition & 1 deletion build/manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "editing-toolbar",
"name": "Editing Toolbar",
"version": "2.4.6",
"version": "2.4.7",
"minAppVersion": "0.14.0",
"description": "The Obsidian Editing Toolbar is modified from cmenu, which provides more powerful customization settings and has many built-in editing commands to be a MS Word-like toolbar editing experience.",
"author": "Cuman",
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "editing-toolbar",
"name": "Editing Toolbar",
"version": "2.4.6",
"version": "2.4.7",
"minAppVersion": "0.14.0",
"description": "The Obsidian Editing Toolbar is modified from cmenu, which provides more powerful customization settings and has many built-in editing commands to be a MS Word-like toolbar editing experience.",
"author": "Cuman",
Expand Down
27 changes: 13 additions & 14 deletions src/modals/cMenuToolbarModal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,9 @@ export function createTablecell(app: App, plugin: cMenuToolbarPlugin, el: string
export function setFontcolor(app: App, plugin: cMenuToolbarPlugin, color: string) {
//from https://github.com/obsidian-canzi/Enhanced-editing
const activeLeaf = app.workspace.getActiveViewOfType(MarkdownView);
if (activeLeaf) {

const view = activeLeaf;
const editor = view.editor;
const editor = app.workspace.activeEditor.editor;
let selectText = editor.getSelection();
// if (selectText == null || selectText.trim() == "") {
// //如果没有选中内容激活格式刷
Expand Down Expand Up @@ -276,15 +276,15 @@ export function setFontcolor(app: App, plugin: cMenuToolbarPlugin, color: string
editor.exec("goRight");
// @ts-ignore
app.commands.executeCommandById("editor:focus");
}

}

export function setBackgroundcolor(app: App, plugin: cMenuToolbarPlugin, color: string) {
//from https://github.com/obsidian-canzi/Enhanced-editing
const activeLeaf = app.workspace.getActiveViewOfType(MarkdownView);
if (activeLeaf) {

const view = activeLeaf;
const editor = view.editor;
const editor = app.workspace.activeEditor.editor;
let selectText = editor.getSelection();
// console.log(selectText,'selectText')
// if (selectText == null || selectText.trim() == "") {
Expand Down Expand Up @@ -319,7 +319,7 @@ export function setBackgroundcolor(app: App, plugin: cMenuToolbarPlugin, color:
editor.exec("goRight");
//@ts-ignore
app.commands.executeCommandById("editor:focus");
}

}

export const setcolorHex = function (color: string) {
Expand Down Expand Up @@ -406,9 +406,9 @@ export function setHeader(_str: string) {
//from https://github.com/obsidian-canzi/Enhanced-editing

const activeLeaf = app.workspace.getActiveViewOfType(MarkdownView);
if (activeLeaf) {

const view = activeLeaf;
const editor = view.editor;
const editor = app.workspace.activeEditor.editor;;
let linetext = editor.getLine(editor.getCursor().line);
let newstr, linend = "";
const regex = /^(\>*(\[[!\w]+\])?\s*)#+\s/;
Expand All @@ -434,13 +434,12 @@ export function setHeader(_str: string) {
};
editor.setLine(editor.getCursor().line, newstr);
editor.setCursor({ line: editor.getCursor().line, ch: Number(newstr.length - linend.length) });
};

}
export function setFormateraser(app: App, plugin: cMenuToolbarPlugin) {
const activeLeaf = app.workspace.getActiveViewOfType(MarkdownView);
if (activeLeaf) {
const view = activeLeaf;
const editor = view.editor


const editor = app.workspace.activeEditor.editor;
let linend;
let selstart = editor.getRange({ line: editor.getCursor().line, ch: 0 }, editor.getCursor());
let linetext = editor.getLine(editor.getCursor().line);
Expand Down Expand Up @@ -480,7 +479,7 @@ export function setFormateraser(app: App, plugin: cMenuToolbarPlugin) {
app.commands.executeCommandById("editor:focus");

}
};

}
export const createFollowingbar = (app: App, settings: cMenuToolbarSettings) => {

Expand Down
41 changes: 23 additions & 18 deletions src/plugin/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,11 +226,12 @@ export default class cMenuToolbarPlugin extends Plugin {
quiteFormatbrushes(this);
}
}
let view = this.app.workspace.getActiveViewOfType(MarkdownView);
if (!view) { return; };
// let view = this.app.workspace.getActiveViewOfType(MarkdownView);
if (!this.isView()) { return; };

//let cmEditor = view.sourceMode.cmEditor;
let cmEditor = view.editor;

let cmEditor = this.app.workspace.activeEditor.editor;
if (cmEditor.hasFocus()) {
let cMenuToolbarModalBar = isExistoolbar(this.app, this.settings)

Expand Down Expand Up @@ -312,9 +313,9 @@ export default class cMenuToolbarPlugin extends Plugin {
id: 'indent-list',
name: 'indent list',
callback: () => {
const activeLeaf = this.app.workspace.getActiveViewOfType(MarkdownView);
const view = activeLeaf;
const editor = view.editor;
//const activeLeaf = this.app.workspace.getActiveViewOfType(MarkdownView);
//const view = activeLeaf;
const editor = this.app.workspace.activeEditor.editor;
//@ts-ignore
return editor.indentList();
},
Expand All @@ -327,7 +328,7 @@ export default class cMenuToolbarPlugin extends Plugin {
callback: () => {
const activeLeaf = this.app.workspace.getActiveViewOfType(MarkdownView);
const view = activeLeaf;
const editor = view.editor;
const editor = this.app.workspace.activeEditor.editor;
//@ts-ignore
return editor.unindentList();
},
Expand All @@ -340,7 +341,7 @@ export default class cMenuToolbarPlugin extends Plugin {
callback: () => {
const activeLeaf = this.app.workspace.getActiveViewOfType(MarkdownView);
const view = activeLeaf;
const editor = view.editor;
const editor = this.app.workspace.activeEditor.editor;
return editor.undo();
},
icon: "undo-glyph"
Expand All @@ -352,7 +353,7 @@ export default class cMenuToolbarPlugin extends Plugin {
callback: () => {
const activeLeaf = this.app.workspace.getActiveViewOfType(MarkdownView);
const view = activeLeaf;
const editor = view.editor;
const editor = this.app.workspace.activeEditor.editor;
return editor.redo();
},
icon: "redo-glyph"
Expand All @@ -364,7 +365,7 @@ export default class cMenuToolbarPlugin extends Plugin {
callback: async () => {
const activeLeaf = this.app.workspace.getActiveViewOfType(MarkdownView);
const view = activeLeaf;
const editor = view.editor;
const editor = this.app.workspace.activeEditor.editor;
try {
await window.navigator.clipboard.writeText(editor.getSelection()); // 使用 window.navigator.clipboard.writeText() 方法将选定的文本写入剪贴板
app.commands.executeCommandById("editor:focus");
Expand All @@ -381,7 +382,7 @@ export default class cMenuToolbarPlugin extends Plugin {
callback: async () => {
const activeLeaf = this.app.workspace.getActiveViewOfType(MarkdownView);
const view = activeLeaf;
const editor = view.editor;
const editor = this.app.workspace.activeEditor.editor;
try {
var replaceSelection = editor.replaceSelection; // 获取编辑器的替换选区方法
var text = await window.navigator.clipboard.readText(); // 使用 window.navigator.clipboard.readText() 方法读取剪贴板中的文本
Expand All @@ -400,7 +401,7 @@ export default class cMenuToolbarPlugin extends Plugin {
callback: async () => {
const activeLeaf = this.app.workspace.getActiveViewOfType(MarkdownView);
const view = activeLeaf;
const editor = view.editor;
const editor = this.app.workspace.activeEditor.editor;
try {
await window.navigator.clipboard.writeText(editor.getSelection()); // 使用 window.navigator.clipboard.writeText() 方法将选定的文本写入剪贴板
editor.replaceSelection(""); // 清空选定的文本
Expand Down Expand Up @@ -595,16 +596,14 @@ export default class cMenuToolbarPlugin extends Plugin {
name: `Toggle ${type}`,
icon: `${type}-glyph`,
callback: async () => {
const activeLeaf =
this.app.workspace.getActiveViewOfType(MarkdownView);
if (activeLeaf) {

const view = activeLeaf;
const editor = view.editor;
const editor = this.app.workspace.activeEditor.editor;
applyCommand(commandsMap[type], editor);
await wait(10);
//@ts-ignore
app.commands.executeCommandById("editor:focus");
}

},
});
});
Expand Down Expand Up @@ -756,7 +755,13 @@ export default class cMenuToolbarPlugin extends Plugin {
this.app.workspace.off("resize", this.handlecMenuToolbar_resize);
}


isView()
{
const view = app.workspace.getActiveViewOfType(ItemView);
if(view?.getViewType()==="markdown" ||view?.getViewType()==="thino_view")
return true;
else return false;
}
handlecMenuToolbar = () => {
if (this.settings.cMenuVisibility == true) {
//const view = this.app.workspace.getActiveViewOfType(ItemView);
Expand Down

0 comments on commit 116b4c1

Please sign in to comment.