Skip to content

Commit df0cd8a

Browse files
v2.0.20 优化撤销功能、优化粘贴过滤
1 parent 305facf commit df0cd8a

4 files changed

Lines changed: 33 additions & 15 deletions

File tree

dist/js/wangEditor.js

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -789,7 +789,7 @@ _e(function (E, $) {
789789
var length = 20; // 缓存的最大长度
790790

791791
// 数据处理
792-
function _handle(editor, data) {
792+
function _handle(editor, data, type) {
793793
// var range = data.range;
794794
// var range2 = range.cloneRange && range.cloneRange();
795795
var val = data.val;
@@ -800,13 +800,27 @@ _e(function (E, $) {
800800
}
801801

802802
if (val === html) {
803-
return;
803+
if (type === 'redo') {
804+
editor.redo();
805+
return;
806+
} else if (type === 'undo') {
807+
editor.undo();
808+
return;
809+
} else {
810+
return;
811+
}
804812
}
805813

806814
// 保存数据
807815
editor.txt.$txt.html(val);
816+
// 更新数据到textarea(有必要的话)
808817
editor.updateValue();
809818

819+
// onchange 事件
820+
if (editor.onchange && typeof editor.onchange === 'function') {
821+
editor.onchange.call(editor);
822+
}
823+
810824
// ?????
811825
// 注释:$txt 被重新赋值之后,range会被重置,cloneRange() 也不好使
812826
// // 重置选区
@@ -822,7 +836,7 @@ _e(function (E, $) {
822836
var val = $txt.html();
823837
var currentVal = undoList.length ? undoList[0] : '';
824838

825-
if (val === currentVal) {
839+
if (val === currentVal.val) {
826840
return;
827841
}
828842

@@ -845,6 +859,7 @@ _e(function (E, $) {
845859

846860
// undo 操作
847861
E.fn.undo = function () {
862+
848863
if (!undoList.length) {
849864
return;
850865
}
@@ -854,7 +869,7 @@ _e(function (E, $) {
854869
redoList.unshift(data);
855870

856871
// 并修改编辑器的内容
857-
_handle(this, data);
872+
_handle(this, data, 'undo');
858873
};
859874

860875
// redo 操作
@@ -868,7 +883,7 @@ _e(function (E, $) {
868883
undoList.unshift(data);
869884

870885
// 并修改编辑器的内容
871-
_handle(this, data);
886+
_handle(this, data, 'redo');
872887
};
873888
});
874889
// 暴露给用户的 API
@@ -2359,9 +2374,12 @@ _e(function (E, $) {
23592374
// 如果是容器,则继续深度遍历
23602375
if (nodeName === 'div') {
23612376
$elem = $(elem);
2362-
$elem.children().each(function () {
2377+
$.each(elem.childNodes, function () {
23632378
handle(this);
23642379
});
2380+
// $elem.children().each(function () {
2381+
// handle(this);
2382+
// });
23652383
return;
23662384
}
23672385

@@ -2373,7 +2391,7 @@ _e(function (E, $) {
23732391
resultHtml += '<p>' + elem.textContent + '</p>';
23742392
} else {
23752393
// 忽略的标签
2376-
if (['meta', 'style', 'script', 'object', 'form', 'iframe'].indexOf(nodeName) >= 0) {
2394+
if (['meta', 'style', 'script', 'object', 'form', 'iframe', 'br', 'hr'].indexOf(nodeName) >= 0) {
23772395
return;
23782396
}
23792397
// 其他标签,移除属性,插入 p 标签
@@ -5932,7 +5950,7 @@ _e(function (E, $) {
59325950
editor.undoRecord();
59335951
}
59345952

5935-
$txt.on('keyup', function (e) {
5953+
$txt.on('keydown', function (e) {
59365954
var keyCode = e.keyCode;
59375955

59385956
// 撤销 ctrl + z

dist/js/wangEditor.min.js

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "wangeditor",
33
"filename": "dist/js/wangEditor.min.js",
4-
"version": "2.0.19",
4+
"version": "2.0.20",
55
"description": "wangEditor - 基于javascript和css开发的 Web富文本编辑器, 轻量、简洁、易用、开源免费",
66
"homepage": "http://wangeditor.github.io/",
77
"keywords": ["wangEditor", "富文本编辑器"],

test/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
<link rel="stylesheet" type="text/css" href="../dist/css/wangEditor.min.css">
77
<style type="text/css">
88
#editor-trigger {
9-
height: 200px;
10-
max-height: 300px;
9+
height: 300px;
10+
max-height: 400px;
1111
}
1212
.container {
1313
width: 100%;

0 commit comments

Comments
 (0)