When a tab is clicked, activate its EditSession

This commit is contained in:
Nathan Sobo
2012-11-20 16:19:50 -07:00
parent 0f2cb6fd96
commit e1f4d2954c
3 changed files with 14 additions and 1 deletions

View File

@@ -3,7 +3,7 @@ _ = require 'underscore'
RootView = require 'root-view'
Tabs = require 'tabs'
fdescribe "Tabs", ->
describe "Tabs", ->
[rootView, editor, statusBar, buffer, tabs] = []
beforeEach ->
@@ -59,3 +59,11 @@ fdescribe "Tabs", ->
editor.destroyActiveEditSession()
expect(tabs.find('.tab').length).toBe 1
expect(tabs.find('.tab:eq(0) .file-name').text()).toBe 'sample.txt'
describe "when a tab is clicked", ->
it "activates the associated edit session", ->
expect(editor.getActiveEditSessionIndex()).toBe 1
tabs.find('.tab:eq(0)').click()
expect(editor.getActiveEditSessionIndex()).toBe 0
tabs.find('.tab:eq(1)').click()
expect(editor.getActiveEditSessionIndex()).toBe 1

View File

@@ -1,3 +1,4 @@
$ = require 'jquery'
{View, $$} = require 'space-pen'
module.exports =
@@ -27,6 +28,9 @@ class Tabs extends View
@editor.on 'editor:edit-session-added', (e, editSession) => @addTabForEditSession(editSession)
@editor.on 'editor:edit-session-removed', (e, editSession, index) => @removeTabAtIndex(index)
@on 'click', '.tab', (e) =>
@editor.setActiveEditSessionIndex($(e.target).closest('.tab').index())
addTabForEditSession: (editSession) ->
@append $$ ->
@div class: 'tab', =>

View File

@@ -4,6 +4,7 @@
}
.tab {
cursor: default;
float: left;
margin: 4px;
margin-bottom: 0;