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

onTextInput not triggered on tab #400

Closed
martinklepsch opened this issue May 12, 2016 · 1 comment
Closed

onTextInput not triggered on tab #400

martinklepsch opened this issue May 12, 2016 · 1 comment

Comments

@martinklepsch
Copy link
Contributor

quoting @bantic

This can probably be fixed simply by removing the special-handling of tab in the keydown handler here https://github.com/bustlelabs/mobiledoc-kit/blob/master/src/js/editor/event-manager.js#L142

bantic added a commit that referenced this issue Aug 30, 2016
Change the event manager to delegate insertion of tab key to the input
handler rather than simply inserting the string.

Also: Lot of cleanup to tests.

Fixes #400
bantic added a commit that referenced this issue Aug 30, 2016
Change the event manager to delegate insertion of tab key to the input
handler rather than simply inserting the string.

Also: Lot of cleanup to tests.

Fixes #400
bantic added a commit that referenced this issue Aug 31, 2016
…479)

Change the event manager to delegate insertion of tab key to the input
handler rather than simply inserting the string.

Also: Lot of cleanup to tests.

Fixes #400
johnelliott pushed a commit to dailybeast/mobiledoc-kit that referenced this issue Feb 7, 2017
…ustle#479)

Change the event manager to delegate insertion of tab key to the input
handler rather than simply inserting the string.

Also: Lot of cleanup to tests.

Fixes bustle#400
@miguelcobain
Copy link
Contributor

@bantic I believe the same is happening with line breaks.
If we use the usual handler to linkify, it doesn't run if you type enter after the link.

    editor.onTextInput({
      name: 'linkify',
      match: /\b(https?:\/\/[^\s]+)\s$/,
      run(editor, matches) {
        let url = matches[0];
        // the editor's current range is the cursor position, 1
        // character after the URL (to account for the space).
        // Keep a reference to this range so that it can be restored later
        let currentRange = editor.range;
        // 1. Create a logical range containing the URL.
        // Move the range 1 space backward (to skip over the space), and
        // then extend it backward the length of the URL:
        let linkRange = currentRange.move(-1).extend(-url.length);
        // 2. Create the markup
        let linkMarkup = editor.builder.createMarkup('a', { href: url });
        // 3. apply the markup to the range
        editor.run((postEditor) => {
          postEditor.addMarkupToRange(linkRange, linkMarkup);
        });
        // 4. restore the cursor position
        editor.selectRange(currentRange);
      }
    });

Since we're using \s on the regex, it should match the newline.

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