editor in class

This commit is contained in:
ojack
2022-01-10 11:12:19 +01:00
parent 006626f1c6
commit f7a085a85e
7 changed files with 405 additions and 401 deletions

View File

@@ -76,13 +76,13 @@ function init () {
})
menu.sketches = sketches
keymaps.init ({
editor: editor,
gallery: sketches,
menu: menu,
repl: repl,
log: log
})
// keymaps.init ({
// editor: editor,
// gallery: sketches,
// menu: menu,
// repl: repl,
// log: log
// })
// define extra functions (eventually should be added to hydra-synth?)

File diff suppressed because one or more lines are too long

View File

@@ -6,12 +6,15 @@ require('codemirror-minified/addon/hint/show-hint')
require('codemirror-minified/addon/selection/mark-selection')
require('codemirror-minified/addon/comment/comment')
const EventEmitter = require('events')
var Mutator = require('../randomizer/Mutator.js');
var isShowing = true
var EditorClass = function () {
module.exports = class Editor {
constructor() {
console.log("*** Editor class created");
var self = this
@@ -29,40 +32,38 @@ var EditorClass = function () {
lineWrapping: true,
styleSelectedText: true
})
// console.log('code mirror', this.cm)
//this.cm.removeKeyMap()
this.cm.refresh()
this.show()
// TO DO: add show code param
// // TO DO: add show code param
let searchParams = new URLSearchParams(window.location.search)
let showCode = searchParams.get('show-code')
if(showCode == "false") {
if (showCode === "false") {
// console.log("not showing code")
var l = document.getElementsByClassName('CodeMirror-scroll')[0]
l.style.display = 'none'
// self.logElement.style.display = 'none'
isShowing = false
}
//}
}
EditorClass.prototype.clear = function () {
clear() {
this.cm.setValue('\n \n // Type some code on a new line (such as "osc().out()"), and press CTRL+shift+enter')
}
EditorClass.prototype.setValue = function (val) {
setValue(val) {
this.cm.setValue(val)
}
EditorClass.prototype.getValue = function () {
getValue() {
return this.cm.getValue()
}
EditorClass.prototype.hide = function () {
hide() {
var l = document.getElementsByClassName('CodeMirror-scroll')[0]
var m = document.getElementById('modal-header')
// l.style.opacity = 0
@@ -73,7 +74,7 @@ m.style.display = 'none'
this.isShowing = false
}
EditorClass.prototype.show = function () {
show() {
var l = document.getElementsByClassName('CodeMirror-scroll')[0]
var m = document.getElementById('modal-header')
// l.style.opacity= 1
@@ -84,7 +85,7 @@ EditorClass.prototype.show = function () {
this.isShowing = true
}
EditorClass.prototype.toggle = function () {
toggle() {
if (this.isShowing) {
this.hide()
} else {
@@ -92,7 +93,7 @@ EditorClass.prototype.toggle = function () {
}
}
EditorClass.prototype.getLine = function () {
getLine() {
var c = this.cm.getCursor()
var s = this.cm.getLine(c.line)
// this.cm.markText({line: c.line, ch:0}, {line: c.line+1, ch:0}, {className: 'styled-background'})
@@ -100,7 +101,7 @@ EditorClass.prototype.getLine = function () {
return s
}
EditorClass.prototype.flashCode = function (start, end) {
flashCode(start, end) {
if (!start) start = { line: this.cm.firstLine(), ch: 0 }
if (!end) end = { line: this.cm.lastLine() + 1, ch: 0 }
var marker = this.cm.markText(start, end, { className: 'styled-background' })
@@ -108,7 +109,7 @@ EditorClass.prototype.flashCode = function (start, end) {
}
EditorClass.prototype.getCurrentBlock = function () { // thanks to graham wakefield + gibber
getCurrentBlock() { // thanks to graham wakefield + gibber
var editor = this.cm
var pos = editor.getCursor()
var startline = pos.line
@@ -138,6 +139,5 @@ EditorClass.prototype.getCurrentBlock = function () { // thanks to graham wakefi
}
}
}
module.exports = EditorClass

View File

@@ -1,4 +1,4 @@
const log = require('./log.js').log
const log = require('./editor/log.js').log
module.exports = {
eval: (arg, callback) => {

5
package-lock.json generated
View File

@@ -43,6 +43,11 @@
"resolved": "https://registry.npmjs.org/dct/-/dct-0.1.0.tgz",
"integrity": "sha512-/uUtEniuMq1aUxvLAoDtAduyl12oM1zhA/le2f83UFN/9+4KDHXFB6znEfoj5SDDLiTpUTr26NpxC7t8IFOYhQ=="
},
"events": {
"version": "3.3.0",
"resolved": "https://registry.npmjs.org/events/-/events-3.3.0.tgz",
"integrity": "sha512-mQw+2fkQbALzQ7V0MY0IqdnXNOeTtP4r0lN9z7AAawCXgqea7bDii20AYrIBrFd/Hx0M2Ocz6S111CaFkUcb0Q=="
},
"fftjs": {
"version": "0.0.4",
"resolved": "https://registry.npmjs.org/fftjs/-/fftjs-0.0.4.tgz",

View File

@@ -20,6 +20,7 @@
"packages/*"
],
"dependencies": {
"events": "^3.3.0",
"hydra-synth": "^1.3.11"
},
"devDependencies": {}

View File

@@ -1128,7 +1128,7 @@ events@^1.0.2:
resolved "https://registry.yarnpkg.com/events/-/events-1.1.1.tgz#9ebdb7635ad099c70dcc4c2a1f5004288e8bd924"
integrity sha1-nr23Y1rQmccNzEwqH1AEKI6L2SQ=
events@^3.0.0:
events@^3.0.0, events@^3.3.0:
version "3.3.0"
resolved "https://registry.yarnpkg.com/events/-/events-3.3.0.tgz#31a95ad0a924e2d2c419a813aeb2c4e878ea7400"
integrity sha512-mQw+2fkQbALzQ7V0MY0IqdnXNOeTtP4r0lN9z7AAawCXgqea7bDii20AYrIBrFd/Hx0M2Ocz6S111CaFkUcb0Q==