Use range detach as much as possible
This commit is contained in:
parent
c0b1c9107d
commit
349d43bd0d
@ -170,15 +170,14 @@ define([
|
||||
adjustScroll = adjustScroll || adjustScrollParam;
|
||||
debouncedUpdateCursorCoordinates();
|
||||
};
|
||||
this.updateSelectionRange = function(range) {
|
||||
this.updateSelectionRange = function() {
|
||||
var min = Math.min(this.selectionStart, this.selectionEnd);
|
||||
var max = Math.max(this.selectionStart, this.selectionEnd);
|
||||
if(!range) {
|
||||
range = this.createRange(min, max);
|
||||
}
|
||||
var selection = rangy.getSelection();
|
||||
var range = this.createRange(min, max);
|
||||
var selection = document.getSelection();
|
||||
selection.removeAllRanges();
|
||||
selection.addRange(range, this.selectionStart > this.selectionEnd);
|
||||
selection.addRange(range);
|
||||
range.detach();
|
||||
};
|
||||
this.setSelectionStartEnd = function(start, end) {
|
||||
if(start === undefined) {
|
||||
@ -204,7 +203,7 @@ define([
|
||||
var selectionStart = self.selectionStart;
|
||||
var selectionEnd = self.selectionEnd;
|
||||
var range;
|
||||
var selection = rangy.getSelection();
|
||||
var selection = document.getSelection();
|
||||
if(selection.rangeCount > 0) {
|
||||
var selectionRange = selection.getRangeAt(0);
|
||||
var element = selectionRange.startContainer;
|
||||
@ -221,7 +220,7 @@ define([
|
||||
element = container = container.parentNode;
|
||||
} while(element && element != inputElt);
|
||||
|
||||
if(selection.isBackwards()) {
|
||||
if(false) {
|
||||
selectionStart = offset + (range + '').length;
|
||||
selectionEnd = offset;
|
||||
}
|
||||
@ -230,6 +229,7 @@ define([
|
||||
selectionEnd = offset + (range + '').length;
|
||||
}
|
||||
}
|
||||
selectionRange.detach();
|
||||
}
|
||||
self.setSelectionStartEnd(selectionStart, selectionEnd);
|
||||
}
|
||||
@ -349,6 +349,7 @@ define([
|
||||
var range = selectionMgr.createRange(startOffset, textContent.length - endOffset);
|
||||
range.deleteContents();
|
||||
range.insertNode(document.createTextNode(replacement));
|
||||
range.detach();
|
||||
}
|
||||
|
||||
editor.setValue = setValue;
|
||||
@ -364,6 +365,7 @@ define([
|
||||
}
|
||||
range.deleteContents();
|
||||
range.insertNode(document.createTextNode(replacement));
|
||||
range.detach();
|
||||
offset = offset - text.length + replacement.length;
|
||||
selectionMgr.setSelectionStartEnd(offset, offset);
|
||||
selectionMgr.updateSelectionRange();
|
||||
|
@ -16,7 +16,7 @@ define([
|
||||
'<div class="comment-block<%= reply ? \' reply\' : \'\' %>">',
|
||||
' <div class="comment-author"><i class="icon-comment"></i> <%= author %></div>',
|
||||
' <div class="comment-content"><%= content %></div>',
|
||||
'</div>',
|
||||
'</div>'
|
||||
].join('');
|
||||
var popoverTitleTmpl = [
|
||||
'<span class="clearfix">',
|
||||
@ -24,7 +24,7 @@ define([
|
||||
' <i class="icon-trash"></i>',
|
||||
' </a>',
|
||||
' “<%- title %>”',
|
||||
'</span>',
|
||||
'</span>'
|
||||
].join('');
|
||||
|
||||
var eventMgr;
|
||||
@ -197,6 +197,7 @@ define([
|
||||
}
|
||||
try {
|
||||
cssApplier.undoToRange(context.rangyRange);
|
||||
context.rangyRange.detach();
|
||||
}
|
||||
catch(e) {}
|
||||
var discussion = context.getDiscussion();
|
||||
@ -289,12 +290,12 @@ define([
|
||||
title += '...';
|
||||
}
|
||||
return _.template(popoverTitleTmpl, {
|
||||
title: title,
|
||||
title: title
|
||||
});
|
||||
},
|
||||
content: function() {
|
||||
var content = _.template(commentsPopoverContentHTML, {
|
||||
commentList: getDiscussionComments(),
|
||||
commentList: getDiscussionComments()
|
||||
});
|
||||
return content;
|
||||
},
|
||||
@ -431,6 +432,7 @@ define([
|
||||
|
||||
// Remove highlight
|
||||
cssApplier.undoToRange(currentContext.rangyRange);
|
||||
currentContext.rangyRange.detach();
|
||||
currentContext = undefined;
|
||||
delete currentFileDesc.newDiscussion;
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user