Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add autocompletion with Zotero snippets to ACE #71

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

zuphilip
Copy link
Collaborator

@zuphilip zuphilip commented Feb 4, 2018

We should first merge #70.

This is a proof-of-concept for #69 for opening a round of feedback.

@zuphilip zuphilip changed the title WIP: Add autocompletion with Zotero snippets to ACE Add autocompletion with Zotero snippets to ACE Feb 11, 2018
@zuphilip
Copy link
Collaborator Author

Here is a short demo:

2018-02-11_18-25-10

I am happy with this now. Any feedback @dstillman, @adam3smith?

},
{
content: "var item = new Zotero.Item(${1:itemType});",
name: "new Zotero.Item"
Copy link
Member

Choose a reason for hiding this comment

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

I think it's best to actually treat these as autocompletes, not shortcuts, so it shouldn't autocomplete to something before what you've actually typed (var item = in this case). The full string could be a different snippet.

var ZoteroCompleter = {
getCompletions: function(editor, session, pos, prefix, callback) {
callback(null, [
{value: "ZU.cleanAuthor", score: 1000, meta: "Zotero Utility function"},
Copy link
Member

Choose a reason for hiding this comment

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

Is this meta required? These seem a bit redundant. (If they need to stay, Utility should be lowercased.)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Not sure, but it shows up in the suggestion selector, e.g.

ace-autocompletion-meta

]);
}
}
var langTools = require("ace/ext/language_tools");
Copy link
Member

Choose a reason for hiding this comment

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

Be sure to document the source of that file in the commit.

<hbox id="editor-external-box" align="center">
<checkbox id="checkbox-editor-external"/>
<label class="label-metadata" value="&scaffold.editor.external.label;" control="checkbox-editor-external"/>
<checkbox id="checkbox-live-autocompletion"/>
<label class="label-metadata" value="&scaffold.editor.liveAutocompletion.label;"/>
Copy link
Member

Choose a reason for hiding this comment

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

I think this can just be on rather than configurable. If someone doesn't want it, they're probably not editing in ACE to begin with.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

There is also the basic autocompletion which is invoked with ctrl+space (at least in windows) which is always activated.

The live autocompletion is IMO sometimes a little disturbing, e.g. I type a in the editor and get suggestions for ZU.cleanAuthor, Z.monitorDOMChanges, ZU.xpath etc. Try it out yourself at http://plnkr.co/edit/Ep3bVPjjkm1laImq443t?p=preview .

Moreover, any feedback from @adam3smith would be appreciated about this.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, I've tried it. If we're going to have it at all, I think it's more awkward to have to turn it on and off.

Copy link
Member

Choose a reason for hiding this comment

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

But also that just sounds like bad autocomplete. It shouldn't trigger ZU.cleanAuthor when you type a. Can we make it left-bound?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Make it left-bound or wait for at least 2-3 characters could work better, but I haven't found anything like this (but it is very hard to find information at all).

The live autocompletion is also disabled in the official demo https://ace.c9.io/build/kitchen-sink.html

Copy link
Member

Choose a reason for hiding this comment

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

Minimum length is a good idea. Assuming we can get to them from the outside, I suspect we can monkey patch getCompletionPrefix or retrievePrecedingIdentifier to do that.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

They may even take such a patch into their official repo, which we could then simply reuse the official way. However, that is not something I can do currently.

Copy link
Member

Choose a reason for hiding this comment

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

That's fine — I can look into this. But I think we should assume we'll have less annoying autocomplete and not bother with a checkbox for it.

@@ -0,0 +1,47 @@
These special Zotero functions are most frequent used in translator coding, for autocompletion try also ctrl+space during writing.
Copy link
Member

Choose a reason for hiding this comment

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

These are the most common functions used in Zotero translators.

Does the second part only apply if the live option is off?

var snippetManager = ace.require("ace/snippets").snippetManager;
snippets = [{
content: "for (let i=0; i<${1:arrayName}.length; i++) {\n\t${2:// continue here}\n}\n",
name: "simple for loop"
Copy link
Member

Choose a reason for hiding this comment

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

If we're going to bother with stuff like this, probably better to default to for...of, with two placeholders.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants