feat: syntax highlighting for cURL and bulk editors

This commit is contained in:
liyasthomas
2021-12-29 08:05:07 +05:30
parent 923c24e3bb
commit a1decaf6ad
34 changed files with 50 additions and 48 deletions

View File

@@ -188,9 +188,9 @@ useCodemirror(bulkEditor, bulkHeaders, {
watch(bulkHeaders, () => {
try {
const transformation = bulkHeaders.value.split("\n").map((item) => ({
key: item.substring(0, item.indexOf(":")).trim().replace(/^\/\//, ""),
key: item.substring(0, item.indexOf(":")).trim().replace(/^#/, ""),
value: item.substring(item.indexOf(":") + 1).trim(),
active: !item.trim().startsWith("//"),
active: !item.trim().startsWith("#"),
}))
setRESTHeaders(transformation as HoppRESTHeader[])
} catch (e) {
@@ -218,14 +218,12 @@ watch(
onBeforeUpdate(() => editBulkHeadersLine(-1, null))
const editBulkHeadersLine = (index: number, item?: HoppRESTHeader | null) => {
const headers = headers$.value
bulkHeaders.value = headers
bulkHeaders.value = headers$.value
.reduce((all, header, pIndex) => {
const current =
index === pIndex && item != null
? `${item.active ? "" : "//"}${item.key}: ${item.value}`
: `${header.active ? "" : "//"}${header.key}: ${header.value}`
? `${item.active ? "" : "#"}${item.key}: ${item.value}`
: `${header.active ? "" : "#"}${header.key}: ${header.value}`
return [...all, current]
}, [])
.join("\n")

View File

@@ -169,9 +169,9 @@ const bulkParams = ref("")
watch(bulkParams, () => {
try {
const transformation = bulkParams.value.split("\n").map((item) => ({
key: item.substring(0, item.indexOf(":")).trim().replace(/^\/\//, ""),
key: item.substring(0, item.indexOf(":")).trim().replace(/^#/, ""),
value: item.substring(item.indexOf(":") + 1).trim(),
active: !item.trim().startsWith("//"),
active: !item.trim().startsWith("#"),
}))
setRESTParams(transformation as HoppRESTParam[])
} catch (e) {
@@ -211,14 +211,12 @@ watch(
onBeforeUpdate(() => editBulkParamsLine(-1, null))
const editBulkParamsLine = (index: number, item?: HoppRESTParam | null) => {
const params = params$.value
bulkParams.value = params
bulkParams.value = params$.value
.reduce((all, param, pIndex) => {
const current =
index === pIndex && item != null
? `${item.active ? "" : "//"}${item.key}: ${item.value}`
: `${param.active ? "" : "//"}${param.key}: ${param.value}`
? `${item.active ? "" : "#"}${item.key}: ${item.value}`
: `${param.active ? "" : "#"}${param.key}: ${param.value}`
return [...all, current]
}, [])
.join("\n")