Skip to content
This repository was archived by the owner on Nov 18, 2017. It is now read-only.
This repository was archived by the owner on Nov 18, 2017. It is now read-only.

Fails to insert mention if no suggestion is specified. #10

Description

@jameskraus

If no suggestion is specified, this block of code fails to insert a suggestion.

          var selected = Math.abs(editor.state[_constants.SELECTED_MENTION_INDEX_KEY]); // selected = 0
          var text = suggestions[selected % suggestions.length || 0]; // text = undefined
          var at = (0, _utils.nearestAt)(state.endText.text, state.selection.startOffset);
          var mentionLength = state.selection.startOffset - at - 1;

          // Remove the current, incomplete text and replace it with the selected suggestion
          return state.transform().deleteBackward(mentionLength).insertText(text).removeMark('mention').insertText(' ').focus().apply(); // fails to insert `undefined` text

I get this error: Cannot read property 'length' of undefined

To reproduce, just enter an @mention that doesn't exist in the example and it will throw the error.

The two normal ways of handling this are to either create an ad-hoc mention or to not allow the user to create the mention at all. Considering the generality of this library, it seems appropriate to handle both cases?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions