mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2024-11-10 10:17:11 +03:00
Merge pull request #10178 from atom/ku-pending-editor
Open file in pending state on single click
This commit is contained in:
commit
db74f4a8f0
@ -18,6 +18,8 @@ describe "Pane", ->
|
||||
onDidDestroy: (fn) -> @emitter.on('did-destroy', fn)
|
||||
destroy: -> @destroyed = true; @emitter.emit('did-destroy')
|
||||
isDestroyed: -> @destroyed
|
||||
isPending: -> @pending
|
||||
pending: false
|
||||
|
||||
beforeEach ->
|
||||
confirm = spyOn(atom.applicationDelegate, 'confirm')
|
||||
@ -153,6 +155,26 @@ describe "Pane", ->
|
||||
pane.activateItem(pane.itemAtIndex(1))
|
||||
expect(observed).toEqual [pane.itemAtIndex(1)]
|
||||
|
||||
it "replaces pending items", ->
|
||||
itemC = new Item("C")
|
||||
itemD = new Item("D")
|
||||
itemC.pending = true
|
||||
itemD.pending = true
|
||||
|
||||
expect(itemC.isPending()).toBe true
|
||||
pane.activateItem(itemC)
|
||||
expect(pane.getItems().length).toBe 3
|
||||
expect(pane.getActiveItem()).toBe pane.itemAtIndex(1)
|
||||
|
||||
expect(itemD.isPending()).toBe true
|
||||
pane.activateItem(itemD)
|
||||
expect(pane.getItems().length).toBe 3
|
||||
expect(pane.getActiveItem()).toBe pane.itemAtIndex(1)
|
||||
|
||||
pane.activateItem(pane.itemAtIndex(2))
|
||||
expect(pane.getItems().length).toBe 2
|
||||
expect(pane.getActiveItem()).toBe pane.itemAtIndex(1)
|
||||
|
||||
describe "::activateNextItem() and ::activatePreviousItem()", ->
|
||||
it "sets the active item to the next/previous item, looping around at either end", ->
|
||||
pane = new Pane(paneParams(items: [new Item("A"), new Item("B"), new Item("C")]))
|
||||
|
@ -5804,3 +5804,29 @@ describe "TextEditor", ->
|
||||
screenRange: marker1.getRange(),
|
||||
rangeIsReversed: false
|
||||
}
|
||||
|
||||
describe "pending state", ->
|
||||
editor1 = null
|
||||
beforeEach ->
|
||||
waitsForPromise ->
|
||||
atom.workspace.open('sample.txt', pending: true).then (o) -> editor1 = o
|
||||
|
||||
it "should open file in pending state if 'pending' option is true", ->
|
||||
expect(editor1.isPending()).toBe true
|
||||
expect(editor.isPending()).toBe false # By default pending status is false
|
||||
|
||||
it "invokes ::onDidTerminatePendingState observers if pending status is terminated", ->
|
||||
events = []
|
||||
editor1.onDidTerminatePendingState (event) -> events.push(event)
|
||||
editor1.terminatePendingState()
|
||||
expect(editor1.isPending()).toBe false
|
||||
expect(events).toEqual [editor1]
|
||||
|
||||
it "should terminate pending state when buffer is changed", ->
|
||||
events = []
|
||||
editor1.onDidTerminatePendingState (event) -> events.push(event)
|
||||
expect(editor1.isPending()).toBe true
|
||||
editor1.insertText('I\'ll be back!')
|
||||
advanceClock(500)
|
||||
expect(editor1.isPending()).toBe false
|
||||
expect(events).toEqual [editor1]
|
||||
|
@ -337,13 +337,19 @@ class Pane extends Model
|
||||
#
|
||||
# * `index` {Number}
|
||||
activateItemAtIndex: (index) ->
|
||||
@activateItem(@itemAtIndex(index))
|
||||
item = @itemAtIndex(index) or @getActiveItem()
|
||||
@setActiveItem(item)
|
||||
|
||||
# Public: Make the given item *active*, causing it to be displayed by
|
||||
# the pane's view.
|
||||
activateItem: (item) ->
|
||||
if item?
|
||||
@addItem(item, @getActiveItemIndex() + 1, false)
|
||||
if @activeItem?.isPending?()
|
||||
index = @getActiveItemIndex()
|
||||
@destroyActiveItem() unless item is @activeItem
|
||||
else
|
||||
index = @getActiveItemIndex() + 1
|
||||
@addItem(item, index, false)
|
||||
@setActiveItem(item)
|
||||
|
||||
# Public: Add the given item to the pane.
|
||||
@ -574,7 +580,6 @@ class Pane extends Model
|
||||
# Public: Makes this pane the *active* pane, causing it to gain focus.
|
||||
activate: ->
|
||||
throw new Error("Pane has been destroyed") if @isDestroyed()
|
||||
|
||||
@container?.setActivePane(this)
|
||||
@emitter.emit 'did-activate'
|
||||
|
||||
|
@ -92,7 +92,7 @@ class TextEditor extends Model
|
||||
softWrapped, @displayBuffer, @selectionsMarkerLayer, buffer, suppressCursorCreation,
|
||||
@mini, @placeholderText, lineNumberGutterVisible, largeFileMode, @config,
|
||||
@notificationManager, @packageManager, @clipboard, @viewRegistry, @grammarRegistry,
|
||||
@project, @assert, @applicationDelegate
|
||||
@project, @assert, @applicationDelegate, @pending
|
||||
} = params
|
||||
|
||||
throw new Error("Must pass a config parameter when constructing TextEditors") unless @config?
|
||||
@ -161,6 +161,9 @@ class TextEditor extends Model
|
||||
@disposables.add @buffer.onDidChangeEncoding =>
|
||||
@emitter.emit 'did-change-encoding', @getEncoding()
|
||||
@disposables.add @buffer.onDidDestroy => @destroy()
|
||||
if @pending
|
||||
@disposables.add @buffer.onDidChangeModified =>
|
||||
@terminatePendingState() if @buffer.isModified()
|
||||
|
||||
@preserveCursorPositionOnBufferReload()
|
||||
|
||||
@ -569,6 +572,13 @@ class TextEditor extends Model
|
||||
getEditorWidthInChars: ->
|
||||
@displayBuffer.getEditorWidthInChars()
|
||||
|
||||
onDidTerminatePendingState: (callback) ->
|
||||
@emitter.on 'did-terminate-pending-state', callback
|
||||
|
||||
terminatePendingState: ->
|
||||
@pending = false
|
||||
@emitter.emit 'did-terminate-pending-state', this
|
||||
|
||||
###
|
||||
Section: File Details
|
||||
###
|
||||
@ -652,6 +662,9 @@ class TextEditor extends Model
|
||||
# Essential: Returns {Boolean} `true` if this editor has no content.
|
||||
isEmpty: -> @buffer.isEmpty()
|
||||
|
||||
# Returns {Boolean} `true` if this editor is pending and `false` if it is permanent.
|
||||
isPending: -> Boolean(@pending)
|
||||
|
||||
# Copies the current file path to the native clipboard.
|
||||
copyPathToClipboard: ->
|
||||
if filePath = @getPath()
|
||||
|
Loading…
Reference in New Issue
Block a user