Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/main.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ module.exports =
tabScrollingThreshold:
type: 'integer'
default: 120
usePreviewTabs:
type: 'boolean'
default: true
description: 'Tabs will only stay open if they are modified or double-clicked'

activate: ->
@tabBarViews = []
Expand Down
10 changes: 8 additions & 2 deletions lib/tab-bar-view.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ BrowserWindow = null # Defer require until actually used
RendererIpc = require 'ipc'

{$, View} = require 'atom-space-pen-views'
{CompositeDisposable} = require 'atom'
{CompositeDisposable, TextEditor} = require 'atom'
_ = require 'underscore-plus'
TabView = require './tab-view'

Expand Down Expand Up @@ -46,7 +46,11 @@ class TabBarView extends View
@subscriptions.add @pane.onDidRemoveItem ({item}) =>
@removeTabForItem(item)

@subscriptions.add @pane.onDidChangeActiveItem =>
@subscriptions.add @pane.onDidChangeActiveItem (item) =>
if atom.config.get('tabs.usePreviewTabs') and item instanceof TextEditor
if @getTabs().length > 1 and @tab.item isnt item and @tab.isPreviewTab
@pane.destroyItem @tab.item
@tab = @tabForItem(item)
@updateActiveTab()

@subscriptions.add atom.config.observe 'tabs.tabScrolling', => @updateTabScrolling()
Expand Down Expand Up @@ -88,6 +92,8 @@ class TabBarView extends View
addTabForItem: (item, index) ->
tabView = new TabView()
tabView.initialize(item)
if atom.config.get('tabs.usePreviewTabs') and not @tab and item instanceof TextEditor
@tab = tabView
@insertTabAtIndex(tabView, index)

moveItemTabToIndex: (item, index) ->
Expand Down
12 changes: 12 additions & 0 deletions lib/tab-view.coffee
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
path = require 'path'
{$} = require 'atom-space-pen-views'
{TextEditor} = require 'atom'

module.exports =
class TabView extends HTMLElement
initialize: (@item) ->
@isPreviewTab = false
if atom.config.get('tabs.usePreviewTabs') and @item instanceof TextEditor
@isPreviewTab = true
@addEventListener 'dblclick', =>
@isPreviewTab = false
@itemTitle.classList.remove('temp')

@classList.add('tab', 'sortable')

@itemTitle = document.createElement('div')
@itemTitle.classList.add('temp') if @isPreviewTab
@itemTitle.classList.add('title')
@appendChild(@itemTitle)

Expand Down Expand Up @@ -156,6 +165,9 @@ class TabView extends HTMLElement

updateModifiedStatus: ->
if @item.isModified?()
if atom.config.get('tabs.usePreviewTabs')
@isPreviewTab = false
@itemTitle.classList.remove('temp')
@classList.add('modified') unless @isModified
@isModified = true
else
Expand Down
83 changes: 83 additions & 0 deletions spec/tabs-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -709,3 +709,86 @@ describe "TabBarView", ->
pane.destroyItem(item2)
expect(pane.getItems().length).toBe 1
expect(tabBar.element).toHaveClass 'hidden'

describe "when usePreviewTabs is true in package settings", ->
beforeEach ->
atom.config.set("tabs.usePreviewTabs", true)
pane.destroyItems()

describe "when opening a new tab", ->
it "adds tab with class 'temp'", ->
editor1 = null
waitsForPromise ->
atom.project.open('sample.txt').then (o) -> editor1 = o
runs ->
pane.activateItem(editor1)
expect(tabBar.find('.tab .temp').length).toBe 1
expect(tabBar.find('.tab:eq(0) .title')).toHaveClass 'temp'

describe "when there is a temp tab already", ->
it "it will replace an existing temporary tab", ->
editor1 = null
editor2 = null

waitsForPromise ->
atom.project.open('sample.txt').then (o) ->
editor1 = o
pane.activateItem(editor1)
atom.project.open('sample2.txt').then (o) ->
editor2 = o
pane.activateItem(editor2)

runs ->
expect(editor1.isDestroyed()).toBe true
expect(editor2.isDestroyed()).toBe false
expect(tabBar.tabForItem(editor1)).not.toExist()
expect($(tabBar.tabForItem(editor2)).find('.title')).toHaveClass 'temp'
it 'makes the tab permanent when dbl clicking the tab', ->
editor2 = null

waitsForPromise ->
atom.project.open('sample.txt').then (o) -> editor2 = o

runs ->
pane.activateItem(editor2)
dbclickEvt = document.createEvent 'MouseEvents'
dbclickEvt.initEvent 'dblclick'
tabBar.tabForItem(editor2).dispatchEvent dbclickEvt
expect($(tabBar.tabForItem(editor2)).find('.title')).not.toHaveClass 'temp'

describe 'when opening views that do not contain an editor', ->
editor2 = null
settingsView = null

beforeEach ->
waitsForPromise ->
atom.project.open('sample.txt').then (o) ->
editor2 = o
pane.activateItem(editor2)

waitsForPromise ->
atom.packages.activatePackage('settings-view').then ->
atom.workspace.open('atom://config').then (o) ->
settingsView = o
pane.activateItem(settingsView)

it 'creates a permanent tab', ->
expect(tabBar.tabForItem(settingsView)).toExist()
expect($(tabBar.tabForItem(settingsView)).find('.title')).not.toHaveClass 'temp'

it 'keeps an existing temp tab', ->
expect(tabBar.tabForItem(editor2)).toExist()
expect($(tabBar.tabForItem(editor2)).find('.title')).toHaveClass 'temp'

describe 'when editing a file', ->
it 'makes the tab permanent', ->
editor1 = null
waitsForPromise ->
atom.workspace.open('sample.txt').then (o) ->
editor1 = o
pane.activateItem(editor1)
editor1.insertText('x')
advanceClock(editor1.buffer.stoppedChangingDelay)

runs ->
expect($(tabBar.tabForItem(editor1)).find('.title')).not.toHaveClass 'temp'
3 changes: 3 additions & 0 deletions styles/tabs.less
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
&.temp {
font-style: italic;
}
}

.hide-icon {
Expand Down