Tweaked comments extension
This commit is contained in:
parent
9d038fae7c
commit
ba90a57646
@ -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;
|
||||
|
@ -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();
|
||||
|
@ -2,7 +2,7 @@
|
||||
<div class="discussion-comment-list"><%= commentList %></div>
|
||||
<div class="new-comment-block">
|
||||
<div class="form-group">
|
||||
<i class="icon-comment"></i> <input class="form-control input-comment-author" placeholder="Your name"></input>
|
||||
<i class="icon-comment"></i> <input class="form-control input-comment-author" placeholder="Your name here!"></input>
|
||||
<textarea class="form-control input-comment-content"></textarea>
|
||||
</div>
|
||||
<div class="form-group text-right">
|
||||
|
Loading…
Reference in New Issue
Block a user