Sfoglia il codice sorgente

Indent all code with indent code format button

sbkwgh 8 anni fa
parent
commit
cea0e7a342
1 ha cambiato i file con 15 aggiunte e 1 eliminazioni
  1. 15 1
      src/components/InputEditorCore.vue

+ 15 - 1
src/components/InputEditorCore.vue

@@ -135,7 +135,21 @@
 				var selectionData = this.getSelectionData();
 
 				if(this.value[selectionData.start-1] === '\n' || selectionData.start === 0) {
-					this.replaceSelectedText('    ', '');
+					var el = this.$refs.textarea;
+					var matches = selectionData.val.match(/\n/g || [] ).length
+					var replacedText = '    ' + selectionData.val.replace(/\n/g, '\n    ')
+
+					this.setEditor(
+						this.value.slice(0, selectionData.start) +
+						replacedText +
+						this.value.slice(selectionData.end)
+					);
+					el.focus();
+
+					setTimeout(function() {
+						el.selectionStart = selectionData.start + 4;
+						el.selectionEnd = selectionData.end + matches*4;
+					}, 1);
 				} else {
 					this.replaceSelectedText('`', '`');
 				}