Skip to content

Commit

Permalink
Accommodate asynchronous editor saving
Browse files Browse the repository at this point in the history
References: #615
  • Loading branch information
Alhadis committed Jun 26, 2017
1 parent a87f55d commit 7e22796
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
4 changes: 2 additions & 2 deletions test/4.5-hashbang.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,8 @@ describe("Interpreter directives", () => {
afterEach(() => open("crystal").then(ed => {
if(editor){
editor.revertToCheckpoint(checkpoint);
editor.save();
atom.commands.dispatch(ed.editorElement, "core:close");
(editor.save() || Promise.resolve()).then(() =>
atom.commands.dispatch(ed.editorElement, "core:close"));
}
}));

Expand Down
21 changes: 11 additions & 10 deletions test/spec-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,16 +131,17 @@ function open(path){
*/
function replaceText(find, replace){
return new Promise(resolve => {
const handler = () => {resolve(); done.dispose()};
const editor = atom.workspace.getActiveTextEditor();
const done = editor.onDidStopChanging(() => {
resolve();
done.dispose();
});
const done = editor.onDidStopChanging(handler);
editor.transact(100, () => {
editor.scan(find, args => args.replace(replace));
});
editor.save();
const saveResult = editor.save();
if(saveResult && saveResult instanceof Promise)
saveResult.then(handler);
})
.then(() => wait(100))
.then(() => TreeView.refreshHack());
}

Expand Down Expand Up @@ -185,14 +186,14 @@ function resolvePath(path){
*/
function revert(steps = 1){
return new Promise(resolve => {
const handler = () => {resolve(); done.dispose()};
const editor = atom.workspace.getActiveTextEditor();
const done = editor.onDidStopChanging(() => {
resolve();
done.dispose();
});
const done = editor.onDidStopChanging(handler);
for(let i = 0; i < steps; ++i)
editor.undo();
editor.save();
const saved = editor.save();
if(saved && saved instanceof Promise)
handler.call();
})
.then(() => TreeView.refreshHack());
}
Expand Down

0 comments on commit 7e22796

Please sign in to comment.