Skip to content

Commit

Permalink
CHG: fix paste bin position calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
farthinker committed Apr 18, 2019
1 parent 5168b58 commit 783ca97
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 22 deletions.
22 changes: 13 additions & 9 deletions lib/simditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -2267,7 +2267,7 @@ Clipboard = (function(superClass) {
}
return this.editor.body.on('paste', (function(_this) {
return function(e) {
var range;
var pasteBinAnchor, range;
if (_this.pasting || _this._pasteBin) {
return;
}
Expand All @@ -2282,11 +2282,17 @@ Clipboard = (function(superClass) {
} else {
_this.editor.formatter.format();
_this.editor.selection.setRangeAtStartOf(_this.editor.body.find('p:first'));
range = _this.editor.selection._range;
}
if (_this._processPasteByClipboardApi(e)) {
return false;
}
_this._createPasteBin($(range.commonAncestorContainer));
pasteBinAnchor = $('<span>');
range.insertNode(pasteBinAnchor[0]);
_this._createPasteBin(pasteBinAnchor);
pasteBinAnchor.remove();
range.collapse(true);
_this.editor.selection.range(range);
_this.editor.inputManager.throttledValueChanged.clear();
_this.editor.inputManager.throttledSelectionChanged.clear();
_this.editor.undoManager.throttledPushState.clear();
Expand Down Expand Up @@ -2332,14 +2338,12 @@ Clipboard = (function(superClass) {
};

Clipboard.prototype._createPasteBin = function(anchorNode) {
var containerOffset;
containerOffset = (anchorNode != null ? anchorNode.position() : void 0) || {
top: 0,
left: 0
};
var anchorOffset, editorOffset;
anchorOffset = anchorNode.offset();
editorOffset = this.editor.el.offset();
return this._pasteBin = $('<div contenteditable="true" />').addClass('simditor-paste-bin').attr('tabIndex', '-1').css({
top: containerOffset.top,
left: containerOffset.left
top: anchorOffset.top - editorOffset.top,
left: anchorOffset.left - editorOffset.left
}).appendTo(this.editor.el);
};

Expand Down
22 changes: 13 additions & 9 deletions site/assets/scripts/simditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -2262,7 +2262,7 @@ Clipboard = (function(superClass) {
}
return this.editor.body.on('paste', (function(_this) {
return function(e) {
var range;
var pasteBinAnchor, range;
if (_this.pasting || _this._pasteBin) {
return;
}
Expand All @@ -2277,11 +2277,17 @@ Clipboard = (function(superClass) {
} else {
_this.editor.formatter.format();
_this.editor.selection.setRangeAtStartOf(_this.editor.body.find('p:first'));
range = _this.editor.selection._range;
}
if (_this._processPasteByClipboardApi(e)) {
return false;
}
_this._createPasteBin($(range.commonAncestorContainer));
pasteBinAnchor = $('<span>');
range.insertNode(pasteBinAnchor[0]);
_this._createPasteBin(pasteBinAnchor);
pasteBinAnchor.remove();
range.collapse(true);
_this.editor.selection.range(range);
_this.editor.inputManager.throttledValueChanged.clear();
_this.editor.inputManager.throttledSelectionChanged.clear();
_this.editor.undoManager.throttledPushState.clear();
Expand Down Expand Up @@ -2327,14 +2333,12 @@ Clipboard = (function(superClass) {
};

Clipboard.prototype._createPasteBin = function(anchorNode) {
var containerOffset;
containerOffset = (anchorNode != null ? anchorNode.position() : void 0) || {
top: 0,
left: 0
};
var anchorOffset, editorOffset;
anchorOffset = anchorNode.offset();
editorOffset = this.editor.el.offset();
return this._pasteBin = $('<div contenteditable="true" />').addClass('simditor-paste-bin').attr('tabIndex', '-1').css({
top: containerOffset.top,
left: containerOffset.left
top: anchorOffset.top - editorOffset.top,
left: anchorOffset.left - editorOffset.left
}).appendTo(this.editor.el);
};

Expand Down
15 changes: 11 additions & 4 deletions src/clipboard.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,16 @@ class Clipboard extends SimpleModule
else
@editor.formatter.format()
@editor.selection.setRangeAtStartOf @editor.body.find('p:first')
range = @editor.selection._range

return false if @_processPasteByClipboardApi(e)

@_createPasteBin $(range.commonAncestorContainer)
pasteBinAnchor = $('<span>')
range.insertNode(pasteBinAnchor[0])
@_createPasteBin pasteBinAnchor
pasteBinAnchor.remove()
range.collapse(true)
@editor.selection.range range

@editor.inputManager.throttledValueChanged.clear()
@editor.inputManager.throttledSelectionChanged.clear()
Expand Down Expand Up @@ -68,13 +74,14 @@ class Clipboard extends SimpleModule
return true

_createPasteBin: (anchorNode) ->
containerOffset = anchorNode?.position() || { top: 0, left: 0 }
anchorOffset = anchorNode.offset()
editorOffset = @editor.el.offset()
@_pasteBin = $ '<div contenteditable="true" />'
.addClass 'simditor-paste-bin'
.attr 'tabIndex', '-1'
.css({
top: containerOffset.top,
left: containerOffset.left
top: anchorOffset.top - editorOffset.top
left: anchorOffset.left - editorOffset.left
})
.appendTo @editor.el

Expand Down

0 comments on commit 783ca97

Please sign in to comment.