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

Stop registering SuggestionListElement as a custom element - #826

Merged
as-cii merged 10 commits into
masterfrom
as-remove-custom-elements
Mar 14, 2017
Merged

as-cii merged 10 commits into
masterfrom
as-remove-custom-elements

Conversation

@as-cii

@as-cii as-cii commented Mar 3, 2017

Copy link
Copy Markdown
Contributor

This pull request stops registering custom elements during startup and uses simple javascript objects that internally manage a DOM element instead.

/cc: @ungb for 👀

Comment thread lib/suggestion-list.js
editorElement.classList.add('autocomplete-active')
}

process.nextTick(() => { this.suggestionListElement.didAttach() })

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@joefitzgerald: what do you think about using process.nextTick here? Removing custom elements also prevents us from detecting when the element has been attached. In this case, we will simply signal SuggestionListElement that it has been attached on the next tick of the event loop.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure - are there any negative implications?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so, but ideally we would do this in a atom.views.updateDocument callback. I guess it should be fine, because we still schedule an animation frame as part of render() which is called in didAttach().

@ungb

ungb commented Mar 13, 2017 •

Copy link
Copy Markdown
Contributor

I was able to see auto complete working, but when I tested on js files before and after and saw different results pop up.

see screenshot:
different

@as-cii

as-cii commented Mar 13, 2017

Copy link
Copy Markdown
Contributor Author

Interesting, this shouldn't change the behavior of the suggestion list. Did you have a set of different files open in the second screenshot?

@ungb

ungb commented Mar 13, 2017

Copy link
Copy Markdown
Contributor

AH, sorry, I think I did, when I have the same files open I see the same. I didn't realize that was what taken to account. I didn't see any issues after this clarification. Thanks! LGTM

Comment thread lib/suggestion-list.js
}

showAtBeginningOfPrefix (editor, prefix, followRawPrefix = false) {
if (!editor) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't an early return with no nesting of meaningful code preferable to the alternative in this function?

Comment thread lib/suggestion-list.js
const marker = this.suggestionMarker = editor.markBufferRange([bufferPosition, bufferPosition])
this.overlayDecoration = editor.decorateMarker(marker, {type: 'overlay', item: this, position: 'tail'})
this.addBindings(editor)
if (editor) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This nesting is unnecessary if we exit early when editor is falsy.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really, because we need to call destroyOverlay if the editor is not the same. I guess we could have an early return that calls destroyOverlay, but I'm not sure if that would be clearer.

Comment thread lib/suggestion-list.js
editorElement.classList.add('autocomplete-active')
}

process.nextTick(() => { this.suggestionListElement.didAttach() })

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure - are there any negative implications?

return atom.views.readDocument(this.readUIPropsFromDOM.bind(this))
}

addActiveClassToEditor () {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm trying to recall why we needed to add this. Why are we able to remove it now?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because we add the active class to the editor above in the call stack, in the showAtBeginningOfPrefix and showAtCursorPosition methods, where we also create the overlay decoration.

@as-cii

as-cii commented Mar 14, 2017

Copy link
Copy Markdown
Contributor Author

Thank you @joefitzgerald and @ungb! ❤️ I think I will go ahead and merge this and let it can bake for a while on master.

@as-cii
as-cii merged commit 3bbac67 into master Mar 14, 2017
@as-cii
as-cii deleted the as-remove-custom-elements branch March 14, 2017 14:04
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants