2
私はTypescriptでコードを書いていますが、カーソルインデックスにTinyMCEにテキストを挿入しようとしています。挿入する文字列が異なるドロップダウンがあり、クリックして挿入したいブックマークでインデックスにTinyMCEにテキストを挿入するときの選択を失う
私は二回この関数を呼び出すと、インデックスの属性があり-1値をすべての私のテキストがereasedされるので、ブックマークが正しく選択を回復していないようです:
addCustomTag(tag: string) {
let bm = this._editor.selection.getBookmark(0);
let selector = "[data-mce-type=bookmark]";
let bmElements = this._editor.dom.select(selector);
this._editor.selection.select(bmElements[0]);
this._editor.selection.collapse();
let elementID = "######cursor######";
let cursorPosition = '<span id="' + elementID + '"></span>';
this._editor.selection.setContent(cursorPosition);
let content = this._editor.getContent({ format: "html" });
let index = content.indexOf(cursorPosition);
this._editor.dom.remove(elementID, false);
this._editor.selection.moveToBookmark(bm);
let tagToInsert = '((' + tag + '))';
let bookmark = this._editor.selection.getBookmark(0);
cursorPosition = '<span id="' + bookmark.id + '_start" data-mce-type="bookmark" data-mce-style="overflow:hidden;line-height:0px"></span>';
content = this._editor.getContent({ format: "html" });
let part1 = content.substr(0, index);
let part2 = content.substr(index);
let contentWithString = part1 + tagToInsert + cursorPosition + part2;
this._editor.setContent(contentWithString, ({ format: "raw" }));
this._editor.selection.moveToBookmark(bookmark);
}
私はに問題があると思いますこの行を修正する方法はわかりません:
this._editor.selection.setContent(cursorPosition);
私を助けてくれますか?事前
EDITによって
ありがとう:
は、私はすべての問題を避けるために簡単な解決策を見つけた:
addCustomTag(tag: string) {
this._editor.execCommand('mceInsertContent', false, '((' + tag + '))');
}