Browse Source

Allow toggling for format selection

sbkwgh 8 năm trước cách đây
mục cha
commit
7503e4df03
1 tập tin đã thay đổi với 25 bổ sung10 xóa
  1. 25 10
      src/components/InputEditorCore.vue

+ 25 - 10
src/components/InputEditorCore.vue

@@ -173,17 +173,32 @@
 				var selectionData = this.getSelectionData();
 				var el = this.$refs.textarea;
 
-				this.setEditor(
-					this.value.slice(0, selectionData.start) +
-					before + selectionData.val + after +
-					this.value.slice(selectionData.end)
-				);
-				el.focus();
+				if(
+					this.value.substr(selectionData.start - before.length, before.length) === before &&
+					this.value.substr(selectionData.end, after.length) === after
+				) {
+					this.setEditor(
+						this.value.slice(0, selectionData.start - before.length) +
+						selectionData.val +
+						this.value.slice(selectionData.end + after.length)
+					);
+					setTimeout(function() {
+						el.selectionStart = selectionData.start - before.length;
+						el.selectionEnd = selectionData.end - after.length;
+					}, 0);
+				} else {
+					this.setEditor(
+						this.value.slice(0, selectionData.start) +
+						before + selectionData.val + after +
+						this.value.slice(selectionData.end)
+					);
+					setTimeout(function() {
+						el.selectionStart = selectionData.start + before.length;
+						el.selectionEnd = selectionData.end + after.length;
+					}, 0);
+				}
 
-				setTimeout(function() {
-					el.selectionStart = selectionData.start + before.length;
-					el.selectionEnd = selectionData.end + before.length;
-				}, 0);
+				el.focus();
 			},
 			addLink () {
 				var linkTextLength = this.linkText.length;