mirror of
https://github.com/atom/atom.git
synced 2026-04-28 03:01:47 -04:00
Merge remote-tracking branch 'origin/master' into vim-core-changes
Conflicts: src/app/pane.coffee
This commit is contained in:
@@ -39,13 +39,13 @@ class CommandPanelView extends View
|
||||
@command 'core:move-up', => @navigateBackwardInHistory()
|
||||
@command 'core:move-down', => @navigateForwardInHistory()
|
||||
|
||||
rootView.command 'command-panel:toggle', => @toggle()
|
||||
rootView.command 'command-panel:toggle-preview', => @togglePreview()
|
||||
rootView.command 'command-panel:find-in-file', => @attach('/')
|
||||
rootView.command 'command-panel:find-in-project', => @attach('Xx/')
|
||||
rootView.command 'command-panel:repeat-relative-address', => @repeatRelativeAddress()
|
||||
rootView.command 'command-panel:repeat-relative-address-in-reverse', => @repeatRelativeAddress(reverse: true)
|
||||
rootView.command 'command-panel:set-selection-as-regex-address', => @setSelectionAsLastRelativeAddress()
|
||||
@subscribeToCommand rootView, 'command-panel:toggle', => @toggle()
|
||||
@subscribeToCommand rootView, 'command-panel:toggle-preview', => @togglePreview()
|
||||
@subscribeToCommand rootView, 'command-panel:find-in-file', => @attach('/')
|
||||
@subscribeToCommand rootView, 'command-panel:find-in-project', => @attach('Xx/')
|
||||
@subscribeToCommand rootView, 'command-panel:repeat-relative-address', => @repeatRelativeAddress()
|
||||
@subscribeToCommand rootView, 'command-panel:repeat-relative-address-in-reverse', => @repeatRelativeAddress(reverse: true)
|
||||
@subscribeToCommand rootView, 'command-panel:set-selection-as-regex-address', => @setSelectionAsLastRelativeAddress()
|
||||
|
||||
@on 'click', '.expand', @onExpandAll
|
||||
@on 'click', '.collapse', @onCollapseAll
|
||||
@@ -65,8 +65,6 @@ class CommandPanelView extends View
|
||||
|
||||
destroy: ->
|
||||
@previewList.destroy()
|
||||
rootView.off "command-panel:toggle-preview command-panel:find-in-file command-panel:find-in-project \
|
||||
command-panel:repeat-relative-address command-panel:repeat-relative-address-in-reverse command-panel:set-selection-as-regex-address"
|
||||
@remove()
|
||||
|
||||
toggle: ->
|
||||
|
||||
@@ -14,10 +14,20 @@ class MarkdownPreviewView extends ScrollView
|
||||
|
||||
initialize: (@buffer) ->
|
||||
super
|
||||
|
||||
@fetchRenderedMarkdown()
|
||||
@on 'core:move-up', => @scrollUp()
|
||||
@on 'core:move-down', => @scrollDown()
|
||||
|
||||
afterAttach: (onDom) ->
|
||||
@subscribe @buffer, 'saved', =>
|
||||
@fetchRenderedMarkdown()
|
||||
pane = @getPane()
|
||||
pane.showItem(this) if pane? and pane isnt rootView.getActivePane()
|
||||
|
||||
getPane: ->
|
||||
@parent('.item-views').parent('.pane').view()
|
||||
|
||||
serialize: ->
|
||||
deserializer: 'MarkdownPreviewView'
|
||||
path: @buffer.getPath()
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
EditSession = require 'edit-session'
|
||||
MarkdownPreviewView = require 'markdown-preview/lib/markdown-preview-view'
|
||||
MarkdownPreviewView = require './markdown-preview-view'
|
||||
|
||||
module.exports =
|
||||
activate: ->
|
||||
rootView.command 'markdown-preview:show', '.editor', => @show()
|
||||
rootView.on 'core:save', ".pane", => @show() if @previewExists()
|
||||
|
||||
show: ->
|
||||
activePane = rootView.getActivePane()
|
||||
@@ -16,17 +15,19 @@ module.exports =
|
||||
console.warn("Can not render markdown for '#{editSession.getUri() ? 'untitled'}'")
|
||||
return
|
||||
|
||||
if nextPane = activePane.getNextPane()
|
||||
if preview = nextPane.itemForUri("markdown-preview:#{editSession.getPath()}")
|
||||
nextPane.showItem(preview)
|
||||
preview.fetchRenderedMarkdown()
|
||||
else
|
||||
nextPane.showItem(new MarkdownPreviewView(editSession.buffer))
|
||||
{previewPane, previewItem} = @getExistingPreview(editSession)
|
||||
if previewItem?
|
||||
previewPane.showItem(previewItem)
|
||||
previewItem.fetchRenderedMarkdown()
|
||||
else if nextPane = activePane.getNextPane()
|
||||
nextPane.showItem(new MarkdownPreviewView(editSession.buffer))
|
||||
else
|
||||
activePane.splitRight(new MarkdownPreviewView(editSession.buffer))
|
||||
activePane.focus()
|
||||
|
||||
previewExists: ->
|
||||
nextPane = rootView.getActivePane().getNextPane()
|
||||
item = rootView.getActivePane().activeItem
|
||||
nextPane?.itemForUri("markdown-preview:#{item.getPath?()}")
|
||||
getExistingPreview: (editSession) ->
|
||||
uri = "markdown-preview:#{editSession.getPath()}"
|
||||
for previewPane in rootView.getPanes()
|
||||
previewItem = previewPane.itemForUri(uri)
|
||||
return {previewPane, previewItem} if previewItem?
|
||||
{}
|
||||
|
||||
@@ -62,7 +62,7 @@ describe "MarkdownPreview package", ->
|
||||
pane.focus()
|
||||
|
||||
MarkdownPreviewView.prototype.fetchRenderedMarkdown.reset()
|
||||
pane.trigger("core:save")
|
||||
pane.activeItem.buffer.trigger 'saved'
|
||||
expect(MarkdownPreviewView.prototype.fetchRenderedMarkdown).not.toHaveBeenCalled()
|
||||
|
||||
describe "when a preview item has already been created for the edit session's uri", ->
|
||||
@@ -86,12 +86,30 @@ describe "MarkdownPreview package", ->
|
||||
expect(pane1).toMatchSelector(':has(:focus)')
|
||||
|
||||
describe "when a buffer is saved", ->
|
||||
it "updates the existing preview item", ->
|
||||
rootView.getActiveView().trigger 'markdown-preview:show'
|
||||
[pane1, pane2] = rootView.getPanes()
|
||||
preview = pane2.activeItem
|
||||
pane1.focus()
|
||||
describe "when the preview is in the same pane", ->
|
||||
it "updates the preview but does not make it active", ->
|
||||
rootView.getActiveView().trigger 'markdown-preview:show'
|
||||
[pane1, pane2] = rootView.getPanes()
|
||||
pane2.moveItemToPane(pane2.activeItem, pane1, 1)
|
||||
pane1.showItemAtIndex(1)
|
||||
pane1.showItemAtIndex(0)
|
||||
preview = pane1.itemAtIndex(1)
|
||||
|
||||
preview.fetchRenderedMarkdown.reset()
|
||||
pane1.trigger("core:save")
|
||||
expect(preview.fetchRenderedMarkdown).toHaveBeenCalled()
|
||||
preview.fetchRenderedMarkdown.reset()
|
||||
pane1.activeItem.buffer.trigger 'saved'
|
||||
expect(preview.fetchRenderedMarkdown).toHaveBeenCalled()
|
||||
expect(pane1.activeItem).not.toBe preview
|
||||
|
||||
describe "when the preview is not in the same pane", ->
|
||||
it "updates the preview and makes it active", ->
|
||||
rootView.getActiveView().trigger 'markdown-preview:show'
|
||||
[pane1, pane2] = rootView.getPanes()
|
||||
preview = pane2.activeItem
|
||||
pane2.showItem($$ -> @div id: 'view', tabindex: -1, 'View')
|
||||
expect(pane2.activeItem).not.toBe preview
|
||||
pane1.focus()
|
||||
|
||||
preview.fetchRenderedMarkdown.reset()
|
||||
pane1.activeItem.buffer.trigger 'saved'
|
||||
expect(preview.fetchRenderedMarkdown).toHaveBeenCalled()
|
||||
expect(pane2.activeItem).toBe preview
|
||||
|
||||
@@ -5,12 +5,8 @@ $ = require 'jquery'
|
||||
module.exports =
|
||||
class StatusBarView extends View
|
||||
@activate: ->
|
||||
rootView.eachEditor (editor) =>
|
||||
@appendToEditorPane(rootView, editor) if editor.attached
|
||||
|
||||
@appendToEditorPane: (rootView, editor) ->
|
||||
if pane = editor.getPane()
|
||||
pane.append(new StatusBarView(rootView, editor))
|
||||
rootView.eachPane (pane) =>
|
||||
pane.append(new StatusBarView(rootView, pane))
|
||||
|
||||
@content: ->
|
||||
@div class: 'status-bar', =>
|
||||
@@ -26,41 +22,46 @@ class StatusBarView extends View
|
||||
@span class: 'cursor-position', outlet: 'cursorPosition'
|
||||
@span class: 'grammar-name', outlet: 'grammarName'
|
||||
|
||||
initialize: (rootView, @editor) ->
|
||||
initialize: (rootView, @pane) ->
|
||||
@updatePathText()
|
||||
@editor.on 'editor:path-changed', =>
|
||||
@subscribe @pane, 'pane:active-item-changed', =>
|
||||
@subscribeToBuffer()
|
||||
@updatePathText()
|
||||
|
||||
@updateCursorPositionText()
|
||||
@subscribe @editor, 'cursor:moved', => @updateCursorPositionText()
|
||||
@subscribe @grammarName, 'click', => @editor.trigger 'grammar-selector:show'
|
||||
@subscribe @editor, 'editor:grammar-changed', => @updateGrammarText()
|
||||
@subscribe @pane, 'cursor:moved', => @updateCursorPositionText()
|
||||
@subscribe @grammarName, 'click', => @pane.activeView.trigger 'grammar-selector:show'
|
||||
@subscribe @pane, 'editor:grammar-changed', => @updateGrammarText()
|
||||
|
||||
if git?
|
||||
@subscribe git, 'status-changed', (path, status) =>
|
||||
@updateStatusBar() if path is @buffer?.getPath()
|
||||
@updateStatusBar() if path is @getActiveItemPath()
|
||||
@subscribe git, 'statuses-changed', =>
|
||||
@updateStatusBar()
|
||||
|
||||
@subscribeToBuffer()
|
||||
|
||||
getActiveItemPath: ->
|
||||
@pane.activeItem?.getPath?()
|
||||
|
||||
subscribeToBuffer: ->
|
||||
@buffer?.off '.status-bar'
|
||||
@buffer = @editor.getBuffer()
|
||||
@buffer.on 'modified-status-changed.status-bar', (isModified) => @updateBufferHasModifiedText(isModified)
|
||||
@buffer.on 'saved.status-bar', => @updateStatusBar()
|
||||
if @buffer = @pane.activeItem.getBuffer?()
|
||||
@buffer.on 'modified-status-changed.status-bar', (isModified) => @updateBufferHasModifiedText(isModified)
|
||||
@buffer.on 'saved.status-bar', => @updateStatusBar()
|
||||
|
||||
@updateStatusBar()
|
||||
|
||||
updateStatusBar: ->
|
||||
@updateGrammarText()
|
||||
@updateBranchText()
|
||||
@updateBufferHasModifiedText(@buffer.isModified())
|
||||
@updateBufferHasModifiedText(@buffer?.isModified())
|
||||
@updateStatusText()
|
||||
@updateCursorPositionText()
|
||||
|
||||
updateGrammarText: ->
|
||||
grammar = @editor.getGrammar()
|
||||
if grammar is syntax.nullGrammar
|
||||
@grammarName.text('').hide()
|
||||
grammar = @pane.activeView.getGrammar?()
|
||||
if not grammar? or grammar is syntax.nullGrammar
|
||||
@grammarName.hide()
|
||||
else
|
||||
@grammarName.text(grammar.name).show()
|
||||
|
||||
@@ -73,7 +74,7 @@ class StatusBarView extends View
|
||||
@isModified = false
|
||||
|
||||
updateBranchText: ->
|
||||
path = @editor.getPath()
|
||||
path = @getActiveItemPath()
|
||||
@branchArea.hide()
|
||||
return unless path
|
||||
|
||||
@@ -82,7 +83,7 @@ class StatusBarView extends View
|
||||
@branchArea.show() if head
|
||||
|
||||
updateStatusText: ->
|
||||
path = @editor.getPath()
|
||||
path = @getActiveItemPath()
|
||||
@gitStatusIcon.removeClass()
|
||||
return unless path
|
||||
|
||||
@@ -113,17 +114,24 @@ class StatusBarView extends View
|
||||
@gitStatusIcon.text('')
|
||||
else if git.isStatusNew(status)
|
||||
@gitStatusIcon.addClass('new-status-icon')
|
||||
@gitStatusIcon.text("+#{@buffer.getLineCount()}")
|
||||
if @buffer?
|
||||
@gitStatusIcon.text("+#{@buffer.getLineCount()}")
|
||||
else
|
||||
@gitStatusIcon.text('')
|
||||
else if git.isPathIgnored(path)
|
||||
@gitStatusIcon.addClass('ignored-status-icon')
|
||||
@gitStatusIcon.text('')
|
||||
|
||||
updatePathText: ->
|
||||
if path = @editor.getPath()
|
||||
@currentPath.text(project.relativize(path))
|
||||
if path = @getActiveItemPath()
|
||||
@currentPath.text(project.relativize(path)).show()
|
||||
else if title = @pane.activeItem.getTitle?()
|
||||
@currentPath.text(title).show()
|
||||
else
|
||||
@currentPath.text('untitled')
|
||||
@currentPath.hide()
|
||||
|
||||
updateCursorPositionText: ->
|
||||
{ row, column } = @editor.getCursorBufferPosition()
|
||||
@cursorPosition.text("#{row + 1},#{column + 1}")
|
||||
if position = @pane.activeView.getCursorBufferPosition?()
|
||||
@cursorPosition.text("#{position.row + 1},#{position.column + 1}").show()
|
||||
else
|
||||
@cursorPosition.hide()
|
||||
|
||||
@@ -3,6 +3,7 @@ _ = require 'underscore'
|
||||
RootView = require 'root-view'
|
||||
StatusBar = require 'status-bar/lib/status-bar-view'
|
||||
fsUtils = require 'fs-utils'
|
||||
{$$} = require 'space-pen'
|
||||
|
||||
describe "StatusBar", ->
|
||||
[editor, statusBar, buffer] = []
|
||||
@@ -102,7 +103,9 @@ describe "StatusBar", ->
|
||||
|
||||
describe "when the associated editor's cursor position changes", ->
|
||||
it "updates the cursor position in the status bar", ->
|
||||
rootView.attachToDom()
|
||||
editor.setCursorScreenPosition([1, 2])
|
||||
editor.updateDisplay()
|
||||
expect(statusBar.cursorPosition.text()).toBe '2,3'
|
||||
|
||||
describe "git branch label", ->
|
||||
@@ -192,7 +195,6 @@ describe "StatusBar", ->
|
||||
editor.activeEditSession.languageMode.grammar = syntax.nullGrammar
|
||||
editor.activeEditSession.trigger 'grammar-changed'
|
||||
expect(statusBar.find('.grammar-name')).toBeHidden()
|
||||
expect(statusBar.find('.grammar-name').text()).toBe ''
|
||||
editor.reloadGrammar()
|
||||
expect(statusBar.find('.grammar-name')).toBeVisible()
|
||||
expect(statusBar.find('.grammar-name').text()).toBe 'JavaScript'
|
||||
@@ -209,3 +211,26 @@ describe "StatusBar", ->
|
||||
editor.on 'grammar-selector:show', eventHandler
|
||||
statusBar.find('.grammar-name').click()
|
||||
expect(eventHandler).toHaveBeenCalled()
|
||||
|
||||
describe "when the active item view does not implement getCursorBufferPosition()", ->
|
||||
it "hides the cursor position view", ->
|
||||
rootView.attachToDom()
|
||||
view = $$ -> @div id: 'view', tabindex: -1, 'View'
|
||||
editor.getPane().showItem(view)
|
||||
expect(statusBar.cursorPosition).toBeHidden()
|
||||
|
||||
describe "when the active item implements getTitle() but not getPath()", ->
|
||||
it "displays the title", ->
|
||||
rootView.attachToDom()
|
||||
view = $$ -> @div id: 'view', tabindex: -1, 'View'
|
||||
view.getTitle = => 'View Title'
|
||||
editor.getPane().showItem(view)
|
||||
expect(statusBar.currentPath.text()).toBe 'View Title'
|
||||
expect(statusBar.currentPath).toBeVisible()
|
||||
|
||||
describe "when the active item neither getTitle() nor getPath()", ->
|
||||
it "hides the path view", ->
|
||||
rootView.attachToDom()
|
||||
view = $$ -> @div id: 'view', tabindex: -1, 'View'
|
||||
editor.getPane().showItem(view)
|
||||
expect(statusBar.currentPath).toBeHidden()
|
||||
|
||||
@@ -77,11 +77,8 @@ class TabBarView extends View
|
||||
(@paneContainer.getPanes().length > 1) or (@pane.getItems().length > 1)
|
||||
|
||||
onDragStart: (event) =>
|
||||
unless @shouldAllowDrag(event)
|
||||
event.preventDefault()
|
||||
return
|
||||
|
||||
event.originalEvent.dataTransfer.setData 'atom-event', 'true'
|
||||
if @shouldAllowDrag()
|
||||
event.originalEvent.dataTransfer.setData 'atom-event', 'true'
|
||||
|
||||
el = $(event.target).closest('.sortable')
|
||||
el.addClass 'is-dragging'
|
||||
@@ -91,8 +88,15 @@ class TabBarView extends View
|
||||
paneIndex = @paneContainer.indexOfPane(pane)
|
||||
event.originalEvent.dataTransfer.setData 'from-pane-index', paneIndex
|
||||
|
||||
item = @pane.getItems()[el.index()]
|
||||
if item.getPath?
|
||||
event.originalEvent.dataTransfer.setData 'text/uri-list', 'file://' + item.getPath()
|
||||
event.originalEvent.dataTransfer.setData 'text/plain', item.getPath()
|
||||
|
||||
onDragEnd: (event) =>
|
||||
@find(".is-dragging").removeClass 'is-dragging'
|
||||
@children('.is-drop-target').removeClass 'is-drop-target'
|
||||
@children('.drop-target-is-after').removeClass 'drop-target-is-after'
|
||||
|
||||
onDragOver: (event) =>
|
||||
unless event.originalEvent.dataTransfer.getData('atom-event') is 'true'
|
||||
@@ -120,8 +124,6 @@ class TabBarView extends View
|
||||
return
|
||||
|
||||
event.stopPropagation()
|
||||
@children('.is-drop-target').removeClass 'is-drop-target'
|
||||
@children('.drop-target-is-after').removeClass 'drop-target-is-after'
|
||||
|
||||
dataTransfer = event.originalEvent.dataTransfer
|
||||
fromIndex = parseInt(dataTransfer.getData('sortable-index'))
|
||||
|
||||
@@ -279,8 +279,8 @@ describe "TabBarView", ->
|
||||
expect(pane2.activeItem).toBe item1
|
||||
expect(pane2.focus).toHaveBeenCalled()
|
||||
|
||||
describe 'when a non-tab is dragged to pane', ->
|
||||
it 'has no effect', ->
|
||||
describe "when a non-tab is dragged to pane", ->
|
||||
it "has no effect", ->
|
||||
expect(tabBar.getTabs().map (tab) -> tab.text()).toEqual ["Item 1", "sample.js", "Item 2"]
|
||||
expect(pane.getItems()).toEqual [item1, editSession1, item2]
|
||||
expect(pane.activeItem).toBe item2
|
||||
@@ -294,3 +294,11 @@ describe "TabBarView", ->
|
||||
expect(pane.activeItem).toBe item2
|
||||
expect(pane.focus).not.toHaveBeenCalled()
|
||||
|
||||
describe "when a tab is dragged out of application", ->
|
||||
it "should carry file's information", ->
|
||||
[dragStartEvent, dropEvent] = buildDragEvents(tabBar.tabAtIndex(1), tabBar.tabAtIndex(1))
|
||||
tabBar.onDragStart(dragStartEvent)
|
||||
|
||||
expect(dragStartEvent.originalEvent.dataTransfer.getData("text/plain")).toEqual editSession1.getPath()
|
||||
expect(dragStartEvent.originalEvent.dataTransfer.getData("text/uri-list")).toEqual 'file://' + editSession1.getPath()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user