Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.

Subscribe to file path if the editor is gone - #375

Merged
nathansobo merged 11 commits into
masterfrom
wl-split-pane
Sep 9, 2016
Merged

nathansobo merged 11 commits into
masterfrom
wl-split-pane

Conversation

@winstliu

Copy link
Copy Markdown
Contributor

Even if the editor that the preview tab was tracking has been destroyed, we can still display the rendered markdown by checking its file contents. Do that instead of instantly destroying the newly-created pane when attempting to split an orphaned preview pane.

While this PR substantially increases the capabilities of Markdown Preview when previewing a file no longer open in Atom, it does not do the following:

  • Track when a file is deleted and update the preview accordingly to show an error message
  • Go back to using editorId if the original file is re-opened in Atom
  • (and probably more, though I can't remember anything else right now)

Closes atom/atom#8652

Even if the editor that the preview tab was tracking has been destroyed,
we can still display the rendered markdown by checking its file
contents.  Do that instead of instantly destroying the pane.

Closes atom/atom#86582
subscribeToFilePath is a bit misleading here...it doesn't actually
subscribe to the file path changing in any way.  Now we subscribe to the
rename event and fire did-change-title so that the Markdown Preview
titles get updated properly.
@winstliu

Copy link
Copy Markdown
Contributor Author

This is ready for review.

Comment thread lib/markdown-preview-view.coffee Outdated
renderMarkdown: ->
@showLoading() unless @loaded
@getMarkdownSource().then (source) => @renderMarkdownText(source) if source?
.catch (reason) =>

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without this catch the preview pane would endlessly display as loading despite the promise already having been rejected (eg when the file has been deleted).

@winstliu

Copy link
Copy Markdown
Contributor Author

The @file.onDidRename method seems a bit flaky. The file was definitely renamed (as seen in the second failing spec), but it looks like the did-change-title event was not fired. In addition I'm not sure why atom.workspace.getActivePaneItem().getPath() is returning the old path. Going to assume that the "Pane has been destroyed" error only occurs when this flakiness happens, as I haven't had any troubles yet while testing locally.

@winstliu winstliu mentioned this pull request Feb 25, 2016
file.writeSync doesn't appear to trigger file.onDidChange
(atom/node-pathwatcher#110)
@winstliu

Copy link
Copy Markdown
Contributor Author

Ok, specs are finally passing.

@nathansobo

Copy link
Copy Markdown
Contributor

Sorry for missing this @50Wliu. I didn't comb over every square inch but the tests look thorough and everything seems reasonable. I trust you to be around to address any issues that might arise. 🚢

@nathansobo
nathansobo merged commit 66b7f18 into master Sep 9, 2016
@nathansobo
nathansobo deleted the wl-split-pane branch September 9, 2016 22:00
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants