update codemirror + added position args
This commit is contained in:
parent
6b883721bd
commit
206a6362b1
|
@ -1,8 +1,8 @@
|
|||
#!/bin/sh
|
||||
test -n "$1" || { echo "usage: codemirror <file>"; exit 0; }
|
||||
test -n "$1" || { echo "usage: codemirror <file> <x> <y> <z>"; exit 0; }
|
||||
|
||||
me="$(dirname $(readlink -f $0))"
|
||||
file="$(readlink -f "$1")"
|
||||
|
||||
$me/codemirror.js "$file"
|
||||
$me/codemirror.js "$file" $2 $3 $4
|
||||
echo "press ctrl-Q to exit editor"
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#!/bin/js
|
||||
|
||||
if( args[1] == undefined ) return "usage: codemirror <file>"
|
||||
let keymap = "default" // "vim"
|
||||
|
||||
if( AFRAME.components.codemirror ) delete AFRAME.components.codemirror
|
||||
AFRAME.registerComponent('codemirror', {
|
||||
|
@ -9,6 +9,7 @@ AFRAME.registerComponent('codemirror', {
|
|||
term: { type:"selector", default: "[isoterminal]" },
|
||||
width: { type:"number", default:700},
|
||||
height: { type:"number", default:500},
|
||||
keymap: { type:"string", default:"default"}
|
||||
},
|
||||
|
||||
init: function () {
|
||||
|
@ -67,7 +68,7 @@ AFRAME.registerComponent('codemirror', {
|
|||
},
|
||||
|
||||
createEditor: function(value){
|
||||
this.el.setAttribute("window", `title: codemirror; uid: ${this.el.dom.id}; attach: #overlay; dom: #${this.el.dom.id}; width: ${this.data.width}px; height: ${this.data.height}px; class: no-full, no-resize`)
|
||||
this.el.setAttribute("window", `title: codemirror; uid: ${this.el.dom.id}; attach: #overlay; dom: #${this.el.dom.id}; width: ${this.data.width}px; height: ${this.data.height}px; class: no-full, no-max, no-resize`)
|
||||
this.editor = CodeMirror( this.el.dom, {
|
||||
value,
|
||||
mode: this.data.file.match(/\.js$/) ? "text/javascript" :
|
||||
|
@ -80,6 +81,7 @@ AFRAME.registerComponent('codemirror', {
|
|||
lineNumbers: true,
|
||||
styleActiveLine: true,
|
||||
matchBrackets: true,
|
||||
keyMap: this.data.keymap,
|
||||
Tab: "indentMore",
|
||||
defaultTab: function(cm) {
|
||||
if (cm.somethingSelected()) cm.indentSelection("add");
|
||||
|
@ -92,15 +94,17 @@ AFRAME.registerComponent('codemirror', {
|
|||
this.el.emit('close',true) // window.js will react accordingly
|
||||
}
|
||||
})
|
||||
this.editor.updateFile = AFRAME.utils.throttle( (file,str) => {
|
||||
this.editor.updateFile = (file,str) => {
|
||||
clearTimeout( this.editor.updateFile.tid)
|
||||
setTimeout( (file,str) => {
|
||||
this.updateFile(file,str)
|
||||
}, 1500)
|
||||
},500, file,str)
|
||||
}
|
||||
this.editor.on('change', (instance,changeObj) => {
|
||||
this.editor.updateFile( this.data.file, instance.getValue() )
|
||||
})
|
||||
|
||||
this
|
||||
.handleFocus()
|
||||
this.handleFocus()
|
||||
|
||||
setTimeout( () => {
|
||||
this.el.setAttribute("html-as-texture-in-xr", `domid: #${this.el.dom.id}`) // only show aframe-html in xr
|
||||
|
@ -209,22 +213,28 @@ AFRAME.utils.require({
|
|||
codemirrorcss: "https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.35.0/codemirror.css",
|
||||
cmtheme: "https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.35.0/theme/shadowfox.css"
|
||||
})
|
||||
.then( () => AFRAME.utils.require({
|
||||
.then( () => {
|
||||
|
||||
let extras = {
|
||||
cmxml: "https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.35.0/mode/xml/xml.js",
|
||||
cmjavascript: "https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.35.0/mode/javascript/javascript.js",
|
||||
cmcss: "https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.35.0/mode/css/css.js",
|
||||
cmlua: "https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.35.0/mode/lua/lua.js",
|
||||
cmpython: "https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.35.0/mode/python/python.js",
|
||||
cmmarkdown: "https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.35.0/mode/markdown/markdown.js",
|
||||
highlight: "https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.35.0/mode/htmlmixed/htmlmixed.js",
|
||||
highlight: "https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.35.0/mode/htmlmixed/htmlmixed.js"
|
||||
}
|
||||
if( keymap == "vim" ) extras.cmvim = "https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.35.0/keymap/vim.js";
|
||||
return AFRAME.utils.require(extras)
|
||||
})
|
||||
)
|
||||
.then( () => {
|
||||
let el = document.createElement("a-entity")
|
||||
el.setAttribute("codemirror", `file: ${args[1]}`)
|
||||
if( args.length == 5 ){
|
||||
el.setAttribute("position",`${args[2]} ${args[3]} ${args[4]}`)
|
||||
}
|
||||
document.querySelector("a-scene").appendChild(el)
|
||||
})
|
||||
|
||||
return "" // empty stdout(put)
|
||||
|
||||
// for shellscript-equivalent see bin/codemirror
|
||||
return "" // empty stdout(put)
|
||||
|
|
Loading…
Reference in New Issue