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

Incorrect Typing of parameter in "onSelection" #30

Closed
MartinHaeusler opened this issue Oct 30, 2017 · 2 comments
Closed

Incorrect Typing of parameter in "onSelection" #30

MartinHaeusler opened this issue Oct 30, 2017 · 2 comments

Comments

@MartinHaeusler
Copy link

According to the type information provided by react-codemirror2, the onSelection callback is defined as follows:

onSelection?: (editor: IInstance, ranges: ISetSelectionOptions) => void;

... where ISetSelectionOptions is defined as:

export interface ISetSelectionOptions {
    anchor: codemirror.Position;
    head: codemirror.Position;
}

However, when the listener is actually fired during runtime, the object I receive as the ranges parameter does not match the type outlined above. It is:

image

It's an object with a property ranges, which in turn is an array of ISetSelectionOptions.

I am using:

  • react-codemirror2: 3.0.3
  • codemirror: 5.31.0
scniro added a commit that referenced this issue Nov 3, 2017
scniro added a commit that referenced this issue Nov 3, 2017
@scniro
Copy link
Owner

scniro commented Nov 3, 2017

This should now be fixed with the 3.0.7 release. I've added this my list of issues to take up with @types/codemirror as there are quite a few incorrect signatures that I've need to hack my way around. E.g. this is what I have to work with from them...

on(doc: Doc, 
   eventName: 'beforeSelectionChange', 
   handler: (instance: CodeMirror.Editor, 
   selection: { head: Position; anchor: Position; }) => void ): void;

yet, and as you found out, codemirror actually returns something different...

"beforeSelectionChange" (instance: CodeMirror, obj: {ranges, origin, update})

Workaround is in place for now though

@scniro
Copy link
Owner

scniro commented Nov 6, 2017

Closing for now, please re-open should this remain problematic

@scniro scniro closed this as completed Nov 6, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants