-
Notifications
You must be signed in to change notification settings - Fork 303
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
Insert HTML #337
Labels
Comments
+1 |
I found a solution. import { ContenteditableEditor } from "@textcomplete/contenteditable";
import {
SearchResult,
StrategyProps,
Textcomplete,
TextcompleteOption
} from "@textcomplete/core";
SearchResult.prototype.replace = function (
this: SearchResult,
beforeCursor: string,
afterCursor: string
): [DocumentFragment, DocumentFragment] | void {
let result = this.strategy.replace(this.data);
if (result == null) return;
if (Array.isArray(result)) {
afterCursor = result[1] + afterCursor;
result = result[0];
}
const match = this.strategy.match(beforeCursor);
if (match == null || match.index == null) return;
const fragment = document.createDocumentFragment();
fragment.append(
beforeCursor.slice(0, match.index),
result,
beforeCursor.slice(match.index + match[0].length)
);
const afterFragment = document.createDocumentFragment();
afterFragment.append(afterCursor);
return [fragment, afterFragment];
};
ContenteditableEditor.prototype.applySearchResult = function (
this: ContenteditableEditor,
searchResult
) {
const before = this.getBeforeCursor();
const after = this.getAfterCursor();
if (before != null && after != null) {
const replace = searchResult.replace(before, after) as [
DocumentFragment,
DocumentFragment
];
if (Array.isArray(replace)) {
const range = this.getRange() as Range;
range.selectNode(range.startContainer);
range.deleteContents();
const last = replace[0].lastChild;
range.insertNode(replace[1]);
range.insertNode(replace[0]);
range.detach();
const newRange = this.getRange();
newRange.setStartAfter(last);
newRange.collapse(true);
}
}
}; |
I have noticed that for string values sometimes the dropdown doesn't show. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi !
I switched from jquery-textcomplete to the new version but I can no longer paste html content in my contenteditable div, it is automatically escaped.
How can I solve my problem ?
I guess the problem is in the
ContenteditableEditor
file (applySearchResult
method) with insertTextThe text was updated successfully, but these errors were encountered: