feat: reactive line wrap on codemirror

Co-authored-by: Andrew Bastin <andrewbastin.k@gmail.com>
This commit is contained in:
liyasthomas
2021-09-09 20:50:04 +05:30
parent 02cf620090
commit c6c08f6c60
7 changed files with 95 additions and 37 deletions

View File

@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="9 10 4 15 9 20"></polyline><path d="M20 4v7a4 4 0 0 1-4 4H4"></path></svg>

After

Width:  |  Height:  |  Size: 274 B

View File

@@ -475,7 +475,7 @@ input[type="checkbox"] {
} }
.CodeMirror-scroll { .CodeMirror-scroll {
@apply min-h-32; @apply min-h-64;
} }
@media (max-width: 767px) { @media (max-width: 767px) {

View File

@@ -17,6 +17,14 @@
{{ $t("response.body") }} {{ $t("response.body") }}
</label> </label>
<div class="flex"> <div class="flex">
<ButtonSecondary
v-if="response.body"
v-tippy="{ theme: 'tooltip' }"
:title="$t('state.linewrap')"
:class="{ '!text-accent': linewrapEnabled }"
svg="corner-down-left"
@click.native.prevent="linewrapEnabled = !linewrapEnabled"
/>
<ButtonSecondary <ButtonSecondary
v-if="response.body" v-if="response.body"
v-tippy="{ theme: 'tooltip' }" v-tippy="{ theme: 'tooltip' }"
@@ -57,7 +65,7 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { computed, ref, useContext } from "@nuxtjs/composition-api" import { computed, ref, useContext, reactive } from "@nuxtjs/composition-api"
import { useCodemirror } from "~/helpers/editor/codemirror" import { useCodemirror } from "~/helpers/editor/codemirror"
import { copyToClipboard } from "~/helpers/utils/clipboard" import { copyToClipboard } from "~/helpers/utils/clipboard"
import "codemirror/mode/htmlmixed/htmlmixed" import "codemirror/mode/htmlmixed/htmlmixed"
@@ -94,15 +102,21 @@ const previewFrame = ref<any | null>(null)
const url = ref("") const url = ref("")
const htmlResponse = ref<any | null>(null) const htmlResponse = ref<any | null>(null)
const linewrapEnabled = ref(true)
useCodemirror(htmlResponse, responseBodyText, { useCodemirror(
extendedEditorConfig: { htmlResponse,
mode: "javascript", responseBodyText,
readOnly: true, reactive({
}, extendedEditorConfig: {
linter: null, mode: "javascript",
completer: null, readOnly: true,
}) lineWrapping: linewrapEnabled,
},
linter: null,
completer: null,
})
)
const downloadResponse = () => { const downloadResponse = () => {
const dataToWrite = responseBodyText.value const dataToWrite = responseBodyText.value

View File

@@ -17,6 +17,14 @@
{{ $t("response.body") }} {{ $t("response.body") }}
</label> </label>
<div class="flex"> <div class="flex">
<ButtonSecondary
v-if="response.body"
v-tippy="{ theme: 'tooltip' }"
:title="$t('state.linewrap')"
:class="{ '!text-accent': linewrapEnabled }"
svg="corner-down-left"
@click.native.prevent="linewrapEnabled = !linewrapEnabled"
/>
<ButtonSecondary <ButtonSecondary
v-if="response.body" v-if="response.body"
ref="downloadResponse" ref="downloadResponse"
@@ -42,7 +50,7 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { computed, ref, useContext } from "@nuxtjs/composition-api" import { computed, ref, useContext, reactive } from "@nuxtjs/composition-api"
import { useCodemirror } from "~/helpers/editor/codemirror" import { useCodemirror } from "~/helpers/editor/codemirror"
import { copyToClipboard } from "~/helpers/utils/clipboard" import { copyToClipboard } from "~/helpers/utils/clipboard"
import "codemirror/mode/javascript/javascript" import "codemirror/mode/javascript/javascript"
@@ -85,15 +93,21 @@ const jsonBodyText = computed(() => {
}) })
const jsonResponse = ref<any | null>(null) const jsonResponse = ref<any | null>(null)
const linewrapEnabled = ref(true)
useCodemirror(jsonResponse, jsonBodyText, { useCodemirror(
extendedEditorConfig: { jsonResponse,
mode: "javascript", jsonBodyText,
readOnly: true, reactive({
}, extendedEditorConfig: {
linter: null, mode: "javascript",
completer: null, readOnly: true,
}) lineWrapping: linewrapEnabled,
},
linter: null,
completer: null,
})
)
const downloadResponse = () => { const downloadResponse = () => {
const dataToWrite = responseBodyText.value const dataToWrite = responseBodyText.value

View File

@@ -17,6 +17,14 @@
{{ $t("response.body") }} {{ $t("response.body") }}
</label> </label>
<div class="flex"> <div class="flex">
<ButtonSecondary
v-if="response.body"
v-tippy="{ theme: 'tooltip' }"
:title="$t('state.linewrap')"
:class="{ '!text-accent': linewrapEnabled }"
svg="corner-down-left"
@click.native.prevent="linewrapEnabled = !linewrapEnabled"
/>
<ButtonSecondary <ButtonSecondary
v-if="response.body" v-if="response.body"
ref="downloadResponse" ref="downloadResponse"
@@ -42,7 +50,7 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { ref, useContext, computed } from "@nuxtjs/composition-api" import { ref, useContext, computed, reactive } from "@nuxtjs/composition-api"
import { useCodemirror } from "~/helpers/editor/codemirror" import { useCodemirror } from "~/helpers/editor/codemirror"
import { copyToClipboard } from "~/helpers/utils/clipboard" import { copyToClipboard } from "~/helpers/utils/clipboard"
import "codemirror/mode/yaml/yaml" import "codemirror/mode/yaml/yaml"
@@ -85,15 +93,21 @@ const responseType = computed(() => {
}) })
const rawResponse = ref<any | null>(null) const rawResponse = ref<any | null>(null)
const linewrapEnabled = ref(true)
useCodemirror(rawResponse, responseBodyText, { useCodemirror(
extendedEditorConfig: { rawResponse,
mode: "text/x-yaml", responseBodyText,
readOnly: true, reactive({
}, extendedEditorConfig: {
linter: null, mode: "text/x-yaml",
completer: null, readOnly: true,
}) lineWrapping: linewrapEnabled,
},
linter: null,
completer: null,
})
)
const downloadResponse = () => { const downloadResponse = () => {
const dataToWrite = responseBodyText.value const dataToWrite = responseBodyText.value

View File

@@ -17,6 +17,14 @@
{{ $t("response.body") }} {{ $t("response.body") }}
</label> </label>
<div class="flex"> <div class="flex">
<ButtonSecondary
v-if="response.body"
v-tippy="{ theme: 'tooltip' }"
:title="$t('state.linewrap')"
:class="{ '!text-accent': linewrapEnabled }"
svg="corner-down-left"
@click.native.prevent="linewrapEnabled = !linewrapEnabled"
/>
<ButtonSecondary <ButtonSecondary
v-if="response.body" v-if="response.body"
ref="downloadResponse" ref="downloadResponse"
@@ -42,7 +50,7 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { computed, ref, useContext } from "@nuxtjs/composition-api" import { computed, ref, useContext, reactive } from "@nuxtjs/composition-api"
import { useCodemirror } from "~/helpers/editor/codemirror" import { useCodemirror } from "~/helpers/editor/codemirror"
import { copyToClipboard } from "~/helpers/utils/clipboard" import { copyToClipboard } from "~/helpers/utils/clipboard"
import "codemirror/mode/xml/xml" import "codemirror/mode/xml/xml"
@@ -85,15 +93,21 @@ const responseType = computed(() => {
}) })
const xmlResponse = ref<any | null>(null) const xmlResponse = ref<any | null>(null)
const linewrapEnabled = ref(true)
useCodemirror(xmlResponse, responseBodyText, { useCodemirror(
extendedEditorConfig: { xmlResponse,
mode: "application/xml", responseBodyText,
readOnly: true, reactive({
}, extendedEditorConfig: {
linter: null, mode: "application/xml",
completer: null, readOnly: true,
}) lineWrapping: linewrapEnabled,
},
linter: null,
completer: null,
})
)
const downloadResponse = () => { const downloadResponse = () => {
const dataToWrite = responseBodyText.value const dataToWrite = responseBodyText.value

View File

@@ -421,6 +421,7 @@
"file_imported": "File imported", "file_imported": "File imported",
"finished_in": "Finished in {duration}ms", "finished_in": "Finished in {duration}ms",
"history_deleted": "History deleted", "history_deleted": "History deleted",
"linewrap": "Wrap lines",
"loading": "Loading...", "loading": "Loading...",
"none": "None", "none": "None",
"nothing_found": "Nothing found for", "nothing_found": "Nothing found for",