Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…ing-toolbar into pr/158
  • Loading branch information
cumany committed Apr 16, 2024
2 parents f99a3bf + c8eedd1 commit dedce43
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 20 deletions.
16 changes: 8 additions & 8 deletions src/modals/cMenuToolbarModal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ export function createTablecell(app: App, plugin: cMenuToolbarPlugin, el: string

export function setFontcolor(app: App, color: string) {
//from https://github.com/obsidian-canzi/Enhanced-editing
const editor = app.workspace.getActiveViewOfType(MarkdownView).editor;
const editor = app.workspace.activeLeaf.view?.editor;
let selectText = editor.getSelection();
// if (selectText == null || selectText.trim() == "") {
// //如果没有选中内容激活格式刷
Expand Down Expand Up @@ -263,7 +263,7 @@ export function setFontcolor(app: App, color: string) {

export function setBackgroundcolor(app: App, color: string) {
//from https://github.com/obsidian-canzi/Enhanced-editing
const editor = app.workspace.getActiveViewOfType(MarkdownView).editor;
const editor = app.workspace.activeLeaf.view?.editor;
let selectText = editor.getSelection();
// console.log(selectText,'selectText')
// if (selectText == null || selectText.trim() == "") {
Expand Down Expand Up @@ -383,7 +383,7 @@ export function quiteFormatbrushes(plugin:cMenuToolbarPlugin) {

export function setHeader(_str: string) {
//from https://github.com/obsidian-canzi/Enhanced-editing
const editor = app.workspace.getActiveViewOfType(MarkdownView).editor;
const editor = app.workspace.activeLeaf.view?.editor;
let linetext = editor.getLine(editor.getCursor().line);
let newstr, linend = "";
const regex = /^(\>*(\[[!\w]+\])?\s*)#+\s/;
Expand Down Expand Up @@ -412,7 +412,7 @@ export function setHeader(_str: string) {

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

let selectText = editor.getSelection();
if (selectText == null || selectText == "") {
Expand Down Expand Up @@ -451,7 +451,7 @@ export const createFollowingbar = (app: App, settings: cMenuToolbarSettings) =>

if (isSource(app)) {
if (cMenuToolbarModalBar) {
const editor = app.workspace.getActiveViewOfType(MarkdownView).editor;
const editor = app.workspace.activeLeaf.view?.editor;

cMenuToolbarModalBar.style.visibility = editor.somethingSelected() ? "visible" : "hidden";
cMenuToolbarModalBar.style.height = (settings.aestheticStyle === "tiny") ? 30 + "px" : 40 + "px";
Expand Down Expand Up @@ -553,7 +553,7 @@ export function cMenuToolbarPopover(
// }

if (settings.positionStyle == "top") {
let currentleaf = app.workspace.getActiveViewOfType(MarkdownView).containerEl;
let currentleaf = app.workspace.activeLeaf.view.containerEl;

if (!currentleaf?.querySelector("#cMenuToolbarPopoverBar"))
{
Expand Down Expand Up @@ -582,8 +582,8 @@ export function cMenuToolbarPopover(



let cMenuToolbarPopoverBar = app.workspace.getActiveViewOfType(MarkdownView).containerEl
?.querySelector("#cMenuToolbarPopoverBar") as HTMLElement
let cMenuToolbarPopoverBar = app.workspace.activeLeaf.view.containerEl
?.querySelector("#cMenuToolbarPopoverBar") as HTMLElement;
settings.menuCommands.forEach((item, index) => {
let tip;
if ("SubmenuCommands" in item) {
Expand Down
22 changes: 10 additions & 12 deletions src/plugin/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ export default class cMenuToolbarPlugin extends Plugin {

//let cmEditor = view.sourceMode.cmEditor;

let cmEditor = app.workspace.getActiveViewOfType(MarkdownView).editor;
let cmEditor = app.workspace.activeLeaf.view?.editor;
if (cmEditor.hasFocus()) {
let cMenuToolbarModalBar = isExistoolbar(this.app, this.settings)

Expand Down Expand Up @@ -316,7 +316,7 @@ export default class cMenuToolbarPlugin extends Plugin {
callback: () => {
//const activeLeaf = this.app.workspace.getActiveViewOfType(MarkdownView);
//const view = activeLeaf;
const editor = app.workspace.getActiveViewOfType(MarkdownView).editor;
const editor = app.workspace.activeLeaf.view?.editor;
//@ts-ignore
return editor.indentList();
},
Expand All @@ -327,7 +327,7 @@ export default class cMenuToolbarPlugin extends Plugin {
id: 'undent-list',
name: 'unindent-list',
callback: () => {
const editor = app.workspace.getActiveViewOfType(MarkdownView).editor;
const editor = app.workspace.activeLeaf.view?.editor;
//@ts-ignore
return editor.unindentList();
},
Expand All @@ -338,7 +338,7 @@ export default class cMenuToolbarPlugin extends Plugin {
id: 'editor-undo',
name: 'undo editor',
callback: () => {
const editor = app.workspace.getActiveViewOfType(MarkdownView).editor;
const editor = app.workspace.activeLeaf.view?.editor;
return editor.undo();
},
icon: "undo-glyph"
Expand All @@ -350,7 +350,7 @@ export default class cMenuToolbarPlugin extends Plugin {
callback: () => {
const activeLeaf = this.app.workspace.getActiveViewOfType(MarkdownView);
const view = activeLeaf;
const editor = app.workspace.getActiveViewOfType(MarkdownView).editor;
const editor = app.workspace.activeLeaf.view?.editor;
return editor.redo();
},
icon: "redo-glyph"
Expand All @@ -361,7 +361,7 @@ export default class cMenuToolbarPlugin extends Plugin {
name: 'copy editor',
callback: async () => {

const editor = app.workspace.getActiveViewOfType(MarkdownView).editor;
const editor = app.workspace.activeLeaf.view?.editor;
try {
await window.navigator.clipboard.writeText(editor.getSelection()); // 使用 window.navigator.clipboard.writeText() 方法将选定的文本写入剪贴板
app.commands.executeCommandById("editor:focus");
Expand All @@ -376,9 +376,7 @@ export default class cMenuToolbarPlugin extends Plugin {
id: 'editor-paste',
name: 'paste editor',
callback: async () => {
const activeLeaf = this.app.workspace.getActiveViewOfType(MarkdownView);
const view = activeLeaf;
const editor = app.workspace.getActiveViewOfType(MarkdownView).editor;
const editor = app.workspace.activeLeaf.view?.editor;
try {
var replaceSelection = editor.replaceSelection; // 获取编辑器的替换选区方法
var text = await window.navigator.clipboard.readText(); // 使用 window.navigator.clipboard.readText() 方法读取剪贴板中的文本
Expand All @@ -396,7 +394,7 @@ export default class cMenuToolbarPlugin extends Plugin {
name: 'cut editor',
callback: async () => {

const editor = app.workspace.getActiveViewOfType(MarkdownView).editor;
const editor = app.workspace.activeLeaf.view?.editor;
try {
await window.navigator.clipboard.writeText(editor.getSelection()); // 使用 window.navigator.clipboard.writeText() 方法将选定的文本写入剪贴板
editor.replaceSelection(""); // 清空选定的文本
Expand Down Expand Up @@ -591,7 +589,7 @@ export default class cMenuToolbarPlugin extends Plugin {
name: `Toggle ${type}`,
icon: `${type}-glyph`,
callback: async () => {
const editor = app.workspace.getActiveViewOfType(MarkdownView).editor;
const editor = app.workspace.activeLeaf.view?.editor;
applyCommand(commandsMap[type], editor);
await wait(10);
//@ts-ignore
Expand All @@ -607,7 +605,7 @@ export default class cMenuToolbarPlugin extends Plugin {
name: `${type["name"]}`,
icon: `${type["icon"]}`,
callback: async () => {
const editor = app.workspace.getActiveViewOfType(MarkdownView).editor;
const editor = app.workspace.activeLeaf.view?.editor;
editor.getCursor("from");
const curserEnd = editor.getCursor("to");
let char;
Expand Down

0 comments on commit dedce43

Please sign in to comment.