mirror of
https://github.com/atom/atom.git
synced 2026-04-06 03:02:13 -04:00
12
src/packages/jump-to-line/index.coffee
Normal file
12
src/packages/jump-to-line/index.coffee
Normal file
@@ -0,0 +1,12 @@
|
||||
DeferredAtomPackage = require 'deferred-atom-package'
|
||||
|
||||
module.exports =
|
||||
class JumpToLinePackage extends DeferredAtomPackage
|
||||
|
||||
loadEvents:
|
||||
'editor:jump-to-line': '.editor'
|
||||
|
||||
instanceClass: 'jump-to-line/lib/jump-to-line-view'
|
||||
|
||||
onLoadEvent: (event, instance) ->
|
||||
instance.toggle(event.currentTargetView())
|
||||
6
src/packages/jump-to-line/keymaps/jump-to-line.cson
Normal file
6
src/packages/jump-to-line/keymaps/jump-to-line.cson
Normal file
@@ -0,0 +1,6 @@
|
||||
'body':
|
||||
'meta-l': 'editor:jump-to-line'
|
||||
'.jump-to-line .mini.editor input':
|
||||
'enter': 'core:confirm',
|
||||
'escape': 'core:cancel'
|
||||
'meta-w': 'core:cancel'
|
||||
52
src/packages/jump-to-line/lib/jump-to-line-view.coffee
Normal file
52
src/packages/jump-to-line/lib/jump-to-line-view.coffee
Normal file
@@ -0,0 +1,52 @@
|
||||
{View} = require 'space-pen'
|
||||
Editor = require 'editor'
|
||||
$ = require 'jquery'
|
||||
Point = require 'point'
|
||||
|
||||
module.exports =
|
||||
class JumpToLineView extends View
|
||||
|
||||
@activate: (rootView) -> new JumpToLineView(rootView)
|
||||
|
||||
@content: ->
|
||||
@div class: 'jump-to-line', =>
|
||||
@subview 'miniEditor', new Editor(mini: true)
|
||||
@div class: 'message', outlet: 'message'
|
||||
|
||||
initialize: (@rootView) ->
|
||||
@miniEditor.on 'focusout', => @detach() if @hasParent()
|
||||
@on 'core:confirm', => @confirm()
|
||||
@on 'core:cancel', => @detach() if @hasParent()
|
||||
|
||||
@miniEditor.preempt 'textInput', (e) =>
|
||||
false unless e.originalEvent.data.match(/[0-9]/)
|
||||
|
||||
toggle: ->
|
||||
if @hasParent()
|
||||
@detach()
|
||||
else
|
||||
@attach()
|
||||
|
||||
detach: ->
|
||||
@miniEditor.setText('')
|
||||
@previouslyFocusedElement?.focus()
|
||||
|
||||
super
|
||||
|
||||
confirm: ->
|
||||
lineNumber = @miniEditor.getText()
|
||||
editor = rootView.getActiveEditor()
|
||||
|
||||
@detach()
|
||||
|
||||
return unless editor and lineNumber.length
|
||||
position = new Point(parseInt(lineNumber - 1, 0))
|
||||
editor.scrollToBufferPosition(position, center: true)
|
||||
editor.setCursorBufferPosition(position)
|
||||
editor.moveCursorToFirstCharacterOfLine()
|
||||
|
||||
attach: ->
|
||||
@previouslyFocusedElement = $(':focus')
|
||||
@rootView.append(this)
|
||||
@message.text("Enter a line number 1-#{@editor.getLineCount()}")
|
||||
@miniEditor.focus()
|
||||
41
src/packages/jump-to-line/spec/jump-to-line-spec.coffee
Normal file
41
src/packages/jump-to-line/spec/jump-to-line-spec.coffee
Normal file
@@ -0,0 +1,41 @@
|
||||
RootView = require 'root-view'
|
||||
|
||||
describe 'JumpToLine', ->
|
||||
[rootView, jumpToLine, editor] = []
|
||||
|
||||
beforeEach ->
|
||||
rootView = new RootView(require.resolve('fixtures/sample.js'))
|
||||
rootView.enableKeymap()
|
||||
jumpToLine = atom.loadPackage("jump-to-line").getInstance()
|
||||
editor = rootView.getActiveEditor()
|
||||
editor.setCursorBufferPosition([1,0])
|
||||
|
||||
afterEach ->
|
||||
rootView.remove()
|
||||
|
||||
describe "when entering a line number", ->
|
||||
it "only allows 0-9 to be entered in the mini editor", ->
|
||||
expect(jumpToLine.miniEditor.getText()).toBe ''
|
||||
jumpToLine.miniEditor.textInput 'a'
|
||||
expect(jumpToLine.miniEditor.getText()).toBe ''
|
||||
jumpToLine.miniEditor.textInput '40'
|
||||
expect(jumpToLine.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", ->
|
||||
jumpToLine.miniEditor.textInput '3'
|
||||
jumpToLine.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", ->
|
||||
jumpToLine.miniEditor.trigger 'core:confirm'
|
||||
expect(jumpToLine.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", ->
|
||||
jumpToLine.miniEditor.trigger 'core:cancel'
|
||||
expect(jumpToLine.hasParent()).toBeFalsy()
|
||||
expect(editor.getCursorBufferPosition()).toEqual [1, 0]
|
||||
27
themes/Atom - Dark/jump-to-line.css
Normal file
27
themes/Atom - Dark/jump-to-line.css
Normal file
@@ -0,0 +1,27 @@
|
||||
.jump-to-line {
|
||||
position: absolute;
|
||||
width: 200px;
|
||||
top: 0;
|
||||
left: 50%;
|
||||
margin-left: -100px;
|
||||
box-sizing: border-box;
|
||||
z-index: 99;
|
||||
background-color: #484848;
|
||||
border: 1px solid #444;
|
||||
color: #d2d2d2;
|
||||
box-shadow: 0 0 10px #000;
|
||||
border-bottom-left-radius: 3px;
|
||||
border-bottom-right-radius: 3px;
|
||||
padding: 5px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.jump-to-line .editor {
|
||||
box-sizing: border-box;
|
||||
padding: 5px;
|
||||
}
|
||||
|
||||
.jump-to-line .message {
|
||||
padding-top: 2px;
|
||||
font-size: 11px;
|
||||
}
|
||||
@@ -15,6 +15,7 @@
|
||||
"command-palette.css",
|
||||
"command-logger.css",
|
||||
"autocomplete.css",
|
||||
"gists.css"
|
||||
"gists.css",
|
||||
"jump-to-line.css"
|
||||
]
|
||||
}
|
||||
|
||||
27
themes/Atom - Light/jump-to-line.css
Normal file
27
themes/Atom - Light/jump-to-line.css
Normal file
@@ -0,0 +1,27 @@
|
||||
.jump-to-line {
|
||||
position: absolute;
|
||||
width: 200px;
|
||||
top: 0;
|
||||
left: 50%;
|
||||
margin-left: -100px;
|
||||
box-sizing: border-box;
|
||||
z-index: 99;
|
||||
background-color: #eeeeee;
|
||||
border: 1px solid #c6c6c6;
|
||||
color: #323232;
|
||||
box-shadow: 0 0 10px #555;
|
||||
border-bottom-left-radius: 3px;
|
||||
border-bottom-right-radius: 3px;
|
||||
padding: 5px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.jump-to-line .editor {
|
||||
box-sizing: border-box;
|
||||
padding: 5px;
|
||||
}
|
||||
|
||||
.jump-to-line .message {
|
||||
padding-top: 2px;
|
||||
font-size: 11px;
|
||||
}
|
||||
@@ -15,6 +15,7 @@
|
||||
"command-palette.css",
|
||||
"command-logger.css",
|
||||
"autocomplete.css",
|
||||
"gists.css"
|
||||
"gists.css",
|
||||
"jump-to-line.css"
|
||||
]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user