Added indenter, fixes #34
This commit is contained in:
parent
c179fbce7e
commit
557750c3f8
@ -40,6 +40,7 @@
|
||||
ronin.controller.addRole('default', 'Edit', 'paste')
|
||||
ronin.controller.addRole('default', 'Edit', 'delete')
|
||||
ronin.controller.addRole('default', 'Edit', 'selectall')
|
||||
ronin.controller.add("default","Edit","Re-Indent",() => { ronin.commander.reindent() },"CmdOrCtrl+Shift+I")
|
||||
ronin.controller.add("default","View","Zoom In",() => { ronin.modZoom(0.25) },"CmdOrCtrl+=")
|
||||
ronin.controller.add("default","View","Zoom Out",() => { ronin.modZoom(-0.25) },"CmdOrCtrl+-")
|
||||
ronin.controller.add("default","View","Zoom Reset",() => { ronin.modZoom(1,true) },"CmdOrCtrl+0")
|
||||
|
@ -13,4 +13,4 @@ body { margin:0px; padding:0px; overflow:hidden; font-family:"input_mono_regular
|
||||
#ronin canvas#guide { background:none; }
|
||||
#ronin canvas#surface { border-radius: 2px }
|
||||
|
||||
#ronin.hidden canvas#surface, #ronin.hidden canvas#guide { left:0px; }
|
||||
#ronin.hidden canvas#surface, #ronin.hidden canvas#guide { left:10px; }
|
@ -33,6 +33,26 @@ function Commander (ronin) {
|
||||
this.run()
|
||||
}
|
||||
|
||||
this.reindent = function () {
|
||||
let val = this._input.value.replace(/\n/g, '').replace(/\( \(/g, '((').replace(/\) \)/g, '))').replace(/ {2}/g, ' ').trim()
|
||||
let depth = 0
|
||||
for (let i = 0; i < val.length; i++) {
|
||||
const c = val.charAt(i)
|
||||
if (c === '(') { depth++ } else if (c === ')') { depth-- }
|
||||
if (c === ';') {
|
||||
const indent = '\n' + (' '.repeat(depth))
|
||||
val = val.insert(indent, i)
|
||||
i += indent.length
|
||||
}
|
||||
if (c === '(') {
|
||||
const indent = '\n' + (' '.repeat(depth - 1))
|
||||
val = val.insert(indent, i)
|
||||
i += indent.length
|
||||
}
|
||||
}
|
||||
this._input.value = val.trim()
|
||||
}
|
||||
|
||||
this.setStatus = function (msg) {
|
||||
if (!msg) { return }
|
||||
this._status.textContent = `${(msg + '').substr(0, 40)}`
|
||||
@ -196,4 +216,6 @@ function Commander (ronin) {
|
||||
}, '')
|
||||
}
|
||||
}
|
||||
|
||||
String.prototype.insert = function (s, i) { return [this.slice(0, i), `${s}`, this.slice(i)].join('') }
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user