diff --git a/lib/debugger/breakpoints.js b/lib/debugger/breakpoints.js index 5474d292..a2036b3f 100644 --- a/lib/debugger/breakpoints.js +++ b/lib/debugger/breakpoints.js @@ -2,7 +2,7 @@ /** @jsx etch.dom */ import {CompositeDisposable, Emitter} from 'atom' -import { showBasicModal } from '../util/basic-modal' +import showBasicModal from '../util/basic-modal' import {Etch} from '../util/etch' import etch from 'etch' @@ -266,12 +266,16 @@ export default class BreakpointManager { if (bp.file !== file || bp.line !== line) return showBasicModal([{ name: 'Condition', - value: bp.condition + defaultText: bp.condition, + message: `Enter the condition when this breakpoint applies (previous: \`${bp.condition}\`).`, }]).then(items => { const condition = items['Condition'] this.addCondition(bp, condition) this.emitter.emit('update') activePane.activate() // Re-activate previously active pane + }).catch((err) => { + if (err) console.error(err); + return }) found = true }) @@ -279,7 +283,8 @@ export default class BreakpointManager { if (!found) { showBasicModal([{ name: 'Condition', - value: '', + defaultText: '', + message: `Enter the condition when this breakpoint applies.`, }]).then(items => { const condition = items['Condition'] this.add({ @@ -291,6 +296,8 @@ export default class BreakpointManager { }) this.emitter.emit('update') activePane.activate() // Re-activate previously active pane + }).catch((err) => { + if (err) console.error(err); }) } } diff --git a/lib/debugger/debugger-pane.js b/lib/debugger/debugger-pane.js index 67f36946..5c5e9605 100644 --- a/lib/debugger/debugger-pane.js +++ b/lib/debugger/debugger-pane.js @@ -3,7 +3,7 @@ import etch from 'etch' import { toView, Toolbar, Tip, Button, Icon, makeicon, Etch, Raw } from '../util/etch' -import { showBasicModal } from '../util/basic-modal' +import showBasicModal from '../util/basic-modal' import { CompositeDisposable, TextEditor } from 'atom' import PaneItem from '../util/pane-item' import { open } from '../util/opener' @@ -360,12 +360,13 @@ export default class DebuggerPane extends PaneItem { addCondition (bp) { showBasicModal([{ name: "Condition", - value: bp.condition + defaultText: bp.condition, + message: `Enter the condition when this breakpoint applies (previous: \`${bp.condition}\`).`, }]).then(items => { const cond = items["Condition"] this.breakpointManager.addCondition(bp, cond) }).catch((err) => { - console.error(err); + if (err) console.error(err); }) } diff --git a/lib/ink.coffee b/lib/ink.coffee index 7da61fac..63a1474d 100644 --- a/lib/ink.coffee +++ b/lib/ink.coffee @@ -40,6 +40,7 @@ exportables = Opener: once(=> require('./util/opener')) matchHighlighter: once(=> require './util/matchHighlighter') ansiToHTML: once(=> require './util/ansitohtml') + showBasicModal: once(=> require './util/basic-modal') module.exports = Ink = activate: -> diff --git a/lib/plots/canopy.js b/lib/plots/canopy.js index 0e0353cb..d1d0ed22 100644 --- a/lib/plots/canopy.js +++ b/lib/plots/canopy.js @@ -3,7 +3,7 @@ import etch from 'etch'; import { prewalk, postwalk, prefor } from './tree.js'; -import { Etch, Tip, Button, toView } from '../util/etch.js'; +import { Etch, Button, toView } from '../util/etch.js'; function clamp (x, min, max) { return Math.min(Math.max(x, min), max) @@ -26,12 +26,12 @@ function dims(tree) { left += ch.width; }); // Centre align children - chwidth = parent.children.map(({width})=>width).reduce((a,b)=>a+b, 0); + const chwidth = parent.children.map(({width})=>width).reduce((a,b)=>a+b, 0); parent.children.forEach(ch => ch.left += (parent.width-chwidth)/2); return parent; }); // Scale total height to 100% - let max = postwalk(tree, ({height, children}) => + const max = postwalk(tree, ({height, children}) => Math.max(height, ...children.map(x=>x+height))); prewalk(tree, (node) => { node.top /= max; @@ -172,7 +172,7 @@ export class Pannable extends Etch { this.toolbar = this.toolbar.concat(this.item.toolbar) } - let style = {position:'relative', height:'inherit', width:'inherit', transformOrigin: '0px 0px'} + const style = { position:'relative', height:'inherit', width:'inherit', transformOrigin: '0px 0px' } if (this.zoomstrategy == 'width') { style.transform = 'translate('+this.left+'px,'+this.top+'px)' diff --git a/lib/util/basic-modal.js b/lib/util/basic-modal.js index 825b9cfa..b64a9f80 100644 --- a/lib/util/basic-modal.js +++ b/lib/util/basic-modal.js @@ -5,21 +5,21 @@ import etch from 'etch' import { toView, Toolbar, Button, Icon, makeicon, Etch, Raw } from './etch' import { TextEditor, CompositeDisposable } from 'atom' -export function showBasicModal(queries) { +export default function showBasicModal(queries) { return new Promise((resolve, reject) => { - subs = new CompositeDisposable() + const subs = new CompositeDisposable() - _resolve = (...args) => { + const _resolve = (...args) => { panel.destroy() subs.dispose() resolve(...args) } - _reject = (...args) => { + const _reject = (...args) => { panel.destroy() subs.dispose() reject(...args) } - let view = new BasicModalView(queries, _resolve, _reject) + const view = new BasicModalView(queries, _resolve, _reject) subs.add(atom.commands.add('.basic-modal .editor', { 'basic-modal:confirm': () => view.confirm() @@ -27,7 +27,7 @@ export function showBasicModal(queries) { subs.add(atom.commands.add('.basic-modal .editor', { 'basic-modal:cancel': () => view.cancel() })) - let panel = atom.workspace.addModalPanel({ + const panel = atom.workspace.addModalPanel({ item: view, autoFocus: true }) @@ -44,24 +44,24 @@ class BasicModalView { this.reject = reject this.models = {} this.queries = queries - for (let query of this.queries) { + this.queries.forEach(query => { this.models[query.name] = new TextEditor({ mini: true, placeholderText: query.placeholder || '' }) - if (query.value) { - this.models[query.name].setText(query.value) + if (query.defaultText) { + this.models[query.name].setText(query.defaultText) } - } + }) etch.initialize(this) } confirm () { - let ret = {} - for (let query of this.queries) { + const ret = {} + this.queries.forEach(query => { ret[query.name] = this.models[query.name].getText() - } + }) this.resolve(ret) } @@ -72,34 +72,35 @@ class BasicModalView { update () {} render () { - let queryViews = this.queries.map(query => { + const queryViews = this.queries.map(query => { return
{query.name || ''}
{toView(this.models[query.name].element)} + {query.message || ''}
}) return
- {queryViews} -
-
- -
-
- -
-
-
+ {queryViews} +
+
+ +
+
+ +
+
+ } } diff --git a/lib/util/etch.js b/lib/util/etch.js index 4597d2c6..f4297b69 100644 --- a/lib/util/etch.js +++ b/lib/util/etch.js @@ -108,7 +108,6 @@ export class Tip { this.tooltip = atom.tooltips.add(this.element, {title: () => this.text}); } - this.text = alt; this.child = child; etch.update(this, false);