Skip to content

Commit

Permalink
trigger handlers without inserting newline
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelcobain committed Aug 20, 2018
1 parent 18d53a1 commit 71c438c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/js/editor/event-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ export default class EventManager {
break;
}
case key.isEnter():
this._textInputHandler.handleNewLine();
editor.handleNewline(event);
break;
case key.isTab():
Expand Down
16 changes: 14 additions & 2 deletions src/js/editor/text-input-handler.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { endsWith } from 'mobiledoc-kit/utils/string-utils';
import assert from 'mobiledoc-kit/utils/assert';
import deprecate from 'mobiledoc-kit/utils/deprecate';
import { ENTER } from 'mobiledoc-kit/utils/characters';

class TextInputHandler {
constructor(editor) {
Expand All @@ -24,6 +25,7 @@ class TextInputHandler {

handle(string) {
let { editor } = this;

editor.insertText(string);

let matchedHandler = this._findHandler();
Expand All @@ -33,9 +35,19 @@ class TextInputHandler {
}
}

_findHandler() {
handleNewLine() {
let { editor } = this;

let matchedHandler = this._findHandler(ENTER);
if (matchedHandler) {
let [ handler, matches ] = matchedHandler;
handler.run(editor, matches);
}
}

_findHandler(string = "") {
let { editor: { range: { head, head: { section } } } } = this;
let preText = section.textUntil(head);
let preText = section.textUntil(head) + string;

for (let i=0; i < this._handlers.length; i++) {
let handler = this._handlers[i];
Expand Down

0 comments on commit 71c438c

Please sign in to comment.