Add ctrl-Z keybinding to checkout HEAD revision

This commit is contained in:
Kevin Sawicki
2012-11-03 15:50:11 -07:00
parent 55d77eea8b
commit 830a0b337a
5 changed files with 48 additions and 1 deletions

View File

@@ -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)

View File

@@ -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('')

View File

@@ -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()

View File

@@ -0,0 +1,2 @@
window.keymap.bindKeys '.editor',
'ctrl-Z': 'editor:checkout-head-revision'

View File

@@ -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: ->