Skip to content
This repository has been archived by the owner on Jan 3, 2023. It is now read-only.

Commit

Permalink
Preview isnt required to update for restored imgs
Browse files Browse the repository at this point in the history
Restored images may be either images that we're previously renamed or
previously deleted. To force a restored image to preview a rerender
through either a preview toggle or source edit is required.

Note that on windows pathwatcher does still watch files even after their
their path no longer exists, updating the preview even for restored
images withour a forced rerender, but on OSX it does not.
  • Loading branch information
Galadirith committed Aug 9, 2015
1 parent 24f017b commit db6a522
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions lib/renderer.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ srcClosure = (src) ->
if event is 'change' and fs.isFileSync(src)
imgVersion[src] = Date.now()
else
imgVersion[src] = 'deleted'
imgVersion[src] = null
renderPreviews()
return

Expand All @@ -128,7 +128,7 @@ resolveImagePaths = (html, filePath) ->

# Use most recent version of image

if not imgVersion[src] > 0 and fs.isFileSync(src)
if not imgVersion[src] and fs.isFileSync(src)
imgVersion[src] = Date.now()
pathWatcher.watch src, srcClosure(src)

Expand Down
20 changes: 10 additions & 10 deletions spec/markdown-preview-view-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -320,8 +320,8 @@ describe "MarkdownPreviewView", ->
expect(newImg3Ver).not.toEqual('deleted')
expect(parseInt(newImg3Ver)).toBeGreaterThan(parseInt(img3Ver))

describe "when an image is previewed, deleted then restored", ->
it "sets the query value to a timestamp, deleted and finally a more recent timestamp", ->
describe "when a previewed image is deleted then restored", ->
it "removes the query timestamp and restores the timestamp after a rerender", ->
[imageURL, imageVer] = []

waitsForPromise -> atom.workspace.open(filePath)
Expand All @@ -340,20 +340,20 @@ describe "MarkdownPreviewView", ->
not imageURL.endsWith imageVer

runs ->
expect(getImageVersion(img1Path, imageURL)).toBe 'deleted'

expect(imageURL).toBe img1Path
fs.writeFileSync img1Path, "clearly not a png but good enough for tests"
preview.renderMarkdown()

waitsFor "image src attribute to update", ->
imageURL = preview.find("img[alt=img1]").attr('src')
not imageURL.endsWith 'deleted'
imageURL isnt img1Path

runs ->
newImageVer = getImageVersion(img1Path, imageURL)
expect(parseInt(newImageVer)).toBeGreaterThan(parseInt(imageVer))

describe "when an image is previewed, renamed and then restored with original name", ->
it "sets the query value to a timestamp, deleted and finally a more recent timestamp", ->
describe "when a previewed image is renamed and then restored with its original name", ->
it "removes the query timestamp and restores the timestamp after a rerender", ->
[imageURL, imageVer] = []

waitsForPromise -> atom.workspace.open(filePath)
Expand All @@ -372,13 +372,13 @@ describe "MarkdownPreviewView", ->
not imageURL.endsWith imageVer

runs ->
expect(getImageVersion(img1Path, imageURL)).toBe 'deleted'

expect(imageURL).toBe img1Path
fs.renameSync img1Path + "trol", img1Path
preview.renderMarkdown()

waitsFor "image src attribute to update", ->
imageURL = preview.find("img[alt=img1]").attr('src')
not imageURL.endsWith 'deleted'
imageURL isnt img1Path

runs ->
newImageVer = getImageVersion(img1Path, imageURL)
Expand Down

0 comments on commit db6a522

Please sign in to comment.