feat: 添加括号符号

close #1
This commit is contained in:
2021-10-07 14:50:14 +08:00
parent c0eb2d5d70
commit c0bdf1fb63
3 changed files with 45 additions and 32 deletions
+36 -2
View File
@@ -1,4 +1,8 @@
import { message } from "antd";
import { toJS } from "mobx";
import state from "../store/state";
import { wrappedAction } from "../store/history";
import { findParagraphAndNotation } from "./editor";
const notations = {
zero: "0",
@@ -11,8 +15,8 @@ const notations = {
si: "7",
extend: "─",
separator: "│",
crackerOpen: "",
crackerClose: ")"
crackerOpen: "(",
crackerClose: ")",
};
const notes = [
notations.zero,
@@ -61,6 +65,35 @@ function cloneNotation(notation) {
return n;
}
// 放置连音线
const placeTie = wrappedAction((notation) => {
if (state.tieSourceKey) {
// 处理连音线
if (state.tieSourceKey === notation.key) {
state.tieSourceKey = null;
// NOTICE: 如果要添加其他逻辑注意这里的return
return;
}
const {
notation: sourceNotation,
paragraph: sourceParagraph,
} = findParagraphAndNotation(state.tieSourceKey);
if (!sourceNotation) {
state.tieSourceKey = null;
return;
}
if (!sourceParagraph.notations.includes(notation)) {
message.warn("只允许相同段落的音符相连!");
} else if (!isNote(notation)) {
message.warn("只允许在音符上添加连音线!");
} else {
sourceNotation.tieTo = notation.key;
notation.tieTo = sourceNotation.key;
}
state.tieSourceKey = null;
}
});
export {
notations,
isNote,
@@ -68,4 +101,5 @@ export {
isSeparator,
createNotation,
cloneNotation,
placeTie,
};