Skip to content

Commit

Permalink
refactor: improve syntax highlighting and change theme in editor (#1200)
Browse files Browse the repository at this point in the history
Co-authored-by: truckershitch <truckershitch@hambone.e4ward.com>
Co-authored-by: Stefan Dej <meteyou@gmail.com>
  • Loading branch information
3 people authored May 18, 2023
1 parent 140d796 commit 080a713
Show file tree
Hide file tree
Showing 9 changed files with 339 additions and 463 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ temp
package-lock.json
*.local
.env
.vscode

cypress/screenshots/
cypress/videos/
Expand Down
42 changes: 42 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"@sindarius/gcodeviewer": "^3.2.2",
"@types/node": "^18.0.0",
"@types/overlayscrollbars": "^1.12.1",
"@uiw/codemirror-theme-vscode": "^4.19.11",
"axios": "^0.27.0",
"codemirror": "^6.0.1",
"core-js": "^3.16.0",
Expand Down
9 changes: 5 additions & 4 deletions src/components/inputs/Codemirror.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import BaseMixin from '../mixins/base'
import { basicSetup } from 'codemirror'
import { EditorView, keymap } from '@codemirror/view'
import { EditorState } from '@codemirror/state'
import { mainsailTheme } from '@/plugins/codemirrorTheme'
import { vscodeDark } from '@uiw/codemirror-theme-vscode'
import { StreamLanguage } from '@codemirror/language'
import { klipper_config } from '@/plugins/StreamParserKlipperConfig'
import { gcode } from '@/plugins/StreamParserGcode'
Expand Down Expand Up @@ -82,9 +82,10 @@ export default class Codemirror extends Mixins(BaseMixin) {
get cmExtensions() {
const extensions = [
EditorView.theme({}, { dark: true }),
basicSetup,
mainsailTheme,
indentUnit.of(' '.repeat(this.getTabSize())),
vscodeDark,
indentUnit.of(' '.repeat(this.tabSize)),
keymap.of([indentWithTab]),
EditorView.updateListener.of((update) => {
this.content = update.state?.doc.toString()
Expand All @@ -106,7 +107,7 @@ export default class Codemirror extends Mixins(BaseMixin) {
if (isVisible) this.cminstance?.focus()
}
getTabSize() {
get tabSize() {
return this.$store.state.gui.editor.tabSize || 2
}
}
Expand Down
18 changes: 13 additions & 5 deletions src/plugins/StreamParserGcode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,19 @@ export const gcode = {
/* Klipper macro attributes */
if (stream.pos > zeroPos && state.klipperMacro) {
stream.eatSpace()
if (stream.match(/^(".+"|true|false)/i)) {
if (stream.match(/^{/)) {
return 'tag'
}
// else if (stream.match(/^'|"/)) {
else if (stream.match(/^"[^{]+"/) || stream.match(/^'[^{]+'/)) {
return 'string'
} else if (stream.match(/^\d+/)) return 'number'
else if (stream.match(/^[A-Za-z\d_]+/)) return 'propertyName'
else if (zeroPos === 0 && stream.match(/^{[^%]+}/)) return 'variable'
} else if (stream.match(/^[-+]?[0-9]*\.?[0-9]+/)) {
return 'number'
} else if (stream.match(/^[A-Za-z\d_]+/)) {
return 'propertyName'
} else if (zeroPos === 0 && stream.match(/^{[^%]+}/)) {
return 'variable'
}
}

/* comments */
Expand All @@ -29,7 +37,7 @@ export const gcode = {
return 'namespace'
}

if (stream.string.substr(zeroPos).toLowerCase().startsWith('m117')) {
if (stream.string.substring(zeroPos).toLowerCase().startsWith('m117')) {
stream.skipToEnd()
return 'string'
}
Expand Down
144 changes: 0 additions & 144 deletions src/plugins/StreamParserJinja2.ts

This file was deleted.

Loading

0 comments on commit 080a713

Please sign in to comment.