Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/jokamax/summernote into j…
Browse files Browse the repository at this point in the history
…okamax-master
  • Loading branch information
lqez committed Dec 25, 2019
2 parents 13393a7 + 8af6514 commit 4355c12
Showing 1 changed file with 32 additions and 3 deletions.
35 changes: 32 additions & 3 deletions src/js/base/module/HintPopover.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export default class HintPopover {

initialize() {
this.lastWordRange = null;
this.matchingWord = null;
this.$popover = this.ui.popover({
className: 'note-hint-popover',
hideArrow: true,
Expand Down Expand Up @@ -106,11 +107,38 @@ export default class HintPopover {

if ($item.length) {
const node = this.nodeFromItem($item);
// XXX: consider to move codes to editor for recording redo/undo.
this.lastWordRange.insertNode(node);
range.createFromNode(node).collapse().select();

// If matchingWord length = 0 -> capture OK / open hint / but as mention capture "" (\w*)
if (this.matchingWord !== null && this.matchingWord.length === 0) {
this.lastWordRange.so = this.lastWordRange.eo;
// Else si > 0 and normal case -> adjust range "before" for correct position of insertion
} else if (this.matchingWord !== null && this.matchingWord.length > 0 && !this.lastWordRange.isCollapsed()) {
let rangeCompute = this.lastWordRange.eo - this.lastWordRange.so - this.matchingWord.length;
if (rangeCompute > 0) {
this.lastWordRange.so += rangeCompute;
}
}
if (document.queryCommandSupported('insertText')) {
this.context.triggerEvent('before.command', this.$editable.html());
this.lastWordRange.select();
this.context.invoke('editor.focus');
document.execCommand('insertText', false, node.textContent);
// -- Normalize
this.$editable = this.context.layoutInfo.editable;
this.$editable[0].normalize();
// -- Add To history
this.history = new History(this.$editable);
this.history.recordUndo();

// Default : if insertText not work
} else {
// XXX: consider to move codes to editor for recording redo/undo.
this.lastWordRange.insertNode(node);
range.createFromNode(node).collapse().select();
}

this.lastWordRange = null;
this.matchingWord = null;
this.hide();
this.context.triggerEvent('change', this.$editable.html(), this.$editable[0]);
this.context.invoke('editor.focus');
Expand Down Expand Up @@ -161,6 +189,7 @@ export default class HintPopover {
const hint = this.hints[index];
if (hint && hint.match.test(keyword) && hint.search) {
const matches = hint.match.exec(keyword);
this.matchingWord = matches[1];
hint.search(matches[1], callback);
} else {
callback();
Expand Down

0 comments on commit 4355c12

Please sign in to comment.