Skip to content

Commit

Permalink
2.4.2
Browse files Browse the repository at this point in the history
  • Loading branch information
cumany committed Mar 29, 2024
1 parent e963cda commit 22b656c
Show file tree
Hide file tree
Showing 10 changed files with 540 additions and 262 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.1",
"version": "2.4.2",
"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
39 changes: 37 additions & 2 deletions build/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
-webkit-transition: 100ms cubic-bezier(0.92, -0.53, 0.65, 1.21);
min-width: fit-content;
justify-content: space-around;
z-index: var(--layer-popover);
z-index: 51;

This comment has been minimized.

Copy link
@s4my

s4my Apr 1, 2024

What's the reason for this change? it introduced a new bug. Now in position set to "following" or "fixed", if you open the settings, the Editing Toolbar shows above the settings window (which has the z-index of --layer-modal, i.e., 50).


}

Expand Down Expand Up @@ -935,4 +935,39 @@ button[class^=cMenuToolbarCommandsubItem]::after {
}
.toolbar-pickr {
display:flex;
}
}


div[data-type="thino_view"] .memo-editor-wrapper:has(#cMenuToolbarModalBar)
{
padding-top:0;
padding-left:0;
padding-right:0;
}

div[data-type="thino_view"] .memo-editor-wrapper:has(#cMenuToolbarModalBar) .common-tools-wrapper
{
padding-left:16px;
padding-right:16px;
}
div[data-type="thino_view"] .memo-editor-wrapper #cMenuToolbarModalBar ~ .cm-editor{
padding-top:8px;
padding-bottom:0px;
padding-left:16px;
padding-right:16px;
}


body.auto-hide-header .workspace-tab-header-container:hover + .workspace-tab-container .workspace-leaf .workspace-leaf-content>.view-header {
margin-top: 0;
transition: all 0.1s linear;
}

body.auto-hide-header .workspace-tab-header-container + .workspace-tab-container .workspace-leaf .workspace-leaf-content>.view-header:hover {
margin-top: 0;
transition: all 0.6s linear;
}
body.auto-hide-header .workspace-tab-header-container + .workspace-tab-container .workspace-leaf .workspace-leaf-content>.view-header {
margin-top: -40px;
transition: all 0.6s linear;
}
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.1",
"version": "2.4.2",
"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
6 changes: 5 additions & 1 deletion src/modals/cMenuToolbarModal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ export function resetToolbar() {
}

export function selfDestruct() {
requireApiVersion("0.15.0") ? activeDocument = activeWindow.document : activeDocument = window.document;
const toolBarElement =activeDocument.getElementById("cMenuToolbarModalBar");
if(toolBarElement) toolBarElement.remove();
const rootSplits = getRootSplits();
const clearToolbar = (leaf: HTMLElement) => {

Expand Down Expand Up @@ -614,6 +617,7 @@ export function cMenuToolbarPopover(
let leafwidth = 99999;
if (settings.positionStyle == "top") {
let currentleaf = app.workspace.activeLeaf.view.containerEl

if (!currentleaf?.querySelector("#cMenuToolbarPopoverBar"))
currentleaf?.querySelector(".markdown-source-view")
.insertAdjacentElement("afterbegin", PopoverMenu);
Expand Down Expand Up @@ -895,7 +899,7 @@ export function cMenuToolbarPopover(
}
};
const view = app.workspace.getActiveViewOfType(ItemView);
if(view?.getViewType()==="markdown" ||view?.getViewType()==="canvas"){
if(view?.getViewType()==="markdown" ||view?.getViewType()==="thino_view"){
// let Markdown = app.workspace.getActiveViewOfType(MarkdownView);
// if (Markdown) {
if (isExistoolbar(app, plugin.settings)) return;
Expand Down
154 changes: 138 additions & 16 deletions src/plugin/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
Notice,
Command,
setIcon,
debounce,
Platform,
Editor,
MarkdownView,
ItemView,
Expand Down Expand Up @@ -84,7 +84,7 @@ export default class cMenuToolbarPlugin extends Plugin {
{
id: "editor:toggle-blockquote",
name: "Toggle blockquote",
icon: "quote-glyph",
icon: "lucide-text-quote",
},
{
id: "editor:toggle-bullet-list",
Expand All @@ -111,6 +111,52 @@ export default class cMenuToolbarPlugin extends Plugin {
name: "Toggle numbered list",
icon: "number-list-glyph",
},
{
id: "editor:insert-callout",
name: "Toggle Callout ",
icon: "lucide-quote",
},
{
id: "editor:insert-mathblock",
name: "Toggle MathBlock",
icon: "lucide-sigma-square",
},
{
id: "editor:toggle-inline-math",
name: "Toggle inline math",
icon: "lucide-sigma",
},
{
id: "editor:insert-table",
name: "Toggle table",
icon: "lucide-table",
},
{
id: "editor:swap-line-up",
name: "Toggle swap line up",
icon: "lucide-corner-right-up",
},
{
id: "editor:swap-line-down",
name: "Toggle swap line down",
icon: "lucide-corner-right-down",
},
{
id: "editor:attach-file",
name: "Toggle upload attach file",
icon: "lucide-paperclip",
},
{
id: "editor:clear-formatting",
name: "Toggle clear formatting",
icon: "lucide-eraser",
},
{
id: "editor:cycle-list-checklist",
name: "Toggle cycle list checklist",
icon: "lucide-check-square",
}

];

IS_MORE_Button: boolean;
Expand All @@ -122,10 +168,21 @@ export default class cMenuToolbarPlugin extends Plugin {

async onload(): Promise<void> {
console.log("cMenuToolbar v" + this.manifest.version + " loaded");

requireApiVersion("0.15.0") ? activeDocument = activeWindow.document : activeDocument = window.document;
await this.loadSettings();
let screenWidth = window.innerWidth > 0 ? window.innerWidth : screen.width;
let isLoadOnMobile = this.settings?.isLoadOnMobile?this.settings.isLoadOnMobile:false;
if (Platform.isMobileApp && !isLoadOnMobile) {
if (screenWidth <= 768) {
// 移动设备且屏幕宽度小于等于 768px,默认不开启toolbar
new Notice("Mobile devices are disabled by default, if enabled please update the Toolbar settings.", 3000);
console.log("editing toolbar disable loading on mobile");
return;
}
}
addIcons();
// addRemixIcons(appIcons);
// addRemixIcconsole.log();ons(appIcons);
this.generateCommands();
this.app.workspace.onLayoutReady(() => {
setTimeout(() => {
Expand All @@ -139,9 +196,12 @@ export default class cMenuToolbarPlugin extends Plugin {
});
}
this.addSettingTab(new cMenuToolbarSettingTab(this.app, this));

this.registerEvent(this.app.workspace.on("thino-editor-created",this.handlecMenuToolbar));
this.registerEvent(this.app.workspace.on("active-leaf-change", this.handlecMenuToolbar));
this.registerEvent(this.app.workspace.on("layout-change", this.handlecMenuToolbar_layout));
this.registerEvent(this.app.workspace.on("resize", this.handlecMenuToolbar_resize));
// this.app.workspace.onLayoutReady(this.handlecMenuToolbar_editor.bind(this));
if (this.settings.cMenuVisibility == true) {
setTimeout(() => {
dispatchEvent(new Event("cMenuToolbar-NewCommand"));
Expand Down Expand Up @@ -291,6 +351,60 @@ export default class cMenuToolbarPlugin extends Plugin {
},
icon: "redo-glyph"

});
this.addCommand({
id: 'editor-copy',
name: 'copy editor',
callback: async() => {
const activeLeaf = this.app.workspace.getActiveViewOfType(MarkdownView);
const view = activeLeaf;
const editor = view.editor;
try {
await window.navigator.clipboard.writeText(editor.getSelection()); // 使用 window.navigator.clipboard.writeText() 方法将选定的文本写入剪贴板
app.commands.executeCommandById("editor:focus");
} catch (error) {
console.error("Copy failed:", error);
}
},
icon: "lucide-copy"

});
this.addCommand({
id: 'editor-paste',
name: 'paste editor',
callback: async() => {
const activeLeaf = this.app.workspace.getActiveViewOfType(MarkdownView);
const view = activeLeaf;
const editor = view.editor;
try {
var replaceSelection = editor.replaceSelection; // 获取编辑器的替换选区方法
var text = await window.navigator.clipboard.readText(); // 使用 window.navigator.clipboard.readText() 方法读取剪贴板中的文本
return replaceSelection.apply(editor, [text]); // 将读取的文本替换当前选区
app.commands.executeCommandById("editor:focus");
} catch (error) {
console.error("Paste failed:", error);
}
},
icon: "lucide-clipboard-type"

});
this.addCommand({
id: 'editor-cut',
name: 'cut editor',
callback: async() => {
const activeLeaf = this.app.workspace.getActiveViewOfType(MarkdownView);
const view = activeLeaf;
const editor = view.editor;
try {
await window.navigator.clipboard.writeText(editor.getSelection()); // 使用 window.navigator.clipboard.writeText() 方法将选定的文本写入剪贴板
editor.replaceSelection(""); // 清空选定的文本
app.commands.executeCommandById("editor:focus");
} catch (error) {
console.error("Cut failed:", error);
}
},
icon: "lucide-scissors"

});
this.addCommand({
id: "fullscreen-focus",
Expand Down Expand Up @@ -630,22 +744,24 @@ export default class cMenuToolbarPlugin extends Plugin {
onunload(): void {
selfDestruct();
console.log("cMenuToolbar unloaded");

this.app.workspace.off("active-leaf-change", this.handlecMenuToolbar);

this.app.workspace.off("layout-change", this.handlecMenuToolbar_layout);
this.app.workspace.off("resize", this.handlecMenuToolbar_resize);
}


handlecMenuToolbar = () => {
if (this.settings.cMenuVisibility == true) {
//const view = this.app.workspace.getActiveViewOfType(ItemView);
//console.log(view?.getViewType() )

let view = this.app.workspace.getActiveViewOfType(MarkdownView)
// const type= this.app.workspace.activeLeaf.getViewState().type
// console.log(type,"active-leaf-chang" )
// let view = true

let toolbar = isExistoolbar(this.app, this.settings)
if(view)
{
// if(view)


if (toolbar) {
if (this.settings.positionStyle != "following") {
Expand All @@ -665,20 +781,24 @@ export default class cMenuToolbarPlugin extends Plugin {
} else {

setTimeout(() => {
console.log("cMenuToolbarPopover begin..." )
cMenuToolbarPopover(this.app, this)
}, 100);
}
}

}
};

handlecMenuToolbar_layout = () => {
// requireApiVersion("0.15.0") ? activeDocument = activeWindow.document : activeDocument = window.document;
//const view = this.app.workspace.getActiveViewOfType(ItemView);
//console.log(view?.getViewType(),"handlecMenuToolbar_layout" )
// const type= this.app.workspace.activeLeaf.getViewState().type
// console.log(type,"handlecMenuToolbar_layout" )
if (this.settings.cMenuVisibility == true) {
let cMenuToolbarModalBar = isExistoolbar(this.app, this.settings)
let view = this.app.workspace.getActiveViewOfType(MarkdownView)
// console.log(cMenuToolbarModalBar,"cMenuToolbarModalBar" )
//let view = this.app.workspace.getActiveViewOfType(MarkdownView) || true
let view = true
if ((getModestate(app)===false)|| (!view)) //no source mode
{
if (cMenuToolbarModalBar) {
Expand All @@ -694,7 +814,7 @@ export default class cMenuToolbarPlugin extends Plugin {
}

} else {

// console.log("cMenuToolbarPopover begin..." )
setTimeout(() => {
cMenuToolbarPopover(this.app, this)
}, 100);
Expand All @@ -710,13 +830,15 @@ export default class cMenuToolbarPlugin extends Plugin {

};
handlecMenuToolbar_resize = () => {

// const type= this.app.workspace.activeLeaf.getViewState().type
// console.log(type,"handlecMenuToolbar_layout" )
//requireApiVersion("0.15.0") ? activeDocument = activeWindow.document : activeDocument = window.document;
if (this.settings.cMenuVisibility == true && this.settings.positionStyle == "top") {
if (getModestate(app)) {
let view = this.app.workspace.getActiveViewOfType(MarkdownView)
let view = this.app.workspace.getActiveViewOfType(MarkdownView) || true
if (view) {
let leafwidth = view.containerEl?.querySelector<HTMLElement>(".markdown-source-view").offsetWidth ?? 0
let leafwidth= this.app.workspace.activeLeaf.view.leaf.width??0
//let leafwidth = view.containerEl?.querySelector<HTMLElement>(".markdown-source-view").offsetWidth ?? 0
if (this.Leaf_Width == leafwidth) return false;
if (leafwidth > 0) {
this.Leaf_Width = leafwidth
Expand Down
Loading

0 comments on commit 22b656c

Please sign in to comment.