mirror of
https://github.com/atom/atom.git
synced 2026-01-24 14:28:14 -05:00
Add ctrl-Z keybinding to checkout HEAD revision
This commit is contained in:
@@ -1889,3 +1889,32 @@ describe "Editor", ->
|
||||
editor.pageUp()
|
||||
expect(editor.getCursor().getScreenPosition().row).toBe(0)
|
||||
expect(editor.getFirstVisibleScreenRow()).toBe(0)
|
||||
|
||||
describe ".checkoutHead()", ->
|
||||
[repo, path, originalPathText] = []
|
||||
|
||||
beforeEach ->
|
||||
path = require.resolve('fixtures/git/working-dir/file.txt')
|
||||
originalPathText = fs.read(path)
|
||||
rootView.open(path)
|
||||
editor = rootView.getActiveEditor()
|
||||
editor.attachToDom()
|
||||
|
||||
afterEach ->
|
||||
fs.write(path, originalPathText)
|
||||
|
||||
it "restores the contents of the editor to the HEAD revision", ->
|
||||
editor.setText('')
|
||||
editor.save()
|
||||
|
||||
fileChangeHandler = jasmine.createSpy('fileChange')
|
||||
editor.getBuffer().file.on 'contents-change', fileChangeHandler
|
||||
|
||||
editor.checkoutHead()
|
||||
|
||||
waitsFor "file to trigger contents-change event", ->
|
||||
fileChangeHandler.callCount > 0
|
||||
|
||||
runs ->
|
||||
editor.checkoutHead()
|
||||
expect(editor.getText()).toBe(originalPathText)
|
||||
|
||||
@@ -146,3 +146,11 @@ describe "StatusBar", ->
|
||||
it "displays the new icon for a new file", ->
|
||||
rootView.open(newPath)
|
||||
expect(statusBar.gitStatusIcon).toHaveText('\uf26b')
|
||||
|
||||
it "updates when an editor-git-status-change event occurs", ->
|
||||
fs.write(path, "i've changed for the worse")
|
||||
rootView.open(path)
|
||||
expect(statusBar.gitStatusIcon).toHaveText('\uf26d')
|
||||
fs.write(path, originalPathText)
|
||||
rootView.getActiveEditor().trigger 'editor-git-status-change'
|
||||
expect(statusBar.gitStatusIcon).toHaveText('')
|
||||
|
||||
@@ -8,7 +8,7 @@ CursorView = require 'cursor-view'
|
||||
SelectionView = require 'selection-view'
|
||||
Native = require 'native'
|
||||
fs = require 'fs'
|
||||
|
||||
Git = require 'git'
|
||||
$ = require 'jquery'
|
||||
_ = require 'underscore'
|
||||
|
||||
@@ -154,6 +154,7 @@ class Editor extends View
|
||||
'editor:show-previous-buffer': @loadPreviousEditSession
|
||||
'editor:toggle-line-comments': @toggleLineCommentsInSelection
|
||||
'editor:log-cursor-scope': @logCursorScope
|
||||
'editor:checkout-head-revision': @checkoutHead
|
||||
|
||||
documentation = {}
|
||||
for name, method of editorBindings
|
||||
@@ -274,6 +275,11 @@ class Editor extends View
|
||||
setInvisibles: (@invisibles={}) ->
|
||||
@renderLines()
|
||||
|
||||
checkoutHead: ->
|
||||
if path = @getPath()
|
||||
if new Git(path).checkoutHead(path)
|
||||
@trigger 'editor-git-status-change'
|
||||
|
||||
setText: (text) -> @getBuffer().setText(text)
|
||||
getText: -> @getBuffer().getText()
|
||||
getPath: -> @getBuffer().getPath()
|
||||
|
||||
2
src/app/keymaps/git.coffee
Normal file
2
src/app/keymaps/git.coffee
Normal file
@@ -0,0 +1,2 @@
|
||||
window.keymap.bindKeys '.editor',
|
||||
'ctrl-Z': 'editor:checkout-head-revision'
|
||||
@@ -40,6 +40,8 @@ class StatusBar extends View
|
||||
@updateCursorPositionText()
|
||||
@editor.on 'cursor-move', => _.delay (=> @updateCursorPositionText()), 50
|
||||
|
||||
@editor.on 'editor-git-status-change', => @updateStatusBar()
|
||||
|
||||
@subscribeToBuffer()
|
||||
|
||||
subscribeToBuffer: ->
|
||||
|
||||
Reference in New Issue
Block a user