Skip to content
This repository has been archived by the owner on Mar 28, 2024. It is now read-only.

Commit

Permalink
fix(sheet name contains squotes bug): formla can not execute, when sh…
Browse files Browse the repository at this point in the history
…eet name contains squotes

input formula controller
  • Loading branch information
DR-Univer committed Oct 16, 2020
1 parent 9b0fcfd commit fc1dd83
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 9 deletions.
9 changes: 8 additions & 1 deletion src/controllers/handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,14 @@ export default function luckysheetHandler() {
}
else if (event.ctrlKey && $("#luckysheet-rich-text-editor").find("span").last().text() != ",") {
//按住ctrl 选择选区时 先处理上一个选区
let vText = $("#luckysheet-rich-text-editor").text() + ",";
let vText = $("#luckysheet-rich-text-editor").text();

if(vText.length > 0){
let lastWord = vText.substr(vText.length-1,1);
if(lastWord!="," && lastWord!="=" && lastWord!="("){
vText += ",";
}
}
if (vText.length > 0 && vText.substr(0, 1) == "=") {
vText = formula.functionHTMLGenerate(vText);

Expand Down
12 changes: 10 additions & 2 deletions src/controllers/keyboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ function formulaMoveEvent(dir, ctrlKey, shiftKey, event){
}
else if(formula.israngeseleciton()){
let anchor = $(window.getSelection().anchorNode);

// console.log(anchor.parent().next().text());
if(anchor.parent().next().text() == null || anchor.parent().next().text() == ""){
let vText = $("#luckysheet-input-box #luckysheet-input-box-index").text();
let range = formula.getcellrange(vText);
Expand Down Expand Up @@ -162,8 +162,10 @@ function formulaMoveEvent(dir, ctrlKey, shiftKey, event){

luckysheetMoveHighlightCell(dir_n, step, "rangeOfFormula");
}

event.preventDefault();
}
event.preventDefault();

}
else if(!ctrlKey && !shiftKey){
let anchor = $(window.getSelection().anchorNode);
Expand Down Expand Up @@ -228,6 +230,9 @@ function formulaMoveEvent(dir, ctrlKey, shiftKey, event){

event.preventDefault();
}
else{
formula.rangeHightlightselected($("#luckysheet-rich-text-editor"));
}
}
else if(dir == 'right'){
if(anchor.parent().is("span") && anchor.parent().next().length == 0 && anchorOffset > 0){
Expand All @@ -248,6 +253,9 @@ function formulaMoveEvent(dir, ctrlKey, shiftKey, event){

event.preventDefault();
}
else{
formula.rangeHightlightselected($("#luckysheet-rich-text-editor"));
}
}
}
}
Expand Down
7 changes: 6 additions & 1 deletion src/controllers/sheetBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,12 @@ export function initialSheetBar(){
}
let $t = $(this);
let txt = $t.text(), oldtxt = $t.data("oldtxt");

var reg1 = new RegExp("[\\[\\]:\\?*\/'\"]");
if(reg1.test(txt)){
alert(locale_sheetconfig.sheetNameSpecCharError);
return;
}

let index = getSheetIndex(Store.currentSheetIndex);
for (let i = 0; i < Store.luckysheetfile.length; i++) {
if (index != i && Store.luckysheetfile[i].name == txt) {
Expand Down
4 changes: 4 additions & 0 deletions src/function/func.js
Original file line number Diff line number Diff line change
Expand Up @@ -1607,6 +1607,10 @@ function luckysheet_getcelldata(txt) {
if (val.length > 1) {
sheettxt = val[0];
rangetxt = val[1];

if(sheettxt.substr(0,1)=="'" && sheettxt.substr(sheettxt.length-1,1)=="'"){
sheettxt = sheettxt.substring(1,sheettxt.length-1);
}

for (let i in luckysheetfile) {
if (sheettxt == luckysheetfile[i].name) {
Expand Down
21 changes: 17 additions & 4 deletions src/global/formula.js
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,9 @@ const luckysheetformula = {
rangetxt = val[1];



if(sheettxt.substr(0,1)=="'" && sheettxt.substr(sheettxt.length-1,1)=="'"){
sheettxt = sheettxt.substring(1,sheettxt.length-1);
}
for (let i in luckysheetfile) {
if (sheettxt == luckysheetfile[i].name) {
sheetIndex = luckysheetfile[i].index;
Expand Down Expand Up @@ -1210,6 +1212,7 @@ const luckysheetformula = {
$("#luckysheet-formula-search-c, #luckysheet-formula-help-c").hide();
_this.helpFunctionExe($editer, currSelection);

console.log(currSelection, $(currSelection).closest(".luckysheet-formula-functionrange-cell").length);
if ($(currSelection).closest(".luckysheet-formula-functionrange-cell").length == 0) {
_this.searchFunction($editer);
return;
Expand Down Expand Up @@ -3877,6 +3880,16 @@ const luckysheetformula = {
matchConfig.dquote += 1;
}
}
else if (s == "'") {
str += "'";

if (matchConfig.squote > 0) {
matchConfig.squote -= 1;
}
else {
matchConfig.squote += 1;
}
}
else if (s == ',' && matchConfig.dquote == 0 && matchConfig.braces == 0) {
if(bracket.length <= 1){
function_str += _this.functionParser(str,cellRangeFunction) + ",";
Expand Down Expand Up @@ -3958,7 +3971,7 @@ const luckysheetformula = {
}
}
else {
if (matchConfig.dquote == 0) {
if (matchConfig.dquote == 0 && matchConfig.squote==0) {
str += $.trim(s);
}
else {
Expand All @@ -3971,7 +3984,7 @@ const luckysheetformula = {

if (_this.iscelldata($.trim(str))) {
let str_nb = $.trim(str);
endstr = "luckysheet_getcelldata('" +str_nb + "')";
endstr = "luckysheet_getcelldata('" +str_nb.replace(/'/g, "\\'") + "')";
if(typeof(cellRangeFunction)=="function"){
cellRangeFunction(str_nb);
}
Expand Down Expand Up @@ -4025,7 +4038,7 @@ const luckysheetformula = {

i++;
}
// console.log(function_str);
console.log(function_str);
return function_str;
},
insertUpdateDynamicArray: function(dynamicArrayItem) {
Expand Down
1 change: 1 addition & 0 deletions src/locale/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -9509,6 +9509,7 @@ export default {
redoDelete:"Can be undo by Ctrl+Z",
noHide:"Can't hide, at least keep one sheet tag",
chartEditNoOpt:"This operation is not allowed in chart editing mode!",
sheetNameSpecCharError:"The name cannot contain:[ ] : \ ? * / ' \"",
},
conditionformat: {
conditionformat_greaterThan: 'Conditionformat-GreaterThan',
Expand Down
1 change: 1 addition & 0 deletions src/locale/es.js
Original file line number Diff line number Diff line change
Expand Up @@ -9508,6 +9508,7 @@ export default {
redoDelete:"Se puede deshacer con Ctrl+Z",
noHide:"No se puede ocultar, al menos conserva una etiqueta de hoja",
chartEditNoOpt:"¡Esta operación no está permitida en el modo de edición de gráficos!",
sheetNameSpecCharError:"El nombre no puede contener:[ ] : \ ? * / ' \"",
},
conditionformat: {
conditionformat_greaterThan: 'Conditionformat-GreaterThan',
Expand Down
2 changes: 1 addition & 1 deletion src/locale/zh.js
Original file line number Diff line number Diff line change
Expand Up @@ -9752,7 +9752,7 @@ export default {
redoDelete:"可以通过Ctrl+Z撤销删除",
noHide:"不能隐藏, 至少保留一个sheet标签",
chartEditNoOpt:"图表编辑模式下不允许该操作!",

sheetNameSpecCharError:"名称不能包含:[ ] : \ ? * / ' \"",
},
conditionformat: {
conditionformat_greaterThan: '条件格式——大于',
Expand Down

0 comments on commit fc1dd83

Please sign in to comment.