diff --git a/bi/base.js b/bi/base.js
index 610b6bf78..8b721b6e7 100644
--- a/bi/base.js
+++ b/bi/base.js
@@ -16346,7 +16346,7 @@ BI.shortcut('bi.rich_editor_text_toolbar', BI.RichEditorTextToolbar);/**
}
this.instanceDoc = document.defaultView;
this.elm.element.on('mousedown', BI.bind(this.selected, this));
- this.elm.element.on('keypress', BI.bind(this.keyDown, this));
+ this.elm.element.on('keydown', BI.bind(this.keyDown, this));
this.elm.element.on('focus', BI.bind(this.selected, this));
this.elm.element.on('blur', BI.bind(this.blur, this));
this.elm.element.on('keyup', BI.bind(this.selected, this));
@@ -16406,6 +16406,37 @@ BI.shortcut('bi.rich_editor_text_toolbar', BI.RichEditorTextToolbar);/**
this.savedSel = this.getSel();
},
+ setFocus: function (el) {
+ try {
+ el.focus();
+ } catch (e) {
+
+ }
+ if (!window.getSelection) {
+ var rng;
+ try {
+ el.focus();
+ } catch (e) {
+
+ }
+ rng = document.selection.createRange();
+ rng.moveStart('character', -el.innerText.length);
+ var text = rng.text;
+ for (var i = 0; i < el.innerText.length; i++) {
+ if (el.innerText.substring(0, i + 1) == text.substring(text.length - i - 1, text.length)) {
+ result = i + 1;
+ }
+ }
+ } else {
+ var range = document.createRange();
+ range.selectNodeContents(el);
+ range.collapse(false);
+ var sel = window.getSelection();
+ sel.removeAllRanges();
+ sel.addRange(range);
+ }
+ },
+
restoreRng: function () {
if (this.savedRange) {
this.selRng(this.savedRange, this.savedSel);
@@ -16740,14 +16771,22 @@ BI.RichEditorParamButton = BI.inherit(BI.RichEditorAction, {
});
this.param.on(BI.Button.EVENT_CHANGE, function () {
var sel = $(o.editor.selectedInstance.selElm());
- var param = "参数"
- if (o.editor.instance.getElm().element.find(sel).length <= 0) {
- o.editor.instance.getElm().element.append(param);
+ var param = $("参数").mousedown(function (e) {
+ e.stopEvent();
+ return false;
+ });
+ var wrapper = o.editor.instance.getElm().element;
+ if (wrapper.find(sel).length <= 0) {
+ wrapper.append(param);
return;
}
var ln = sel.closest("a");
if (ln.length === 0) {
- sel.after(param)
+ if (sel[0].nodeType === 3 && wrapper.find(sel.parent()).length > 0) {
+ sel.parent().after(param)
+ } else {
+ sel.after(param)
+ }
}
});
},
@@ -16759,10 +16798,30 @@ BI.RichEditorParamButton = BI.inherit(BI.RichEditorAction, {
key: function (e) {
var o = this.options;
+ var instance = o.editor.selectedInstance;
+ var wrapper = instance.getElm().element;
+ var sel = $(instance.selElm());
+ if (sel[0].nodeType === 3 && wrapper.find(sel.parent()).length > 0) {
+ sel = sel.parent();
+ }
+ if (BI.Key[e.keyCode]) {
+ if (sel.attr("data-type") === "param") {
+ var span = $("").text(BI.Key[e.keyCode]);
+ if (sel.text() !== BI.Key[e.keyCode]) {
+ sel.after(span);
+ sel.text(sel.attr("data-value"));
+ } else {
+ sel.after(span);
+ sel.destroy();
+ }
+ instance.setFocus(span[0]);
+ }
+ }
if (e.keyCode === BI.KeyCode.BACKSPACE) {
- var sel = $(o.editor.selectedInstance.selElm()).parent();
if (sel.attr("data-type") === "param") {
- sel.destroy();
+ if (sel.text() !== sel.attr("data-value")) {
+ sel.destroy();
+ }
}
}
}
diff --git a/bi/core.js b/bi/core.js
index c17e6fce5..b10c868e2 100644
--- a/bi/core.js
+++ b/bi/core.js
@@ -4134,6 +4134,59 @@ _.extend(BI, {
emptyFn: function () {
},
empty: null,
+ Key: {
+ "48": "0",
+ "49": "1",
+ "50": "2",
+ "51": "3",
+ "52": "4",
+ "53": "5",
+ "54": "6",
+ "55": "7",
+ "56": "8",
+ "57": "9",
+ "65": "a",
+ "66": "b",
+ "67": "c",
+ "68": "d",
+ "69": "e",
+ "70": "f",
+ "71": "g",
+ "72": "h",
+ "73": "i",
+ "74": "j",
+ "75": "k",
+ "76": "l",
+ "77": "m",
+ "78": "n",
+ "79": "o",
+ "80": "p",
+ "81": "q",
+ "82": "r",
+ "83": "s",
+ "84": "t",
+ "85": "u",
+ "86": "v",
+ "87": "w",
+ "88": "x",
+ "89": "y",
+ "90": "z",
+ "96": "0",
+ "97": "1",
+ "98": "2",
+ "99": "3",
+ "100": "4",
+ "101": "5",
+ "102": "6",
+ "103": "7",
+ "104": "8",
+ "105": "9",
+ "106": "*",
+ "107": "+",
+ "109": "-",
+ "110": ".",
+ "111": "/"
+ },
KeyCode: {
BACKSPACE: 8,
COMMA: 188,
diff --git a/dist/base.js b/dist/base.js
index 426cdc33a..516807807 100644
--- a/dist/base.js
+++ b/dist/base.js
@@ -16346,7 +16346,7 @@ BI.shortcut('bi.rich_editor_text_toolbar', BI.RichEditorTextToolbar);/**
}
this.instanceDoc = document.defaultView;
this.elm.element.on('mousedown', BI.bind(this.selected, this));
- this.elm.element.on('keypress', BI.bind(this.keyDown, this));
+ this.elm.element.on('keydown', BI.bind(this.keyDown, this));
this.elm.element.on('focus', BI.bind(this.selected, this));
this.elm.element.on('blur', BI.bind(this.blur, this));
this.elm.element.on('keyup', BI.bind(this.selected, this));
@@ -16406,6 +16406,37 @@ BI.shortcut('bi.rich_editor_text_toolbar', BI.RichEditorTextToolbar);/**
this.savedSel = this.getSel();
},
+ setFocus: function (el) {
+ try {
+ el.focus();
+ } catch (e) {
+
+ }
+ if (!window.getSelection) {
+ var rng;
+ try {
+ el.focus();
+ } catch (e) {
+
+ }
+ rng = document.selection.createRange();
+ rng.moveStart('character', -el.innerText.length);
+ var text = rng.text;
+ for (var i = 0; i < el.innerText.length; i++) {
+ if (el.innerText.substring(0, i + 1) == text.substring(text.length - i - 1, text.length)) {
+ result = i + 1;
+ }
+ }
+ } else {
+ var range = document.createRange();
+ range.selectNodeContents(el);
+ range.collapse(false);
+ var sel = window.getSelection();
+ sel.removeAllRanges();
+ sel.addRange(range);
+ }
+ },
+
restoreRng: function () {
if (this.savedRange) {
this.selRng(this.savedRange, this.savedSel);
@@ -16740,14 +16771,22 @@ BI.RichEditorParamButton = BI.inherit(BI.RichEditorAction, {
});
this.param.on(BI.Button.EVENT_CHANGE, function () {
var sel = $(o.editor.selectedInstance.selElm());
- var param = "参数"
- if (o.editor.instance.getElm().element.find(sel).length <= 0) {
- o.editor.instance.getElm().element.append(param);
+ var param = $("参数").mousedown(function (e) {
+ e.stopEvent();
+ return false;
+ });
+ var wrapper = o.editor.instance.getElm().element;
+ if (wrapper.find(sel).length <= 0) {
+ wrapper.append(param);
return;
}
var ln = sel.closest("a");
if (ln.length === 0) {
- sel.after(param)
+ if (sel[0].nodeType === 3 && wrapper.find(sel.parent()).length > 0) {
+ sel.parent().after(param)
+ } else {
+ sel.after(param)
+ }
}
});
},
@@ -16759,10 +16798,30 @@ BI.RichEditorParamButton = BI.inherit(BI.RichEditorAction, {
key: function (e) {
var o = this.options;
+ var instance = o.editor.selectedInstance;
+ var wrapper = instance.getElm().element;
+ var sel = $(instance.selElm());
+ if (sel[0].nodeType === 3 && wrapper.find(sel.parent()).length > 0) {
+ sel = sel.parent();
+ }
+ if (BI.Key[e.keyCode]) {
+ if (sel.attr("data-type") === "param") {
+ var span = $("").text(BI.Key[e.keyCode]);
+ if (sel.text() !== BI.Key[e.keyCode]) {
+ sel.after(span);
+ sel.text(sel.attr("data-value"));
+ } else {
+ sel.after(span);
+ sel.destroy();
+ }
+ instance.setFocus(span[0]);
+ }
+ }
if (e.keyCode === BI.KeyCode.BACKSPACE) {
- var sel = $(o.editor.selectedInstance.selElm()).parent();
if (sel.attr("data-type") === "param") {
- sel.destroy();
+ if (sel.text() !== sel.attr("data-value")) {
+ sel.destroy();
+ }
}
}
}
diff --git a/dist/bundle.js b/dist/bundle.js
index 2e9d8216f..796b8f6e1 100644
--- a/dist/bundle.js
+++ b/dist/bundle.js
@@ -25045,6 +25045,59 @@ _.extend(BI, {
emptyFn: function () {
},
empty: null,
+ Key: {
+ "48": "0",
+ "49": "1",
+ "50": "2",
+ "51": "3",
+ "52": "4",
+ "53": "5",
+ "54": "6",
+ "55": "7",
+ "56": "8",
+ "57": "9",
+ "65": "a",
+ "66": "b",
+ "67": "c",
+ "68": "d",
+ "69": "e",
+ "70": "f",
+ "71": "g",
+ "72": "h",
+ "73": "i",
+ "74": "j",
+ "75": "k",
+ "76": "l",
+ "77": "m",
+ "78": "n",
+ "79": "o",
+ "80": "p",
+ "81": "q",
+ "82": "r",
+ "83": "s",
+ "84": "t",
+ "85": "u",
+ "86": "v",
+ "87": "w",
+ "88": "x",
+ "89": "y",
+ "90": "z",
+ "96": "0",
+ "97": "1",
+ "98": "2",
+ "99": "3",
+ "100": "4",
+ "101": "5",
+ "102": "6",
+ "103": "7",
+ "104": "8",
+ "105": "9",
+ "106": "*",
+ "107": "+",
+ "109": "-",
+ "110": ".",
+ "111": "/"
+ },
KeyCode: {
BACKSPACE: 8,
COMMA: 188,
@@ -45152,7 +45205,7 @@ BI.shortcut('bi.rich_editor_text_toolbar', BI.RichEditorTextToolbar);/**
}
this.instanceDoc = document.defaultView;
this.elm.element.on('mousedown', BI.bind(this.selected, this));
- this.elm.element.on('keypress', BI.bind(this.keyDown, this));
+ this.elm.element.on('keydown', BI.bind(this.keyDown, this));
this.elm.element.on('focus', BI.bind(this.selected, this));
this.elm.element.on('blur', BI.bind(this.blur, this));
this.elm.element.on('keyup', BI.bind(this.selected, this));
@@ -45212,6 +45265,37 @@ BI.shortcut('bi.rich_editor_text_toolbar', BI.RichEditorTextToolbar);/**
this.savedSel = this.getSel();
},
+ setFocus: function (el) {
+ try {
+ el.focus();
+ } catch (e) {
+
+ }
+ if (!window.getSelection) {
+ var rng;
+ try {
+ el.focus();
+ } catch (e) {
+
+ }
+ rng = document.selection.createRange();
+ rng.moveStart('character', -el.innerText.length);
+ var text = rng.text;
+ for (var i = 0; i < el.innerText.length; i++) {
+ if (el.innerText.substring(0, i + 1) == text.substring(text.length - i - 1, text.length)) {
+ result = i + 1;
+ }
+ }
+ } else {
+ var range = document.createRange();
+ range.selectNodeContents(el);
+ range.collapse(false);
+ var sel = window.getSelection();
+ sel.removeAllRanges();
+ sel.addRange(range);
+ }
+ },
+
restoreRng: function () {
if (this.savedRange) {
this.selRng(this.savedRange, this.savedSel);
@@ -45546,14 +45630,22 @@ BI.RichEditorParamButton = BI.inherit(BI.RichEditorAction, {
});
this.param.on(BI.Button.EVENT_CHANGE, function () {
var sel = $(o.editor.selectedInstance.selElm());
- var param = "参数"
- if (o.editor.instance.getElm().element.find(sel).length <= 0) {
- o.editor.instance.getElm().element.append(param);
+ var param = $("参数").mousedown(function (e) {
+ e.stopEvent();
+ return false;
+ });
+ var wrapper = o.editor.instance.getElm().element;
+ if (wrapper.find(sel).length <= 0) {
+ wrapper.append(param);
return;
}
var ln = sel.closest("a");
if (ln.length === 0) {
- sel.after(param)
+ if (sel[0].nodeType === 3 && wrapper.find(sel.parent()).length > 0) {
+ sel.parent().after(param)
+ } else {
+ sel.after(param)
+ }
}
});
},
@@ -45565,10 +45657,30 @@ BI.RichEditorParamButton = BI.inherit(BI.RichEditorAction, {
key: function (e) {
var o = this.options;
+ var instance = o.editor.selectedInstance;
+ var wrapper = instance.getElm().element;
+ var sel = $(instance.selElm());
+ if (sel[0].nodeType === 3 && wrapper.find(sel.parent()).length > 0) {
+ sel = sel.parent();
+ }
+ if (BI.Key[e.keyCode]) {
+ if (sel.attr("data-type") === "param") {
+ var span = $("").text(BI.Key[e.keyCode]);
+ if (sel.text() !== BI.Key[e.keyCode]) {
+ sel.after(span);
+ sel.text(sel.attr("data-value"));
+ } else {
+ sel.after(span);
+ sel.destroy();
+ }
+ instance.setFocus(span[0]);
+ }
+ }
if (e.keyCode === BI.KeyCode.BACKSPACE) {
- var sel = $(o.editor.selectedInstance.selElm()).parent();
if (sel.attr("data-type") === "param") {
- sel.destroy();
+ if (sel.text() !== sel.attr("data-value")) {
+ sel.destroy();
+ }
}
}
}
diff --git a/dist/core.js b/dist/core.js
index c4fc62cd4..542814184 100644
--- a/dist/core.js
+++ b/dist/core.js
@@ -24994,6 +24994,59 @@ _.extend(BI, {
emptyFn: function () {
},
empty: null,
+ Key: {
+ "48": "0",
+ "49": "1",
+ "50": "2",
+ "51": "3",
+ "52": "4",
+ "53": "5",
+ "54": "6",
+ "55": "7",
+ "56": "8",
+ "57": "9",
+ "65": "a",
+ "66": "b",
+ "67": "c",
+ "68": "d",
+ "69": "e",
+ "70": "f",
+ "71": "g",
+ "72": "h",
+ "73": "i",
+ "74": "j",
+ "75": "k",
+ "76": "l",
+ "77": "m",
+ "78": "n",
+ "79": "o",
+ "80": "p",
+ "81": "q",
+ "82": "r",
+ "83": "s",
+ "84": "t",
+ "85": "u",
+ "86": "v",
+ "87": "w",
+ "88": "x",
+ "89": "y",
+ "90": "z",
+ "96": "0",
+ "97": "1",
+ "98": "2",
+ "99": "3",
+ "100": "4",
+ "101": "5",
+ "102": "6",
+ "103": "7",
+ "104": "8",
+ "105": "9",
+ "106": "*",
+ "107": "+",
+ "109": "-",
+ "110": ".",
+ "111": "/"
+ },
KeyCode: {
BACKSPACE: 8,
COMMA: 188,
diff --git a/src/base/richeditor/niceditor/niceditor.js b/src/base/richeditor/niceditor/niceditor.js
index 8a7031e02..35566cf1a 100644
--- a/src/base/richeditor/niceditor/niceditor.js
+++ b/src/base/richeditor/niceditor/niceditor.js
@@ -125,7 +125,7 @@
}
this.instanceDoc = document.defaultView;
this.elm.element.on('mousedown', BI.bind(this.selected, this));
- this.elm.element.on('keypress', BI.bind(this.keyDown, this));
+ this.elm.element.on('keydown', BI.bind(this.keyDown, this));
this.elm.element.on('focus', BI.bind(this.selected, this));
this.elm.element.on('blur', BI.bind(this.blur, this));
this.elm.element.on('keyup', BI.bind(this.selected, this));
@@ -185,6 +185,37 @@
this.savedSel = this.getSel();
},
+ setFocus: function (el) {
+ try {
+ el.focus();
+ } catch (e) {
+
+ }
+ if (!window.getSelection) {
+ var rng;
+ try {
+ el.focus();
+ } catch (e) {
+
+ }
+ rng = document.selection.createRange();
+ rng.moveStart('character', -el.innerText.length);
+ var text = rng.text;
+ for (var i = 0; i < el.innerText.length; i++) {
+ if (el.innerText.substring(0, i + 1) == text.substring(text.length - i - 1, text.length)) {
+ result = i + 1;
+ }
+ }
+ } else {
+ var range = document.createRange();
+ range.selectNodeContents(el);
+ range.collapse(false);
+ var sel = window.getSelection();
+ sel.removeAllRanges();
+ sel.addRange(range);
+ }
+ },
+
restoreRng: function () {
if (this.savedRange) {
this.selRng(this.savedRange, this.savedSel);
diff --git a/src/base/richeditor/plugins/button.param.js b/src/base/richeditor/plugins/button.param.js
index a242020bb..9d94716a9 100644
--- a/src/base/richeditor/plugins/button.param.js
+++ b/src/base/richeditor/plugins/button.param.js
@@ -26,14 +26,22 @@ BI.RichEditorParamButton = BI.inherit(BI.RichEditorAction, {
});
this.param.on(BI.Button.EVENT_CHANGE, function () {
var sel = $(o.editor.selectedInstance.selElm());
- var param = "参数"
- if (o.editor.instance.getElm().element.find(sel).length <= 0) {
- o.editor.instance.getElm().element.append(param);
+ var param = $("参数").mousedown(function (e) {
+ e.stopEvent();
+ return false;
+ });
+ var wrapper = o.editor.instance.getElm().element;
+ if (wrapper.find(sel).length <= 0) {
+ wrapper.append(param);
return;
}
var ln = sel.closest("a");
if (ln.length === 0) {
- sel.after(param)
+ if (sel[0].nodeType === 3 && wrapper.find(sel.parent()).length > 0) {
+ sel.parent().after(param)
+ } else {
+ sel.after(param)
+ }
}
});
},
@@ -45,10 +53,30 @@ BI.RichEditorParamButton = BI.inherit(BI.RichEditorAction, {
key: function (e) {
var o = this.options;
+ var instance = o.editor.selectedInstance;
+ var wrapper = instance.getElm().element;
+ var sel = $(instance.selElm());
+ if (sel[0].nodeType === 3 && wrapper.find(sel.parent()).length > 0) {
+ sel = sel.parent();
+ }
+ if (BI.Key[e.keyCode]) {
+ if (sel.attr("data-type") === "param") {
+ var span = $("").text(BI.Key[e.keyCode]);
+ if (sel.text() !== BI.Key[e.keyCode]) {
+ sel.after(span);
+ sel.text(sel.attr("data-value"));
+ } else {
+ sel.after(span);
+ sel.destroy();
+ }
+ instance.setFocus(span[0]);
+ }
+ }
if (e.keyCode === BI.KeyCode.BACKSPACE) {
- var sel = $(o.editor.selectedInstance.selElm()).parent();
if (sel.attr("data-type") === "param") {
- sel.destroy();
+ if (sel.text() !== sel.attr("data-value")) {
+ sel.destroy();
+ }
}
}
}
diff --git a/src/core/var.js b/src/core/var.js
index c5885ed84..ee2334e2e 100644
--- a/src/core/var.js
+++ b/src/core/var.js
@@ -15,6 +15,59 @@ _.extend(BI, {
emptyFn: function () {
},
empty: null,
+ Key: {
+ "48": "0",
+ "49": "1",
+ "50": "2",
+ "51": "3",
+ "52": "4",
+ "53": "5",
+ "54": "6",
+ "55": "7",
+ "56": "8",
+ "57": "9",
+ "65": "a",
+ "66": "b",
+ "67": "c",
+ "68": "d",
+ "69": "e",
+ "70": "f",
+ "71": "g",
+ "72": "h",
+ "73": "i",
+ "74": "j",
+ "75": "k",
+ "76": "l",
+ "77": "m",
+ "78": "n",
+ "79": "o",
+ "80": "p",
+ "81": "q",
+ "82": "r",
+ "83": "s",
+ "84": "t",
+ "85": "u",
+ "86": "v",
+ "87": "w",
+ "88": "x",
+ "89": "y",
+ "90": "z",
+ "96": "0",
+ "97": "1",
+ "98": "2",
+ "99": "3",
+ "100": "4",
+ "101": "5",
+ "102": "6",
+ "103": "7",
+ "104": "8",
+ "105": "9",
+ "106": "*",
+ "107": "+",
+ "109": "-",
+ "110": ".",
+ "111": "/"
+ },
KeyCode: {
BACKSPACE: 8,
COMMA: 188,