From e86a53bbf176870692e1ecb2995d6a6cb07d340d Mon Sep 17 00:00:00 2001 From: windy <1374721899@qq.com> Date: Thu, 29 Jun 2017 17:07:46 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=99codeeditor=E6=B7=BB=E5=8A=A0paramforma?= =?UTF-8?q?tter=E6=8E=A5=E5=8F=A3=EF=BC=8C=E6=98=AF=E7=9A=84=E5=8F=AF?= =?UTF-8?q?=E4=BB=A5=E8=87=AA=E5=AE=9A=E4=B9=89=E5=8F=82=E6=95=B0=E6=98=BE?= =?UTF-8?q?=E7=A4=BA=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bi/base.js | 14 ++++++++++++-- docs/base.js | 14 ++++++++++++-- src/base/single/editor/editor.code.js | 14 ++++++++++++-- 3 files changed, 36 insertions(+), 6 deletions(-) diff --git a/bi/base.js b/bi/base.js index 83ed77616..12e4d1099 100644 --- a/bi/base.js +++ b/bi/base.js @@ -17727,7 +17727,11 @@ BI.CodeEditor = BI.inherit(BI.Single, { value: '', watermark: "", lineHeight: 2, - readOnly: false + readOnly: false, + //参数显示值构造函数 + paramFormatter: function (v) { + return v; + } }); }, _init: function () { @@ -17811,6 +17815,8 @@ BI.CodeEditor = BI.inherit(BI.Single, { }, insertParam: function (param) { + var value = param; + param = this.options.paramFormatter(param); var from = this.editor.getCursor(); this.editor.replaceSelection(param); var to = this.editor.getCursor(); @@ -17818,6 +17824,7 @@ BI.CodeEditor = BI.inherit(BI.Single, { if (BI.isNotNull(param.match(/^$/))) { options.className = 'error-param'; } + options.value = value; this.editor.markText(from, to, options); this.editor.replaceSelection(" "); this.editor.focus(); @@ -17837,8 +17844,11 @@ BI.CodeEditor = BI.inherit(BI.Single, { case "param": case "error-param": var fieldNameLength = i.to - i.from; - value = value.substr(0, i.from + num) + "$\{" + value.substr(i.from + num, fieldNameLength) + "\}" + value.substr(i.to + num, value.length); + value = value.substr(0, i.from + num) + "$\{" + i.marker.value + "\}" + value.substr(i.to + num, value.length); + //加上${}的偏移 num += 3; + //加上实际值和显示值的长度差的偏移 + num += (i.marker.value.length - fieldNameLength); break; } }); diff --git a/docs/base.js b/docs/base.js index 83ed77616..12e4d1099 100644 --- a/docs/base.js +++ b/docs/base.js @@ -17727,7 +17727,11 @@ BI.CodeEditor = BI.inherit(BI.Single, { value: '', watermark: "", lineHeight: 2, - readOnly: false + readOnly: false, + //参数显示值构造函数 + paramFormatter: function (v) { + return v; + } }); }, _init: function () { @@ -17811,6 +17815,8 @@ BI.CodeEditor = BI.inherit(BI.Single, { }, insertParam: function (param) { + var value = param; + param = this.options.paramFormatter(param); var from = this.editor.getCursor(); this.editor.replaceSelection(param); var to = this.editor.getCursor(); @@ -17818,6 +17824,7 @@ BI.CodeEditor = BI.inherit(BI.Single, { if (BI.isNotNull(param.match(/^$/))) { options.className = 'error-param'; } + options.value = value; this.editor.markText(from, to, options); this.editor.replaceSelection(" "); this.editor.focus(); @@ -17837,8 +17844,11 @@ BI.CodeEditor = BI.inherit(BI.Single, { case "param": case "error-param": var fieldNameLength = i.to - i.from; - value = value.substr(0, i.from + num) + "$\{" + value.substr(i.from + num, fieldNameLength) + "\}" + value.substr(i.to + num, value.length); + value = value.substr(0, i.from + num) + "$\{" + i.marker.value + "\}" + value.substr(i.to + num, value.length); + //加上${}的偏移 num += 3; + //加上实际值和显示值的长度差的偏移 + num += (i.marker.value.length - fieldNameLength); break; } }); diff --git a/src/base/single/editor/editor.code.js b/src/base/single/editor/editor.code.js index 02e5d6883..dcc648ec8 100644 --- a/src/base/single/editor/editor.code.js +++ b/src/base/single/editor/editor.code.js @@ -11,7 +11,11 @@ BI.CodeEditor = BI.inherit(BI.Single, { value: '', watermark: "", lineHeight: 2, - readOnly: false + readOnly: false, + //参数显示值构造函数 + paramFormatter: function (v) { + return v; + } }); }, _init: function () { @@ -95,6 +99,8 @@ BI.CodeEditor = BI.inherit(BI.Single, { }, insertParam: function (param) { + var value = param; + param = this.options.paramFormatter(param); var from = this.editor.getCursor(); this.editor.replaceSelection(param); var to = this.editor.getCursor(); @@ -102,6 +108,7 @@ BI.CodeEditor = BI.inherit(BI.Single, { if (BI.isNotNull(param.match(/^$/))) { options.className = 'error-param'; } + options.value = value; this.editor.markText(from, to, options); this.editor.replaceSelection(" "); this.editor.focus(); @@ -121,8 +128,11 @@ BI.CodeEditor = BI.inherit(BI.Single, { case "param": case "error-param": var fieldNameLength = i.to - i.from; - value = value.substr(0, i.from + num) + "$\{" + value.substr(i.from + num, fieldNameLength) + "\}" + value.substr(i.to + num, value.length); + value = value.substr(0, i.from + num) + "$\{" + i.marker.value + "\}" + value.substr(i.to + num, value.length); + //加上${}的偏移 num += 3; + //加上实际值和显示值的长度差的偏移 + num += (i.marker.value.length - fieldNameLength); break; } });