From c0bdf1fb637598b6ab15f397542ecc791e4e4bb7 Mon Sep 17 00:00:00 2001 From: mattuy Date: Thu, 7 Oct 2021 14:50:14 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E6=8B=AC=E5=8F=B7?= =?UTF-8?q?=E7=AC=A6=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit close #1 --- src/util/notation.js | 38 +++++++++++++++++++++++++++++++++++-- src/view/HelpModal/index.js | 9 +++++++-- src/view/Notation/index.js | 30 ++--------------------------- 3 files changed, 45 insertions(+), 32 deletions(-) diff --git a/src/util/notation.js b/src/util/notation.js index e5a889e..74e7a43 100644 --- a/src/util/notation.js +++ b/src/util/notation.js @@ -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, }; diff --git a/src/view/HelpModal/index.js b/src/view/HelpModal/index.js index 60e0792..5490cd2 100644 --- a/src/view/HelpModal/index.js +++ b/src/view/HelpModal/index.js @@ -40,9 +40,14 @@ function HelpModal({ visible, onVisibleChange }) {

仅选中符号时

-

输入

+

输入音符

+ 直接按键盘上相应的键即可输入到当前符号。支持的音符符号有: +

+ 0~7 + ( ) +

+

输入辅助元素