mirror of
https://github.com/atom/atom.git
synced 2026-04-06 03:02:13 -04:00
Pull out go-to-line package into a separate repo
This commit is contained in:
@@ -73,6 +73,7 @@
|
||||
"gfm": "0.1.0",
|
||||
"git-diff": "0.1.0",
|
||||
"gists": "0.1.0",
|
||||
"go-to-line": "0.1.0",
|
||||
"image-view": "0.1.0",
|
||||
"spell-check": "0.1.0",
|
||||
"terminal": "0.3.0",
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
'body':
|
||||
'meta-l': 'editor:go-to-line'
|
||||
'.go-to-line .mini.editor input':
|
||||
'enter': 'core:confirm',
|
||||
'escape': 'core:cancel'
|
||||
'meta-w': 'core:cancel'
|
||||
@@ -1,64 +0,0 @@
|
||||
{View} = require 'space-pen'
|
||||
Editor = require 'editor'
|
||||
$ = require 'jquery'
|
||||
Point = require 'point'
|
||||
|
||||
module.exports =
|
||||
class GoToLineView extends View
|
||||
|
||||
@activate: -> new GoToLineView
|
||||
|
||||
@content: ->
|
||||
@div class: 'go-to-line overlay from-top mini', =>
|
||||
@subview 'miniEditor', new Editor(mini: true)
|
||||
@div class: 'message', outlet: 'message'
|
||||
|
||||
detaching: false
|
||||
|
||||
initialize: ->
|
||||
rootView.command 'editor:go-to-line', '.editor', => @toggle()
|
||||
@miniEditor.on 'focusout', => @detach() unless @detaching
|
||||
@on 'core:confirm', => @confirm()
|
||||
@on 'core:cancel', => @detach()
|
||||
|
||||
@miniEditor.preempt 'textInput', (e) =>
|
||||
false unless e.originalEvent.data.match(/[0-9]/)
|
||||
|
||||
toggle: ->
|
||||
if @hasParent()
|
||||
@detach()
|
||||
else
|
||||
@attach()
|
||||
|
||||
detach: ->
|
||||
return unless @hasParent()
|
||||
|
||||
@detaching = true
|
||||
@miniEditor.setText('')
|
||||
|
||||
if @previouslyFocusedElement?.isOnDom()
|
||||
@previouslyFocusedElement.focus()
|
||||
else
|
||||
rootView.focus()
|
||||
|
||||
super
|
||||
|
||||
@detaching = false
|
||||
|
||||
confirm: ->
|
||||
lineNumber = @miniEditor.getText()
|
||||
editor = rootView.getActiveView()
|
||||
|
||||
@detach()
|
||||
|
||||
return unless editor and lineNumber.length
|
||||
position = new Point(parseInt(lineNumber - 1))
|
||||
editor.scrollToBufferPosition(position, center: true)
|
||||
editor.setCursorBufferPosition(position)
|
||||
editor.moveCursorToFirstCharacterOfLine()
|
||||
|
||||
attach: ->
|
||||
@previouslyFocusedElement = $(':focus')
|
||||
rootView.append(this)
|
||||
@message.text("Enter a line number 1-#{rootView.getActiveView().getLineCount()}")
|
||||
@miniEditor.focus()
|
||||
@@ -1,4 +0,0 @@
|
||||
'main': './lib/go-to-line-view'
|
||||
'description': 'Jump to a specific editor line number with `cmd-l`.'
|
||||
'activationEvents':
|
||||
'editor:go-to-line': '.editor'
|
||||
@@ -1,50 +0,0 @@
|
||||
RootView = require 'root-view'
|
||||
GoToLineView = require 'go-to-line/lib/go-to-line-view'
|
||||
|
||||
describe 'GoToLine', ->
|
||||
[goToLine, editor] = []
|
||||
|
||||
beforeEach ->
|
||||
window.rootView = new RootView
|
||||
rootView.open('sample.js')
|
||||
rootView.enableKeymap()
|
||||
editor = rootView.getActiveView()
|
||||
goToLine = GoToLineView.activate()
|
||||
editor.setCursorBufferPosition([1,0])
|
||||
|
||||
describe "when editor:go-to-line is triggered", ->
|
||||
it "attaches to the root view", ->
|
||||
expect(goToLine.hasParent()).toBeFalsy()
|
||||
editor.trigger 'editor:go-to-line'
|
||||
expect(goToLine.hasParent()).toBeTruthy()
|
||||
|
||||
describe "when entering a line number", ->
|
||||
it "only allows 0-9 to be entered in the mini editor", ->
|
||||
expect(goToLine.miniEditor.getText()).toBe ''
|
||||
goToLine.miniEditor.textInput 'a'
|
||||
expect(goToLine.miniEditor.getText()).toBe ''
|
||||
goToLine.miniEditor.textInput '40'
|
||||
expect(goToLine.miniEditor.getText()).toBe '40'
|
||||
|
||||
describe "when core:confirm is triggered", ->
|
||||
describe "when a line number has been entered", ->
|
||||
it "moves the cursor to the first character of the line", ->
|
||||
goToLine.miniEditor.textInput '3'
|
||||
goToLine.miniEditor.trigger 'core:confirm'
|
||||
expect(editor.getCursorBufferPosition()).toEqual [2, 4]
|
||||
|
||||
describe "when no line number has been entered", ->
|
||||
it "closes the view and does not update the cursor position", ->
|
||||
editor.trigger 'editor:go-to-line'
|
||||
expect(goToLine.hasParent()).toBeTruthy()
|
||||
goToLine.miniEditor.trigger 'core:confirm'
|
||||
expect(goToLine.hasParent()).toBeFalsy()
|
||||
expect(editor.getCursorBufferPosition()).toEqual [1, 0]
|
||||
|
||||
describe "when core:cancel is triggered", ->
|
||||
it "closes the view and does not update the cursor position", ->
|
||||
editor.trigger 'editor:go-to-line'
|
||||
expect(goToLine.hasParent()).toBeTruthy()
|
||||
goToLine.miniEditor.trigger 'core:cancel'
|
||||
expect(goToLine.hasParent()).toBeFalsy()
|
||||
expect(editor.getCursorBufferPosition()).toEqual [1, 0]
|
||||
Reference in New Issue
Block a user