Skip to content

Commit

Permalink
0.5.2 fixed open flow and added close flow
Browse files Browse the repository at this point in the history
  • Loading branch information
jp-cen committed Nov 26, 2022
1 parent a8af472 commit 46170da
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 17 deletions.
39 changes: 31 additions & 8 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -6852,7 +6852,11 @@ var T4 = class {
},
commandPalette: {
enable: "Enable",
disabled: "Disable"
disabled: "Disable",
openFlow: "Open Flow Editors in Selection",
closeFlow: "Close Flow Editors in Selection",
toggleBold: "Toggle Bold",
toggleItalics: "Toggle Italics"
},
menu: {
openFilePane: "Open in a new pane",
Expand Down Expand Up @@ -18438,20 +18442,34 @@ var MakeMDPlugin = class extends import_obsidian15.Plugin {
this.openFileTreeLeaf(true);
};
}
toggleFlow() {
openFlow() {
const cm = getActiveCM();
if (cm) {
const value = cm.state.field(flowEditorInfo, false);
const currPosition = cm.state.selection.main;
for (let flowEditor of value) {
if (flowEditor.from > currPosition.from && flowEditor.to < currPosition.to) {
if (flowEditor.from < currPosition.to && flowEditor.to > currPosition.from) {
cm.dispatch({
annotations: toggleFlowEditor.of([flowEditor.id, 2])
});
}
}
}
}
closeFlow() {
const cm = getActiveCM();
if (cm) {
const value = cm.state.field(flowEditorInfo, false);
const currPosition = cm.state.selection.main;
for (let flowEditor of value) {
if (flowEditor.from < currPosition.to && flowEditor.to > currPosition.from) {
cm.dispatch({
annotations: toggleFlowEditor.of([flowEditor.id, 0])
});
}
}
}
}
toggleBold() {
const cm = getActiveCM();
if (cm) {
Expand Down Expand Up @@ -18494,9 +18512,14 @@ var MakeMDPlugin = class extends import_obsidian15.Plugin {
document.body.classList.toggle("mk-flow-replace", this.settings.editorFlow);
document.body.classList.toggle("mk-flow-" + this.settings.editorFlowStyle, true);
this.addCommand({
id: "mk-toggle-flow",
name: "Open Flow Editors in Selection",
callback: () => this.toggleFlow()
id: "mk-open-flow",
name: i18n_default.commandPalette.openFlow,
callback: () => this.openFlow()
});
this.addCommand({
id: "mk-close-flow",
name: i18n_default.commandPalette.closeFlow,
callback: () => this.closeFlow()
});
if (this.settings.editorFlow) {
this.registerMarkdownPostProcessor((element, context) => {
Expand All @@ -18520,7 +18543,7 @@ var MakeMDPlugin = class extends import_obsidian15.Plugin {
document.body.classList.toggle("mk-mark-sans", this.settings.markSans);
this.addCommand({
id: "mk-toggle-bold",
name: "Toggle Bold",
name: i18n_default.commandPalette.toggleBold,
callback: () => this.toggleBold(),
hotkeys: [
{
Expand All @@ -18531,7 +18554,7 @@ var MakeMDPlugin = class extends import_obsidian15.Plugin {
});
this.addCommand({
id: "mk-toggle-italics",
name: "Toggle Italics",
name: i18n_default.commandPalette.toggleItalics,
callback: () => this.toggleEm(),
hotkeys: [
{
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": "make-md",
"name": "MAKE.md",
"version": "0.5.1",
"version": "0.5.2",
"minAppVersion": "0.16.0",
"description": "The ultimate experience for makers on Obsidian",
"author": "MAKE.md",
Expand Down
6 changes: 5 additions & 1 deletion src/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class T {
tag: 'Tag',
makeMenu: 'Make Menu',
selectStyle: 'Style',
toggleKeyboard: 'Toggle Keyboard'
toggleKeyboard: 'Toggle Keyboard',

},
styles: {
Expand All @@ -41,6 +41,10 @@ class T {
commandPalette: {
enable: "Enable",
disabled: "Disable",
openFlow: 'Open Flow Editors in Selection',
closeFlow: 'Close Flow Editors in Selection',
toggleBold: 'Toggle Bold',
toggleItalics: 'Toggle Italics',
},
menu: {
openFilePane: 'Open in a new pane',
Expand Down
34 changes: 27 additions & 7 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,40 @@ import { platform } from 'os';
import { getActiveCM, iterateTreeAtPos } from 'utils/codemirror';
import { mkLogo } from 'utils/icons';
import { flowEditorInfo, toggleFlowEditor } from 'cm-extensions/flowEditor/flowEditor';
import t from 'i18n'
export default class MakeMDPlugin extends Plugin {
settings: MakeMDPluginSettings;
activeEditorView?: MarkdownView;
flowEditors: FlowEditor[];

toggleFlow() {
openFlow() {
const cm = getActiveCM();
if (cm) {
const value = cm.state.field(flowEditorInfo, false);
const currPosition = cm.state.selection.main;
for (let flowEditor of value) {
if (flowEditor.from > currPosition.from && flowEditor.to < currPosition.to) {
if (flowEditor.from < currPosition.to && flowEditor.to > currPosition.from) {
cm.dispatch({
annotations: toggleFlowEditor.of([flowEditor.id, 2])
});
}
}
}
}
closeFlow() {
const cm = getActiveCM();
if (cm) {
const value = cm.state.field(flowEditorInfo, false);
const currPosition = cm.state.selection.main;
for (let flowEditor of value) {
if (flowEditor.from < currPosition.to && flowEditor.to > currPosition.from) {
cm.dispatch({
annotations: toggleFlowEditor.of([flowEditor.id, 0])
});
}
}
}
}

toggleBold () {
const cm = getActiveCM();
Expand Down Expand Up @@ -87,11 +102,16 @@ export default class MakeMDPlugin extends Plugin {
document.body.classList.toggle('mk-flow-'+this.settings.editorFlowStyle, true);

this.addCommand({
id: 'mk-toggle-flow',
name: 'Open Flow Editors in Selection',
callback: () => this.toggleFlow(),
id: 'mk-open-flow',
name: t.commandPalette.openFlow,
callback: () => this.openFlow(),
});

this.addCommand({
id: 'mk-close-flow',
name: t.commandPalette.closeFlow,
callback: () => this.closeFlow(),
});
if (this.settings.editorFlow) {
this.registerMarkdownPostProcessor((element, context) => {
const removeAllFlowMarks = (el: HTMLElement) => {
Expand All @@ -118,7 +138,7 @@ export default class MakeMDPlugin extends Plugin {
document.body.classList.toggle('mk-mark-sans', this.settings.markSans);
this.addCommand({
id: 'mk-toggle-bold',
name: 'Toggle Bold',
name: t.commandPalette.toggleBold,
callback: () => this.toggleBold(),
hotkeys: [
{
Expand All @@ -130,7 +150,7 @@ export default class MakeMDPlugin extends Plugin {

this.addCommand({
id: 'mk-toggle-italics',
name: 'Toggle Italics',
name: t.commandPalette.toggleItalics,
callback: () => this.toggleEm(),
hotkeys: [
{
Expand Down

0 comments on commit 46170da

Please sign in to comment.