Skip to content

Open-Source API Development Ecosystem • https://hoppscotch.io • Offline, On-Prem & Cloud • Web, Desktop & CLI • Open-Source Alternative to Postman, Insomnia

wip - some raw text formtting with one small return bug to fix

Nicholas Palencharfddd41f6b41a
diff --git a/pages/index.vue b/pages/index.vue
index 501be50c7..82788ad02 100644
--- a/pages/index.vue
+++ b/pages/index.vue
@@ -68,7 +68,7 @@
</li>
</ul>
</div><div v-else>
- <textarea v-model="rawParams" style="font-family: monospace;" rows="16"></textarea>
+ <textarea v-model="rawParams" style="font-family: monospace;" rows="16" @keydown="formatRawParams"></textarea>
</div>
</pw-section>
@@ -379,6 +379,31 @@
},
removeRequestBodyParam(index) {
this.bodyParams.splice(index, 1)
+ },
+ formatRawParams(event) {
+ if ((event.which !== 13 && event.which !== 9)) {
+ console.log('not not returning');
+ return
+ }
+
+ const textBody = event.target.value;
+ const textBeforeCursor = textBody.substring(0, event.target.selectionStart);
+ const textAfterCursor = textBody.substring(event.target.selectionEnd);
+
+ if (event.which === 13) {
+ const lastLine = textBody.split('\n').slice(-1)[0];
+ const rightPadding = lastLine.match(/([\s\t]*).*/)[1] || "";
+ setTimeout(() => event.target.value = textBeforeCursor + '\n' + rightPadding + textAfterCursor, 1);
+ }
+ else if (event.which === 9) {
+ event.preventDefault();
+ const oldSelectionStart = event.target.selectionStart;
+ const oldSelectionEnd = event.target.selectionEnd;
+ event.target.value = textBeforeCursor + '\xa0\xa0' + textAfterCursor;
+ debugger;
+ event.target.selectionStart = event.target.selectionEnd = oldSelectionStart + 2;
+ return false;
+ }
}
}
}