From 297975b07b494b6fdc7f1dddacc1c063a4cda2f5 Mon Sep 17 00:00:00 2001 From: Sebastian Pfitzner Date: Fri, 23 Nov 2018 12:44:44 +0100 Subject: [PATCH 1/4] allow opening remote files --- lib/ink.coffee | 3 +++ lib/util/opener.js | 23 +++++++++++++++++++---- package.json | 5 +++++ 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/lib/ink.coffee b/lib/ink.coffee index 5c71ad59..8759d6c6 100644 --- a/lib/ink.coffee +++ b/lib/ink.coffee @@ -54,6 +54,9 @@ module.exports = Ink = consumeStatusBar: (bar) -> exportables.progress().consumeStatusBar bar + consumeRemoteFileOpener: (opener) -> + exportables.Opener().consumeRemoteFileOpener(opener) + provide: -> obj = util: diff --git a/lib/util/opener.js b/lib/util/opener.js index 3c5f5a2b..27fd39b7 100644 --- a/lib/util/opener.js +++ b/lib/util/opener.js @@ -2,12 +2,23 @@ import {focusEditorPane} from './pane-item' import {existsSync} from 'fs' -export function open (pathOrId, line, {pending = false, existingOnly = true} = {}) { +let remoteFileOpener = undefined + +export function open (pathOrId, line, {pending = false, existingOnly = true, remote = false} = {}) { focusEditorPane() let id = getUntitledId(pathOrId) - return id ? openEditorById(id, line) : - (!existingOnly || existsSync(pathOrId)) ? - atom.workspace.open(pathOrId, {initialLine: line, searchAllPanes: true, pending}) : Promise.resolve(false) + + if (id) { + return openEditorById(id, line) + } else if (!existingOnly || existsSync(pathOrId)) { + return atom.workspace.open(pathOrId, {initialLine: line, searchAllPanes: true, pending}) + } else if (remoteFileOpener) { + return new Promise((resolve, reject) => { + resolve(remoteFileOpener(pathOrId)) + }) + } else { + return Promise.resolve(false) + } } export function isUntitled(pathOrId) { @@ -19,6 +30,10 @@ export function getUntitledId (file) { return id != null ? id[1] : false } +export function consumeRemoteFileOpener (o) { + remoteFileOpener = o +} + function openEditorById (id, line) { return new Promise((resolve) => { for (const pane of atom.workspace.getPanes()) { diff --git a/package.json b/package.json index 0fa8a681..926b1908 100644 --- a/package.json +++ b/package.json @@ -37,6 +37,11 @@ "versions": { "^1.0.0": "consumeStatusBar" } + }, + "ftp-remote.openFile": { + "versions": { + "0.1.0": "consumeRemoteFileOpener" + } } } } From bada22ceab3a486a5b38beb430b9970b554838e1 Mon Sep 17 00:00:00 2001 From: Sebastian Pfitzner Date: Sun, 25 Nov 2018 11:12:17 +0100 Subject: [PATCH 2/4] better remote file handling --- lib/util/opener.js | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/lib/util/opener.js b/lib/util/opener.js index 27fd39b7..5054adc0 100644 --- a/lib/util/opener.js +++ b/lib/util/opener.js @@ -3,6 +3,7 @@ import {focusEditorPane} from './pane-item' import {existsSync} from 'fs' let remoteFileOpener = undefined +let allowremote = false export function open (pathOrId, line, {pending = false, existingOnly = true, remote = false} = {}) { focusEditorPane() @@ -10,12 +11,23 @@ export function open (pathOrId, line, {pending = false, existingOnly = true, rem if (id) { return openEditorById(id, line) - } else if (!existingOnly || existsSync(pathOrId)) { - return atom.workspace.open(pathOrId, {initialLine: line, searchAllPanes: true, pending}) - } else if (remoteFileOpener) { + } else if (allowremote && remoteFileOpener) { return new Promise((resolve, reject) => { - resolve(remoteFileOpener(pathOrId)) + let disposable = atom.workspace.observeActiveTextEditor(ed => { + if (ed && ed.getPath().indexOf(pathOrId) > -1) { + ed.setCursorBufferPosition([line, 0]) + if (disposable) disposable.dispose() + } + }) + if (remoteFileOpener(pathOrId)) { + resolve(true) + } else { + resolve(false) + if (disposable) disposable.dispose() + } }) + } else if (!existingOnly || existsSync(pathOrId)) { + return atom.workspace.open(pathOrId, {initialLine: line, searchAllPanes: true, pending}) } else { return Promise.resolve(false) } @@ -34,6 +46,10 @@ export function consumeRemoteFileOpener (o) { remoteFileOpener = o } +export function allowRemoteFiles (val) { + allowremote = val +} + function openEditorById (id, line) { return new Promise((resolve) => { for (const pane of atom.workspace.getPanes()) { From 0794f811519689ff860f73d4d3c3d2b7eb2e7517 Mon Sep 17 00:00:00 2001 From: Sebastian Pfitzner Date: Tue, 27 Nov 2018 15:45:17 +0100 Subject: [PATCH 3/4] term resize improvements --- lib/console2/console.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/console2/console.js b/lib/console2/console.js index 47675582..642582d5 100644 --- a/lib/console2/console.js +++ b/lib/console2/console.js @@ -198,6 +198,8 @@ export default class InkTerminal extends PaneItem { resize () { let {cols, rows} = this.terminal.proposeGeometry() + // resize twice with different sizes to actually force a resize: + this.terminal.resize(cols - 2, rows) this.terminal.resize(cols - 1, rows) } From ea7d9dcc491e6187d432c0bc38719d3d32922f66 Mon Sep 17 00:00:00 2001 From: Sebastian Pfitzner Date: Thu, 29 Nov 2018 10:14:12 +0100 Subject: [PATCH 4/4] more robust file opening --- lib/util/opener.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/util/opener.js b/lib/util/opener.js index 5054adc0..d896034a 100644 --- a/lib/util/opener.js +++ b/lib/util/opener.js @@ -14,9 +14,15 @@ export function open (pathOrId, line, {pending = false, existingOnly = true, rem } else if (allowremote && remoteFileOpener) { return new Promise((resolve, reject) => { let disposable = atom.workspace.observeActiveTextEditor(ed => { - if (ed && ed.getPath().indexOf(pathOrId) > -1) { - ed.setCursorBufferPosition([line, 0]) - if (disposable) disposable.dispose() + if (ed) { + let ep = ed.getPath() + if (ep) { + ep = ep.replace(/\\/g, '/') + if (ep.indexOf(pathOrId) > -1) { + ed.setCursorBufferPosition([line, 0]) + if (disposable) disposable.dispose() + } + } } }) if (remoteFileOpener(pathOrId)) {