mirror of
https://github.com/atom/atom.git
synced 2026-01-24 06:18:03 -05:00
Change case of prefix and suffix to matched word
Previously an inserted automcomplete match would not update the case of the prefix or suffix of the match and instead only insert the text from the matched word between the prefix and suffix. Now the entire matched word is inserted as-is replacing the existing prefix and suffix.
This commit is contained in:
@@ -11,6 +11,11 @@ class Range
|
||||
else
|
||||
new Range(object.start, object.end)
|
||||
|
||||
@fromPointWithDelta: (point, rowDelta, columnDelta) ->
|
||||
pointA = Point.fromObject(point)
|
||||
pointB = new Point(point.row + rowDelta, point.column + columnDelta)
|
||||
new Range(pointA, pointB)
|
||||
|
||||
constructor: (pointA = new Point(0, 0), pointB = new Point(0, 0)) ->
|
||||
pointA = Point.fromObject(pointA)
|
||||
pointB = Point.fromObject(pointB)
|
||||
|
||||
@@ -96,6 +96,15 @@ describe "Autocomplete", ->
|
||||
expect(autocomplete.matchesList.find('li').length).toBe 1
|
||||
expect(autocomplete.matchesList.find('li:eq(0)')).toHaveText "No matches found"
|
||||
|
||||
it "autocompletes word and replaces case of prefix with case of word", ->
|
||||
editor.getBuffer().insert([10,0] ,"extra:SO:extra")
|
||||
editor.setCursorBufferPosition([10,8])
|
||||
autocomplete.attach()
|
||||
|
||||
expect(editor.lineForBufferRow(10)).toBe "extra:sort:extra"
|
||||
expect(editor.getCursorBufferPosition()).toEqual [10,10]
|
||||
expect(editor.getSelection().isEmpty()).toBeTruthy()
|
||||
|
||||
describe "when text is selected", ->
|
||||
it 'autocompletes word when there is only a prefix', ->
|
||||
editor.getBuffer().insert([10,0] ,"extra:sort:extra")
|
||||
@@ -399,5 +408,3 @@ describe "Autocomplete", ->
|
||||
|
||||
editor.trigger 'core:move-up'
|
||||
expect(editor.getCursorBufferPosition().row).toBe 0
|
||||
|
||||
|
||||
|
||||
@@ -185,11 +185,10 @@ class Autocomplete extends View
|
||||
{prefix, suffix} = @prefixAndSuffixOfSelection(selection)
|
||||
|
||||
if (prefix.length + suffix.length) > 0
|
||||
regex = new RegExp("^#{prefix}(.+)#{suffix}$", "i")
|
||||
regex = new RegExp("^#{prefix}.+#{suffix}$", "i")
|
||||
currentWord = prefix + @editor.getSelectedText() + suffix
|
||||
for word in @wordList when regex.test(word) and word != currentWord
|
||||
match = regex.exec(word)
|
||||
{prefix, suffix, word, infix: match[1]}
|
||||
{prefix, suffix, word}
|
||||
else
|
||||
[]
|
||||
|
||||
@@ -197,9 +196,15 @@ class Autocomplete extends View
|
||||
selection = @editor.getSelection()
|
||||
startPosition = selection.getBufferRange().start
|
||||
@isAutocompleting = true
|
||||
@editor.insertText(match.infix)
|
||||
buffer = @editor.getBuffer()
|
||||
@editor.activeEditSession.transact =>
|
||||
selection.deleteSelectedText()
|
||||
buffer.delete(Range.fromPointWithDelta(@editor.getCursorBufferPosition(), 0, -match.prefix.length))
|
||||
buffer.delete(Range.fromPointWithDelta(@editor.getCursorBufferPosition(), 0, match.suffix.length))
|
||||
@editor.insertText(match.word)
|
||||
|
||||
@currentMatchBufferRange = [startPosition, [startPosition.row, startPosition.column + match.infix.length]]
|
||||
infixLength = match.word.length - match.prefix.length - match.suffix.length
|
||||
@currentMatchBufferRange = [startPosition, [startPosition.row, startPosition.column + infixLength]]
|
||||
@editor.setSelectedBufferRange(@currentMatchBufferRange)
|
||||
@isAutocompleting = false
|
||||
|
||||
|
||||
Reference in New Issue
Block a user