From f5e9e0ee4b99eae94677bf63723ee531f0ce203e Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Thu, 11 Jun 2020 23:44:49 -0500 Subject: [PATCH] views.activate --- lib/ui.coffee | 2 +- lib/ui/views.js | 19 +++++++++++-------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/lib/ui.coffee b/lib/ui.coffee index caf613e8..27b3ebea 100644 --- a/lib/ui.coffee +++ b/lib/ui.coffee @@ -31,7 +31,7 @@ module.exports = @subs.dispose() consumeInk: (@ink) -> - @views.ink = @ink + @views.activate(@ink) @selector.activate(@ink) @docpane.activate(@ink) @progress.activate(@ink) diff --git a/lib/ui/views.js b/lib/ui/views.js index b8c3657f..3268ee7b 100644 --- a/lib/ui/views.js +++ b/lib/ui/views.js @@ -5,7 +5,10 @@ import { once } from '../misc'; const getlazy = client.import('getlazy'); -// TODO this.ink is not imported! +let ink; +export function activate (ink_in) { + ink = ink_in +} export function dom({tag, attrs, contents}, opts) { const view = document.createElement(tag); @@ -38,7 +41,7 @@ export function html(...args) { } export function tree({head, children, expand}, opts) { - this.ink.tree.treeView(render(head, opts), + ink.tree.treeView(render(head, opts), children.map(x=> render(tags.div([x]), opts)), {expand}); } @@ -51,13 +54,13 @@ export function lazy({head, id}, opts) { console.warn('Unregistered lazy view'); } let view; - return view = this.ink.tree.treeView(render(head, opts), [], { + return view = ink.tree.treeView(render(head, opts), [], { onToggle: once(() => { if (client.conn !== conn) { return; } getlazy(id).then(children => { const body = view.querySelector(':scope > .body'); children.map(x => render(tags.div([x]), opts)).forEach(x => { - body.appendChild(this.ink.ansiToHTML(x)); + body.appendChild(ink.ansiToHTML(x)); }); }); }) @@ -93,13 +96,13 @@ export function link({file, line, contents}) { // TODO: maybe need to dispose of the tooltip onclick and readd them, but // that doesn't seem to be necessary let tt; - if (this.ink.Opener.isUntitled(file)) { + if (ink.Opener.isUntitled(file)) { tt = atom.tooltips.add(view, {title() { return 'untitled'; }}); } else { tt = atom.tooltips.add(view, {title() { return file; }}); } view.onclick = e => { - this.ink.Opener.open(file, line, { + ink.Opener.open(file, line, { pending: atom.config.get('core.allowPendingPaneItems') }); e.stopPropagation(); @@ -132,7 +135,7 @@ export function code({text, attrs, scope}) { export function latex({attrs, text}) { const block = (attrs != null ? attrs.block : undefined) || false; // attrs?.block || false - const latex = this.ink.KaTeX.texify(text, block); + const latex = ink.KaTeX.texify(text, block); return render({type: 'html', block, content: latex}); } @@ -153,7 +156,7 @@ export const views = { export function render(data, opts = {}) { if (views.hasOwnProperty(data.type)) { const r = views[data.type](data, opts); - this.ink.ansiToHTML(r); + ink.ansiToHTML(r); return r; } else if ((data != null ? data.constructor : undefined) === String) { // data?.constructor === String return new Text(data);