Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

Commit

Permalink
Don't hide suggestion list for text change not at cursor position
Browse files Browse the repository at this point in the history
If the suggestion list is displayed, and the user enters a newline, we
currently hide (i.e., dismiss) the suggestion list. That makes sense,
and we want to retain that behavior. However, if a text change occurs
_elsewhere_ in the buffer (e.g., automated tooling that adds semicolons
at the end of each line of code in JavaScript), that change shouldn't
interfere with a human user interacting with the autocomplete suggestion
list. With this change, we only hide the suggestion list if a text
change occurs at the cursor where the human user is interacting with
the autocomplete selection list.
  • Loading branch information
jasonrudolph committed Sep 12, 2017
1 parent 9e7f364 commit 05d33f8
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 9 deletions.
14 changes: 8 additions & 6 deletions lib/autocomplete-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -701,12 +701,14 @@ See https://github.com/atom/autocomplete-plus/wiki/Provider-API`
return newRange.containsPoint(lastCursorPosition)
})

if (this.shouldActivate && changeOccurredNearLastCursor) {
this.cancelHideSuggestionListRequest()
this.requestNewSuggestions()
} else {
this.cancelNewSuggestionsRequest()
this.hideSuggestionList()
if (changeOccurredNearLastCursor) {
if (this.shouldActivate) {
this.cancelHideSuggestionListRequest()
this.requestNewSuggestions()
} else {
this.cancelNewSuggestionsRequest()
this.hideSuggestionList()
}
}

this.shouldActivate = false
Expand Down
22 changes: 19 additions & 3 deletions spec/autocomplete-manager-integration-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -585,18 +585,34 @@ describe('Autocomplete Manager', () => {
})

describe('when the character entered is not at the cursor position', () => {
beforeEach(() => {
it('does not show the suggestion list', () => {
editor.setText('some text ok')
editor.setCursorBufferPosition([0, 7])
})

it('does not show the suggestion list', () => {
let buffer = editor.getBuffer()
buffer.setTextInRange([[0, 0], [0, 0]], 's')
waitForAutocomplete()

runs(() => expect(editorView.querySelector('.autocomplete-plus')).not.toExist())
})

it('does not hide the suggestion list', () => {
editor.setText(
'0\n' +
'1\n'
)
editor.setCursorBufferPosition([2, 0])
editor.insertText('2')
waitForAutocomplete()

runs(() => {
expect(editorView.querySelector('.autocomplete-plus')).toExist()
editor.setTextInBufferRange([[0, 0], [0, 0]], '*')
expect(editorView.querySelector('.autocomplete-plus')).toExist()
editor.setTextInBufferRange([[0, 0], [0, 0]], '\n')
expect(editorView.querySelector('.autocomplete-plus')).toExist()
})
})
})

describe('when number of suggestions > maxVisibleSuggestions', () => {
Expand Down

0 comments on commit 05d33f8

Please sign in to comment.