Skip to content

Commit

Permalink
FIX: 全选复制整段文字,粘贴后会错误的出现在第一行的前边
Browse files Browse the repository at this point in the history
  • Loading branch information
biallo committed Jun 13, 2018
1 parent 69fa956 commit 76d091f
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 11 deletions.
7 changes: 4 additions & 3 deletions lib/simditor.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*!
* Simditor v2.3.15
* http://simditor.tower.im/
* 2018-05-15
* 2018-06-13
*/
(function (root, factory) {
if (typeof define === 'function' && define.amd) {
Expand Down Expand Up @@ -1578,7 +1578,7 @@ UndoManager = (function(superClass) {
offset = ref[i];
childNodes = node.childNodes;
if (offset > childNodes.length - 1) {
if (i === position.length - 2 && $(node).is('pre:empty')) {
if (i === position.length - 2 && $(node).is(':empty')) {
child = document.createTextNode('');
node.appendChild(child);
childNodes = node.childNodes;
Expand Down Expand Up @@ -2376,7 +2376,8 @@ Clipboard = (function(superClass) {
$blockEl = this._pasteInBlockEl;
if (!pasteContent) {
return;
} else if (this._pastePlainText) {
}
if (this._pastePlainText) {
if ($blockEl.is('table')) {
lines = pasteContent.split('\n');
lastLine = lines.pop();
Expand Down
5 changes: 3 additions & 2 deletions site/assets/scripts/simditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -1573,7 +1573,7 @@ UndoManager = (function(superClass) {
offset = ref[i];
childNodes = node.childNodes;
if (offset > childNodes.length - 1) {
if (i === position.length - 2 && $(node).is('pre:empty')) {
if (i === position.length - 2 && $(node).is(':empty')) {
child = document.createTextNode('');
node.appendChild(child);
childNodes = node.childNodes;
Expand Down Expand Up @@ -2371,7 +2371,8 @@ Clipboard = (function(superClass) {
$blockEl = this._pasteInBlockEl;
if (!pasteContent) {
return;
} else if (this._pastePlainText) {
}
if (this._pastePlainText) {
if ($blockEl.is('table')) {
lines = pasteContent.split('\n');
lastLine = lines.pop();
Expand Down
8 changes: 5 additions & 3 deletions src/clipboard.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class Clipboard extends SimpleModule
@editor.undoManager.resetCaretPosition()

@pasting = true

@_getPasteContent (pasteContent) =>
@_processPasteContent pasteContent
@_pasteInBlockEl = null
Expand Down Expand Up @@ -109,7 +110,8 @@ class Clipboard extends SimpleModule

if !pasteContent
return
else if @_pastePlainText

if @_pastePlainText
if $blockEl.is('table')
lines = pasteContent.split('\n')
lastLine = lines.pop()
Expand All @@ -125,7 +127,7 @@ class Clipboard extends SimpleModule
@editor.selection.insertNode(node) for node in pasteContent
else if pasteContent.length < 1
return
else if pasteContent.length == 1
else if pasteContent.length == 1
if pasteContent.is('p')
children = pasteContent.contents()

Expand Down Expand Up @@ -172,7 +174,7 @@ class Clipboard extends SimpleModule
# cannot paste image in safari
else if $img.is('img[src^="webkit-fake-url://"]')
return

@editor.selection.insertNode(node) for node in children

else if $blockEl.is('p') and @editor.util.isEmptyNode $blockEl
Expand Down
5 changes: 3 additions & 2 deletions src/undoManager.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,10 @@ class UndoManager extends SimpleModule

for offset, i in position[0...position.length - 1]
childNodes = node.childNodes

if offset > childNodes.length - 1
# when pre is empty, the text node will be lost
if i == position.length - 2 and $(node).is('pre:empty')
# when node is empty, the text node will be lost
if i == position.length - 2 and $(node).is(':empty')
child = document.createTextNode ''
node.appendChild child
childNodes = node.childNodes
Expand Down
2 changes: 1 addition & 1 deletion styles/simditor.css
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*!
* Simditor v2.3.15
* http://simditor.tower.im/
* 2018-05-15
* 2018-06-13
*/
@font-face {
font-family: 'Simditor';
Expand Down

0 comments on commit 76d091f

Please sign in to comment.