Skip to content

Commit

Permalink
feat(ui): Socket Panel > json highlighting + auto bracket closing + i…
Browse files Browse the repository at this point in the history
…ndent on input (closes #299)
  • Loading branch information
flawiddsouza committed Dec 23, 2024
1 parent 1a668ad commit f5c9ae0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
23 changes: 22 additions & 1 deletion packages/ui/src/components/CodeMirrorSingleLine.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@
import { EditorView, keymap, placeholder, drawSelection } from '@codemirror/view'
import { EditorState, StateEffect } from '@codemirror/state'
import { defaultKeymap, history, historyKeymap } from '@codemirror/commands'
import { autocompletion, completeFromList } from '@codemirror/autocomplete'
import { closeBrackets, autocompletion, completeFromList } from '@codemirror/autocomplete'
import { envVarDecoration } from '@/utils/codemirror-extensions'
import { tags } from '@/codemirror-extensions/tags'
import { json } from '@codemirror/lang-json'
import { codeMirrorSyntaxHighlighting, getEditorConfig, getSpaces } from '@/helpers'
import { syntaxHighlighting } from '@codemirror/language'
import { indentOnInput, indentUnit, bracketMatching, syntaxHighlighting } from '@codemirror/language'

Check failure on line 15 in packages/ui/src/components/CodeMirrorSingleLine.vue

View workflow job for this annotation

GitHub Actions / test

'syntaxHighlighting' is already defined
import type { ParsedResult } from '@/parsers/tag'
function getExtensions(vueInstance) {
Expand Down Expand Up @@ -64,7 +68,20 @@ function getExtensions(vueInstance) {
vueInstance.$emit('tag-click', parsedFunc, updateFunc)
}
const languageExtensions = []
if (vueInstance.lang === 'json') {
languageExtensions.push(json())
const highlightStyle = codeMirrorSyntaxHighlighting()
languageExtensions.push(syntaxHighlighting(highlightStyle, { fallback: true }))
languageExtensions.push(indentOnInput())
languageExtensions.push(indentUnit.of(getSpaces(getEditorConfig().indentSize)))
languageExtensions.push(bracketMatching())
languageExtensions.push(closeBrackets()) // auto close flower brackets, close double quotes
}
const extensions = [
...languageExtensions,
history(),
EditorView.updateListener.of(v => {
if(v.docChanged) {
Expand Down Expand Up @@ -181,6 +198,10 @@ export default {
type: Array,
default: () => []
},
lang: {

Check warning on line 201 in packages/ui/src/components/CodeMirrorSingleLine.vue

View workflow job for this annotation

GitHub Actions / test

Prop 'lang' requires default value to be set
type: String,
required: false,
},
},
data() {
return {
Expand Down
1 change: 1 addition & 0 deletions packages/ui/src/components/SocketPanel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@
:env-variables="collectionItemEnvironmentResolved"
:input-text-compatible="true"
:allow-multiple-lines="true"
lang="json"
class="w-100p mt-0_5rem input o-a"
style="height: 5.8rem; resize: vertical; margin-bottom: 0.2rem;"
/>
Expand Down

0 comments on commit f5c9ae0

Please sign in to comment.