Skip to content

Commit

Permalink
Merge pull request #42 from PolicyStat/issue_38_redundant_bookmarks
Browse files Browse the repository at this point in the history
Fix #38 - don't create bookmarks out of the current selection's block
  • Loading branch information
caffodian committed Nov 3, 2016
2 parents a9dd4ca + 81b8824 commit fcd3b20
Showing 1 changed file with 9 additions and 17 deletions.
26 changes: 9 additions & 17 deletions plugins/nanospell/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -664,19 +664,17 @@
var blockList = event.data.blockList;
var url = resolveAjaxHandler();
var callback = function (data) {
var bookmarks;
var selectionStart = editor.getSelection().getStartElement();
var rootElement;
parseRpc(data, words);
editor.lockSelection();
bookmarks = editor.getSelection().createBookmarks(true);

for (var i = 0; i < blockList.length; i++) {
var rootElement = blockList[i];
rootElement = blockList[i];
editor.fire(EVENT_NAMES.START_RENDER, {
root: rootElement,
needsBookmarkCreated: false,
needsBookmarkCreated: selectionStart ? rootElement.contains(selectionStart) || rootElement.equals(selectionStart) : null,
});
}
editor.unlockSelection();
editor.getSelection().selectBookmarks(bookmarks);
};
var data = wordsToRPC(words, lang);
rpc(url, data, callback);
Expand Down Expand Up @@ -741,13 +739,15 @@
bookmarks;

if (needsBookmarkCreated) {
editor.lockSelection();
bookmarks = editor.getSelection().createBookmarks(true);
}

self.markTypos(editor, rootElement);

if (needsBookmarkCreated) {
editor.getSelection().selectBookmarks(bookmarks);
editor.unlockSelection();
}

rootElement.setCustomData('spellCheckInProgress', false);
Expand Down Expand Up @@ -832,11 +832,6 @@
function getWords(block) {
var range = editor.createRange(),
currentWordObj,
// a bookmark2 doesn't actually create a DOM node,
// but doesn't maintain its position through DOM mutations.
// We can create a bookmark2 for scanning purposes without restoring it
// And there will be no residual span in the DOM, like with bookmark(1)
bookmarks = editor.getSelection().createBookmarks2(false),
words = [],
word;

Expand All @@ -853,28 +848,25 @@
}

function startCheckOrMarkWords(words, blockList) {
var selectionStart = editor.getSelection().getStartElement();
if (words.length > 0) {
editor.fire(EVENT_NAMES.START_CHECK_WORDS, {
words: words,
blockList: blockList
});
}
else {
editor.lockSelection();
var bookmarks = editor.getSelection().createBookmarks(true);
for (var i = 0; i < blockList.length; i++) {
var rootElement = blockList[i];

editor.fire(
EVENT_NAMES.START_RENDER,
{
root: rootElement,
needsBookmarkCreated: false,
needsBookmarkCreated: selectionStart ? rootElement.contains(selectionStart) || rootElement.equals(selectionStart) : null,
});

}
editor.getSelection().selectBookmarks(bookmarks);
editor.unlockSelection();
}
}

Expand Down

0 comments on commit fcd3b20

Please sign in to comment.