Skip to content

Commit

Permalink
7.1.2 Fix #218 (#219)
Browse files Browse the repository at this point in the history
* 7.1.2 Fix #218

* Fix typo
  • Loading branch information
JiuqingSong authored Feb 1, 2019
1 parent a0cfd76 commit 65a4817
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 9 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "roosterjs",
"version": "7.1.1",
"version": "7.1.2",
"description": "Framework-independent javascript editor",
"repository": {
"type": "git",
Expand Down
9 changes: 9 additions & 0 deletions packages/roosterjs-editor-api/lib/format/replaceWithNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,15 @@ export default function replaceWithNode(
if (range) {
let backupRange = editor.getSelectionRange();

// If the range to replace is rgith before current cursor, it is actually an exact match
if (
backupRange.collapsed &&
range.endContainer == backupRange.startContainer &&
range.endOffset == backupRange.startOffset
) {
exactMatch = true;
}

range.deleteContents();
range.insertNode(node);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
PluginEvent,
PluginEventType,
PluginKeyboardEvent,
ClipboardData,
} from 'roosterjs-editor-types';
import {
Editor,
Expand Down Expand Up @@ -43,6 +44,19 @@ function cacheGetLinkData(event: PluginEvent, editor: Editor): LinkData {
return event.eventType == PluginEventType.KeyDown ||
(event.eventType == PluginEventType.ContentChanged && event.source == ChangeSource.Paste)
? cacheGetEventData(event, 'LINK_DATA', () => {
// First try to match link from the whole paste string from the plain text in clipboard.
// This helps when we paste a link next to some existing character, and the text we got
// from clipboard will only contain what we pasted, any existing characters will not
// be included.
let clipboardData =
event.eventType == PluginEventType.ContentChanged &&
event.source == ChangeSource.Paste &&
(event.data as ClipboardData);
let link = matchLink((clipboardData.text || '').trim());
if (link) {
return link;
}

let searcher = cacheGetContentSearcher(event, editor);
let word = searcher && searcher.getWordBefore();
if (word && word.length > MINIMUM_LENGTH) {
Expand Down
4 changes: 1 addition & 3 deletions packages/roosterjs-editor-plugins/lib/Paste/Paste.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,7 @@ export default class Paste implements EditorPlugin {
image: items.image,
text: items.text,
rawHtml: items.html,
html: items.html
? this.sanitizeHtml(items.html)
: textToHtml(items.text, true /*parseLink*/),
html: items.html ? this.sanitizeHtml(items.html) : textToHtml(items.text),
});
});
};
Expand Down
8 changes: 3 additions & 5 deletions packages/roosterjs-editor-plugins/lib/Paste/textToHtml.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import { Browser, matchLink } from 'roosterjs-editor-dom';
import { Browser } from 'roosterjs-editor-dom';

var ZERO_WIDTH_SPACE = '​';

/**
* Convert plain to HTML
* @param text The plain text to convert
* @param parseLink True to parse hyperlink from the text and generate HTML A tag, otherwise false
* @returns HTML string to present the input text
*/
export default function textToHtml(text: string, parseLink?: boolean): string {
let linkData = parseLink && matchLink(text);
export default function textToHtml(text: string): string {
text = (text || '')
.replace(/&/g, '&')
.replace(/</g, '&lt;')
Expand All @@ -35,5 +33,5 @@ export default function textToHtml(text: string, parseLink?: boolean): string {
});
}
text = text.replace(/\s\s/g, ' &nbsp;');
return linkData ? `<a href="${linkData.normalizedUrl}">${text}</a>` : text;
return text;
}

0 comments on commit 65a4817

Please sign in to comment.