Skip to content

Commit

Permalink
Fix #193: Tab icons not updating when renaming extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
Alhadis committed Apr 14, 2016
1 parent 83237f8 commit 8454a05
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ This project adheres to [Semantic Versioning](http://semver.org/).
- **Support:** `.ad`, `.am`, `.desktop`, `.directory`, `.ebuild`, `.install`, `.m4`, `.menu`, `_osc`, `PKGBUILD`, `.sed`, `_service`, `.spacemacs`
- Support for numerous GNU Automake/Autoconf files

### Fixed
- [[`#193`](https://github.com/DanBrooker/file-icons/issues/193)] Tab icons now update when changing file extensions
- [[`#316`](https://github.com/DanBrooker/file-icons/issues/316)] Newly-saved files now display icons in tab


[1.7.1] - 2016-04-05
--------------------
Expand Down
28 changes: 24 additions & 4 deletions index.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -49,24 +49,44 @@ module.exports =


observe: (enabled) ->

# Setting up observers
if enabled
@observer = atom.workspace.observeTextEditors (editor) ->
workspace = atom.views.getView(atom.workspace)
openedFile = editor.getPath()

# New file
if not editor.getFileName()?
unless openedFile
onSave = editor.onDidSave (file) ->
pane = atom.views.getView(atom.workspace.getActivePane())
tab = pane?.querySelector(".tab-bar > .active.tab > .title")
tab = workspace?.querySelector(".tab-bar > .active.tab > .title")

# Patch data-* attributes to fix missing tab-icon
if not tab.dataset.path
if not tab?.dataset.path
{path} = file
tab.dataset.path = path
tab.dataset.name = basename path

# Remove the listener
onSave.dispose()

# Existing file: wait for pane to finish loading before querying the DOM
else
onDone = editor.onDidStopChanging () ->
tabs = workspace?.querySelectorAll(".pane > .tab-bar > .tab")
fileTabs = [].filter.call tabs, (tab) -> tab?.item is editor

# When a file's been renamed, patch the dataset of each tab that has it open
editor.onDidChangePath (path) =>
for tab in fileTabs
title = tab.itemTitle
title.dataset.path = path
title.dataset.name = basename path

# Drop the registration listener
onDone.dispose()

# Disable observers if deactivating package
else if @observer?
@observer.dispose()

Expand Down

0 comments on commit 8454a05

Please sign in to comment.