From de586b699b1154451dbed817939b193e4a3cdc07 Mon Sep 17 00:00:00 2001 From: neauoire Date: Sun, 3 Nov 2019 10:08:08 -0500 Subject: [PATCH] Added inline docs --- desktop/sources/scripts/commander.js | 49 +++++++++++++++++++--------- desktop/sources/scripts/library.js | 1 - desktop/sources/scripts/ronin.js | 3 +- desktop/sources/scripts/surface.js | 11 ------- 4 files changed, 35 insertions(+), 29 deletions(-) diff --git a/desktop/sources/scripts/commander.js b/desktop/sources/scripts/commander.js index 6b0d98b..e3bfd78 100644 --- a/desktop/sources/scripts/commander.js +++ b/desktop/sources/scripts/commander.js @@ -73,11 +73,6 @@ function Commander (ronin) { this.setStatus() } - this.getLastfn = function () { - const pos = this._input.value.substr(0, this._input.selectionStart).lastIndexOf('(') - return this._input.value.substr(pos).split(' ')[0].replace(/\(/g, '').replace(/\)/g, '').trim() - } - this.reindent = function () { let val = this._input.value.replace(/\n/g, '').replace(/ \)/g, ')').replace(/ +(?= )/g, '').replace(/\( \(/g, '((').replace(/\) \)/g, '))').trim() let depth = 0 @@ -115,14 +110,7 @@ function Commander (ronin) { if (msg && msg !== this._log.textContent) { this._log.textContent = `${msg}` } - // Docs - // const lstFn = this.getLastfn() - // const rect = ronin.surface.getFrame() - // TODO - // const _docs = this.docs.hasDocs(lstFn) === true ? this.docs.print(lstFn) : `${ronin.source}:${this.length()} ${rect.w}x${rect.h}` - // if (_docs !== this._docs.textContent) { - // this._docs.textContent = `${_docs}` - // } + this._docs.textContent = this.getDocs() } // Injection @@ -224,10 +212,38 @@ function Commander (ronin) { setTimeout(() => { this._run.className = '' }, 150) } + // Docs + + this.getCurrentWord = () => { + const pos = this._input.value.substr(0, this._input.selectionStart).lastIndexOf('(') + return this._input.value.substr(pos).split(' ')[0].replace(/\(/g, '').replace(/\)/g, '').trim() + } + + this.getCurrentFunction = () => { + const word = this.getCurrentWord() + let mostSimilar = '' + for (const id of Object.keys(ronin.library)) { + if (id.substr(0, word.length) === word) { + mostSimilar = id + } + } + return mostSimilar + } + + this.getDocs = (id) => { + const name = this.getCurrentFunction() + const fn = ronin.library[name] + if (!fn) { return } + const fnString = fn.toString() + if (fnString.indexOf(') => {') < 0) { return } + const fnParams = fnString.split(') => {')[0].substr(1).replace(/,/g, '').trim() + return `(${name} ${fnParams})` + } + // Splash - this.splash = `; welcome to ronin -; v2.40 + this.splash = ` +; Ronin v2.40 (clear) (def logo-path "M60,60 L195,60 A45,45 0 0,1 240,105 A45,45 0 0,1 195,150 L60,150 M195,150 A45,45 0 0,1 240,195 L240,240 ") (def pos-x @@ -235,7 +251,8 @@ function Commander (ronin) { (def pos-y (sub frame:m 150)) (stroke - (svg pos-x pos-y logo-path) theme:b_high 5)` + (svg pos-x pos-y logo-path) theme:b_high 5) +` function insert (str, add, i) { return [str.slice(0, i), `${add}`, str.slice(i)].join('') diff --git a/desktop/sources/scripts/library.js b/desktop/sources/scripts/library.js index 44cb5a6..a4e004a 100644 --- a/desktop/sources/scripts/library.js +++ b/desktop/sources/scripts/library.js @@ -4,7 +4,6 @@ function Library (ronin) { // IO - this.import = async (name, shape, alpha = 1) => { // Imports a graphic file with format. const src = ronin.cache.get(name) if (!src) { ronin.log('No data for ' + name); return } diff --git a/desktop/sources/scripts/ronin.js b/desktop/sources/scripts/ronin.js index 993d2c7..4551563 100644 --- a/desktop/sources/scripts/ronin.js +++ b/desktop/sources/scripts/ronin.js @@ -7,6 +7,7 @@ /* global Surface */ /* global Library */ /* global Lisp */ +/* global Image */ /* global requestAnimationFrame */ function Ronin () { @@ -38,7 +39,7 @@ function Ronin () { this.acels.set('File', 'New', 'CmdOrCtrl+N', () => { this.source.new(); this.surface.clear(); this.commander.clear() }) this.acels.set('File', 'Save', 'CmdOrCtrl+S', () => { this.source.save('export.lisp', this.commander._input.value, 'text/plain') }) - this.acels.set('File', 'Export Image', 'CmdOrCtrl+E', () => { this.source.download('export.png', ronin.surface.el.toDataURL('image/png', 1.0), 'image/png') }) + this.acels.set('File', 'Export Image', 'CmdOrCtrl+E', () => { this.source.download('export.png', this.surface.el.toDataURL('image/png', 1.0), 'image/png') }) this.acels.set('File', 'Open', 'CmdOrCtrl+O', () => { this.source.open('lisp', this.whenOpen) }) this.acels.set('File', 'Revert', 'CmdOrCtrl+W', () => { this.source.revert() }) this.acels.set('View', 'Toggle Guides', 'CmdOrCtrl+Shift+H', () => { this.surface.toggleGuides() }) diff --git a/desktop/sources/scripts/surface.js b/desktop/sources/scripts/surface.js index b57db01..7782afb 100644 --- a/desktop/sources/scripts/surface.js +++ b/desktop/sources/scripts/surface.js @@ -244,9 +244,6 @@ function Surface (ronin) { this._guide.height = size.h this._guide.style.width = (size.w / this.ratio) + 'px' this._guide.style.height = (size.h / this.ratio) + 'px' - if (fit === true) { - this.fitWindow(size) - } } this.copy = function (rect) { @@ -292,14 +289,6 @@ function Surface (ronin) { }) } - this.fitWindow = function (size) { - console.log('TODO') - // const win = require('electron').remote.getCurrentWindow() - // const pad = { w: ronin.commander.isVisible === true ? 400 : 60, h: 60 } - // if (size.w < 10 || size.h < 10) { return } - // win.setSize(Math.floor((size.w / this.ratio) + pad.w), Math.floor((size.h / this.ratio) + pad.h), true) - } - this.maximize = () => { this.resize(this.bounds()) }