mirror of
https://github.com/atom/atom.git
synced 2026-01-22 21:38:10 -05:00
Display matches when more than one tag is found
This commit is contained in:
3
spec/fixtures/tagged-duplicate.js
vendored
Normal file
3
spec/fixtures/tagged-duplicate.js
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
function duplicate() {
|
||||
return false;
|
||||
}
|
||||
6
spec/fixtures/tagged.js
vendored
6
spec/fixtures/tagged.js
vendored
@@ -4,4 +4,8 @@ function callMeMaybe() {
|
||||
return "here's my number";
|
||||
}
|
||||
|
||||
var iJustMetYou = callMeMaybe()
|
||||
var iJustMetYou = callMeMaybe();
|
||||
|
||||
function duplicate() {
|
||||
return true;
|
||||
}
|
||||
|
||||
3
spec/fixtures/tags
vendored
3
spec/fixtures/tags
vendored
@@ -5,3 +5,6 @@
|
||||
!_TAG_PROGRAM_URL http://ctags.sourceforge.net /official site/
|
||||
!_TAG_PROGRAM_VERSION 5.8 //
|
||||
callMeMaybe tagged.js /^function callMeMaybe() {$/;" f
|
||||
duplicate tagged-duplicate.js /^function duplicate() {$/;" f
|
||||
duplicate tagged.js /^function duplicate() {$/;" f
|
||||
thisIsCrazy tagged.js /^var thisIsCrazy = true;$/;" v
|
||||
|
||||
@@ -129,9 +129,9 @@ describe "OutlineView", ->
|
||||
it "doesn't move the cursor when no declaration is found", ->
|
||||
rootView.open("tagged.js")
|
||||
editor = rootView.getActiveEditor()
|
||||
editor.setCursorBufferPosition([0,12])
|
||||
editor.setCursorBufferPosition([0,2])
|
||||
editor.trigger 'outline-view:jump-to-declaration'
|
||||
expect(editor.getCursorBufferPosition()).toEqual [0,12]
|
||||
expect(editor.getCursorBufferPosition()).toEqual [0,2]
|
||||
|
||||
it "moves the cursor to the declaration", ->
|
||||
rootView.open("tagged.js")
|
||||
@@ -139,3 +139,14 @@ describe "OutlineView", ->
|
||||
editor.setCursorBufferPosition([6,24])
|
||||
editor.trigger 'outline-view:jump-to-declaration'
|
||||
expect(editor.getCursorBufferPosition()).toEqual [2,0]
|
||||
|
||||
it "displays matches when more than one exists and opens the selected match", ->
|
||||
rootView.open("tagged.js")
|
||||
editor = rootView.getActiveEditor()
|
||||
editor.setCursorBufferPosition([8,14])
|
||||
editor.trigger 'outline-view:jump-to-declaration'
|
||||
expect(outlineView.list.children('li').length).toBe 2
|
||||
expect(outlineView).toBeVisible()
|
||||
outlineView.confirmed(outlineView.array[0])
|
||||
expect(rootView.getActiveEditor().getPath()).toBe rootView.project.resolve("tagged-duplicate.js")
|
||||
expect(rootView.getActiveEditor().getCursorBufferPosition()).toEqual [0,4]
|
||||
|
||||
@@ -4,6 +4,8 @@ Editor = require 'editor'
|
||||
TagGenerator = require 'outline-view/src/tag-generator'
|
||||
TagReader = require 'outline-view/src/tag-reader'
|
||||
Point = require 'point'
|
||||
fs = require 'fs'
|
||||
$ = require 'jquery'
|
||||
|
||||
module.exports =
|
||||
class OutlineView extends SelectList
|
||||
@@ -51,8 +53,12 @@ class OutlineView extends SelectList
|
||||
@setError("No symbols found")
|
||||
setTimeout (=> @detach()), 2000
|
||||
|
||||
confirmed : ({position, name}) ->
|
||||
confirmed : (tag) ->
|
||||
@cancel()
|
||||
@openTag(tag)
|
||||
|
||||
openTag: ({position, file}) ->
|
||||
@rootView.openInExistingEditor(file, true, true) if file
|
||||
@moveToPosition(position)
|
||||
|
||||
moveToPosition: (position) ->
|
||||
@@ -69,17 +75,29 @@ class OutlineView extends SelectList
|
||||
@rootView.append(this)
|
||||
@miniEditor.focus()
|
||||
|
||||
getTagLine: (tag) ->
|
||||
pattern = tag.pattern?.replace(/(^^\/\^)|(\$\/$)/g, '') # Remove leading /^ and trailing $/
|
||||
return unless pattern
|
||||
for line, index in fs.read(@rootView.project.resolve(tag.file)).split('\n')
|
||||
return new Point(index, 0) if pattern is $.trim(line)
|
||||
|
||||
jumpToDeclaration: ->
|
||||
editor = @rootView.getActiveEditor()
|
||||
matches = TagReader.find(editor)
|
||||
return unless matches.length is 1
|
||||
return unless matches.length
|
||||
|
||||
tag = matches[0]
|
||||
return unless tag.pattern
|
||||
pattern = tag.pattern.replace(/(^^\/\^)|(\$\/$)/g, '') # Remove leading /^ and trailing $/
|
||||
if pattern and @rootView.openInExistingEditor(tag.file, true, true)
|
||||
buffer = editor.getBuffer()
|
||||
for row in [0...buffer.getLineCount()]
|
||||
continue unless pattern is buffer.lineForRow(row)
|
||||
@moveToPosition(new Point(row, 0))
|
||||
break
|
||||
if matches.length is 1
|
||||
position = @getTagLine(matches[0])
|
||||
@openTag(file: matches[0].file, position: position) if position
|
||||
else
|
||||
tags = []
|
||||
for match in matches
|
||||
position = @getTagLine(match)
|
||||
continue unless position
|
||||
tags.push
|
||||
file: match.file
|
||||
name: fs.base(match.file)
|
||||
position: position
|
||||
@miniEditor.show()
|
||||
@setArray(tags)
|
||||
@attach()
|
||||
|
||||
@@ -31,8 +31,5 @@
|
||||
color: #ddd;
|
||||
-webkit-border-radius: 3px;
|
||||
padding: 0 4px;
|
||||
}
|
||||
|
||||
.outline-view ol .function-line {
|
||||
background: rgba(0, 0, 0, .2);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user