Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { ChangeSource } from 'roosterjs-content-model-dom';
import { checkAndInsertHorizontalLine } from './horizontalLine/checkAndInsertHorizontalLine';
import { createLink } from './link/createLink';
import { formatTextSegmentBeforeSelectionMarker, promoteLink } from 'roosterjs-content-model-api';
import { getListTypeStyle } from './list/getListTypeStyle';
import { keyboardListTrigger } from './list/keyboardListTrigger';
import { transformFraction } from './numbers/transformFraction';
import { transformHyphen } from './hyphen/transformHyphen';
Expand Down Expand Up @@ -100,6 +101,42 @@ export class AutoFormatPlugin implements EditorPlugin {
this.editor = null;
}

private shouldHandleInputEventExclusively(editor: IEditor, event: EditorInputEvent) {
const rawEvent = event.rawEvent;
const selection = editor.getDOMSelection();
let shouldHandle = false;
if (
rawEvent.inputType === 'insertText' &&
selection &&
selection.type === 'range' &&
selection.range.collapsed &&
rawEvent.data == ' '
) {
formatTextSegmentBeforeSelectionMarker(editor, (model, previousSegment, paragraph) => {
const { autoLink, autoTel, autoMailto, autoBullet, autoNumbering } = this.options;
const list = getListTypeStyle(model, autoBullet, autoNumbering);
const link = promoteLink(previousSegment, paragraph, {
autoLink,
autoTel,
autoMailto,
});
shouldHandle = !!link || !!list;
return false;
});
}
return shouldHandle;
}

willHandleEventExclusively(event: PluginEvent) {
if (this.editor) {
switch (event.eventType) {
case 'input':
return this.shouldHandleInputEventExclusively(this.editor, event);
}
}
return false;
}

/**
* Core method for a plugin. Once an event happens in editor, editor will call this
* method of each plugin to handle the event as long as the event is not handled
Expand Down
Loading
Loading