Browse Source

feat: 元素编辑1.6

TIANYONG 1 year ago
parent
commit
edc307dc89
1 changed files with 20 additions and 8 deletions
  1. 20 8
      src/view/plugins/move-music-score/index.tsx

+ 20 - 8
src/view/plugins/move-music-score/index.tsx

@@ -483,15 +483,27 @@ export const renderForMoveData = () => {
 				let index = moveData.modelList.findIndex((n: any) => n.id === item.id);
 				if (item.type === 'vf-text' && item.textContent) {
 					let textValue = document.querySelector("#" + moveData.modelList[index].id)?.querySelector("text")?.innerHTML || ''
-					let targetIndex = index, preEnd = false;
-					while (textValue !== item.textContent) {
-						if (preEnd) {
-							targetIndex = targetIndex + 1
-						} else {
-							targetIndex = targetIndex > 0 ? targetIndex - 1 : targetIndex
+					let targetIndex = index, preEnd = false, done = false, preIndex = index, nextIndex = index;
+					// while (textValue !== item.textContent) {
+					// 	if (preEnd) {
+					// 		targetIndex = targetIndex + 1
+					// 	} else {
+					// 		targetIndex = targetIndex > 0 ? targetIndex - 1 : targetIndex
+					// 	}
+					// 	if (targetIndex == 0) preEnd = true
+					// 	textValue = document.querySelector("#" + moveData.modelList[targetIndex].id)?.querySelector("text")?.innerHTML || ''
+					// }
+					if (textValue !== item.textContent) {
+						while (!done) {
+							preIndex = targetIndex - 1
+							nextIndex = targetIndex + 1
+							let text1 = document.querySelector("#" + moveData.modelList[preIndex].id)?.querySelector("text")?.innerHTML || ''
+							let text2 = document.querySelector("#" + moveData.modelList[nextIndex].id)?.querySelector("text")?.innerHTML || ''
+							if (text1 === item.textContent || text2 === item.textContent) {
+								done = true
+								targetIndex = text1 === item.textContent ? preIndex : nextIndex
+							}
 						}
-						if (targetIndex == 0) preEnd = true
-						textValue = document.querySelector("#" + moveData.modelList[targetIndex].id)?.querySelector("text")?.innerHTML || ''
 					}
 					// index = targetIndex + 1
 					// item.id = `text${index}`