diff --git a/public/res/editor.js b/public/res/editor.js index 2dd5ab63..f49e0877 100644 --- a/public/res/editor.js +++ b/public/res/editor.js @@ -288,14 +288,18 @@ define([ var nextTickAdjustScroll = false; var debouncedSave = utils.debounce(function() { save(); - if(lastSelectionStart == self.selectionStart && lastSelectionEnd == self.selectionEnd) { + if(lastSelectionStart === self.selectionStart && lastSelectionEnd === self.selectionEnd) { nextTickAdjustScroll = false; } self.updateCursorCoordinates(nextTickAdjustScroll); nextTickAdjustScroll = false; }); - return function(debounced, adjustScroll) { + return function(debounced, adjustScroll, forceAdjustScroll) { + if(forceAdjustScroll) { + lastSelectionStart = undefined; + lastSelectionEnd = undefined; + } if(debounced) { nextTickAdjustScroll = nextTickAdjustScroll || adjustScroll; return debouncedSave(); @@ -386,11 +390,11 @@ define([ editor.selectionMgr = selectionMgr; $(document).on('selectionchange', '.editor-content', _.bind(selectionMgr.saveSelectionState, selectionMgr, true, false)); - function adjustCursorPosition() { + function adjustCursorPosition(force) { if(inputElt === undefined) { return; } - selectionMgr.saveSelectionState(true, true); + selectionMgr.saveSelectionState(true, true, force); } editor.adjustCursorPosition = adjustCursorPosition; diff --git a/public/res/extensions/comments.js b/public/res/extensions/comments.js index f14434e1..9c4c514c 100644 --- a/public/res/extensions/comments.js +++ b/public/res/extensions/comments.js @@ -66,6 +66,7 @@ define([ var newCommentElt = crel('a', { class: 'discussion icon-comment new' }); + var newCommentEltY; function Context(commentElt, fileDesc) { this.commentElt = commentElt; @@ -131,9 +132,8 @@ define([ delete commentEltMap[commentElt.discussionIndex]; }); // Move newCommentElt + setCommentEltCoordinates(newCommentElt, newCommentEltY, true); if(currentContext && !currentContext.discussionIndex) { - coordinates = selectionMgr.getCoordinates(currentContext.getDiscussion().selectionEnd); - setCommentEltCoordinates(newCommentElt, coordinates.y, true); inputElt.scrollTop += parseInt(newCommentElt.style.top) - inputElt.scrollTop - inputElt.offsetHeight * 3 / 4; movePopover(newCommentElt); } @@ -190,6 +190,11 @@ define([ currentFileDesc === fileDesc && refreshDiscussions(); }; + comments.onCursorCoordinates = function(x, y) { + newCommentEltY = y; + setCommentEltCoordinates(newCommentElt, y, true); + }; + comments.onCommentsChanged = function(fileDesc) { if(currentFileDesc !== fileDesc) { return; @@ -333,8 +338,6 @@ define([ commentList: [] }; currentFileDesc.newDiscussion = discussion; - var coordinates = selectionMgr.getCoordinates(selectionStart); - setCommentEltCoordinates(newCommentElt, coordinates.y, true); } context.selectionRange = selectionMgr.createRange(discussion.selectionStart, discussion.selectionEnd); inputElt.scrollTop += parseInt(evt.target.style.top) - inputElt.scrollTop - inputElt.offsetHeight * 3 / 4; @@ -466,11 +469,14 @@ define([ $commentElt = $(sortedCommentEltList[(curentIndex + 1)]); } } + else if(selectionMgr.selectionStart === selectionMgr.selectionEnd && sortedCommentEltList.length) { + $commentElt = $(_.first(sortedCommentEltList)); + } if($commentElt.length === 0) { // Close the popover properly closeCurrentPopover(); editor.focus(); - editor.adjustCursorPosition(); + editor.adjustCursorPosition(true); } else { $commentElt.click(); diff --git a/public/res/html/commentsPopoverContent.html b/public/res/html/commentsPopoverContent.html index 008d64ee..bae8ea06 100644 --- a/public/res/html/commentsPopoverContent.html +++ b/public/res/html/commentsPopoverContent.html @@ -2,7 +2,7 @@
<%= commentList %>
- +