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

"pick" event for hint doesn't seem to fire properly. #4729

Closed
danostrowski opened this Issue May 6, 2017 · 4 comments

Comments

Projects
None yet
2 participants
@danostrowski

danostrowski commented May 6, 2017

I registered a helper for hint.. (CodeMirror.registerHelper("hint", "lua", function() ...)

and I got it working, but the "pick" event described in the docs didn't fire when I hooked up this:

    var editor = CodeMirror.fromTextArea( ... )
    editor.on('pick', function(comp) {
        console.log('selected: ' + comp);
    });

If you look at the code here: https://github.com/codemirror/CodeMirror/blob/master/addon/hint/show-hint.js#L88

... you'll see that the first parameter to signal seems to be data, which is what is returned from my helper.

However, if I change "data" to "this.cm" ... the signal I connected then works.

Which seems logical, the editor should be the object sending the signal. There are other places in show-hint.js where signals are sent with data instead of a CodeMirror instance, too, so I think it's a pervasive problem.

Anyhow, maybe I'm wrong but this is what worked for me.

@marijnh

This comment has been minimized.

Show comment
Hide comment
@marijnh

marijnh May 6, 2017

Member

Hi, you should register the handler this on the completion result, i.e. on the object that's returned from your hint source function. There is an endCompletion event fired on the editor object, but that only happens after completion finishes, and doesn't allow you to intercept the effect of the completion.

Member

marijnh commented May 6, 2017

Hi, you should register the handler this on the completion result, i.e. on the object that's returned from your hint source function. There is an endCompletion event fired on the editor object, but that only happens after completion finishes, and doesn't allow you to intercept the effect of the completion.

@marijnh marijnh closed this May 6, 2017

@danostrowski

This comment has been minimized.

Show comment
Hide comment
@danostrowski

danostrowski May 6, 2017

Thanks for the reply!

OK, so you would do something like CodeMirror.on(result, 'signal', function(...)) ?

I can definitely do this, but this seems different than how other .on signal handling is for most of CodeMirror? At least it's not very obvious and I'm wondering if this needs to be in the documentation somewhere?

danostrowski commented May 6, 2017

Thanks for the reply!

OK, so you would do something like CodeMirror.on(result, 'signal', function(...)) ?

I can definitely do this, but this seems different than how other .on signal handling is for most of CodeMirror? At least it's not very obvious and I'm wondering if this needs to be in the documentation somewhere?

@marijnh

This comment has been minimized.

Show comment
Hide comment
@marijnh

marijnh May 7, 2017

Member

It is in the documentation, I assume that's where you got the event name from. The idea is that the place where you'd want to register these is the completion source, so they are local to that, not to the editor.

Member

marijnh commented May 7, 2017

It is in the documentation, I assume that's where you got the event name from. The idea is that the place where you'd want to register these is the completion source, so they are local to that, not to the editor.

@danostrowski

This comment has been minimized.

Show comment
Hide comment
@danostrowski

danostrowski May 7, 2017

Ah, OK, you're right it is, apologies. It says...

The following events will be fired on the completions object during completion

It's just very quickly mentioned and "completions object" is what's referenced above as:

and return a {list, from, to} object,

This all makes sense if you understand how the plugin works, but the documentation is pretty spartan and the "example" demo isn't very informative.

I got confused because the mention was so brief and the documentation for signals for CM is all referencing events from the editor.

danostrowski commented May 7, 2017

Ah, OK, you're right it is, apologies. It says...

The following events will be fired on the completions object during completion

It's just very quickly mentioned and "completions object" is what's referenced above as:

and return a {list, from, to} object,

This all makes sense if you understand how the plugin works, but the documentation is pretty spartan and the "example" demo isn't very informative.

I got confused because the mention was so brief and the documentation for signals for CM is all referencing events from the editor.

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