diff --git a/src/controllers/inlineString.js b/src/controllers/inlineString.js
index 50d83c8..73b965d 100644
--- a/src/controllers/inlineString.js
+++ b/src/controllers/inlineString.js
@@ -1,9 +1,12 @@
import {getFontStyleByCell, textTrim} from "../global/getdata";
+import {selectTextContent,selectTextContentCross,selectTextContentCollapse} from '../global/cursorPos';
import locale from '../locale/locale';
import Store from '../store';
+export const inlineStyleAffectAttribute = {"bl":1, "it":1 , "ff":1, "cl":1, "un":1,"fs":1,"fc":1};
+
export function isInlineStringCell(cell){
- let isIs = cell.ct!=null && cell.ct.t=="inlineStr" && cell.ct.s!=null && cell.ct.s.length>0;
+ let isIs = cell && cell.ct!=null && cell.ct.t=="inlineStr" && cell.ct.s!=null && cell.ct.s.length>0;
return isIs;
}
@@ -13,26 +16,27 @@ export function isInlineStringCT(ct){
}
export function updateInlineStringFormat(cell, attr, value, $input){
-
-
-
- let s = Store.inlineStringEditCache;
+ // let s = Store.inlineStringEditCache;
var w = window.getSelection();
- var range = w.getRangeAt(0);
- if(range.collapsed===true){
- return;
- }
-
- if(isInlineStringCell(cell)){
- if(Store.inlineStringEditCache==null){
- Store.inlineStringEditCache = JSON.parse(JSON.stringify(cell.ct.s));
- }
+ var range;
+ if(w.type=="None"){
+ range = Store.inlineStringEditRange;
}
else{
- Store.inlineStringEditCache = [{
- v:cell.v
- }];
- }
+ range = w.getRangeAt(0);
+ }
+
+
+ // if(isInlineStringCell(cell)){
+ // if(Store.inlineStringEditCache==null){
+ // Store.inlineStringEditCache = JSON.parse(JSON.stringify(cell.ct.s));
+ // }
+ // }
+ // else{
+ // Store.inlineStringEditCache = [{
+ // v:cell.v
+ // }];
+ // }
let cac = range.commonAncestorContainer;
let $textEditor;
@@ -44,54 +48,248 @@ export function updateInlineStringFormat(cell, attr, value, $input){
}
let $functionbox = $(cac).closest("#luckysheet-functionbox-cell");
+ if($textEditor.length==0 && $functionbox.length==0 && Store.inlineStringEditRange!=null){
+ range = Store.inlineStringEditRange;
+ cac = range.commonAncestorContainer;
+ if(cac.id=="luckysheet-rich-text-editor"){
+ $textEditor = $(cac);
+ }
+ else{
+ $textEditor = $(cac).closest("#luckysheet-rich-text-editor");
+ }
+ $functionbox = $(cac).closest("#luckysheet-functionbox-cell");
+ }
+
+ if(range.collapsed===true){
+ return;
+ }
+
let endContainer = range.endContainer, startContainer = range.startContainer;
let endOffset = range.endOffset, startOffset = range.startOffset;
if($textEditor.length>0){
if(startContainer===endContainer){
+ let span = startContainer.parentNode, spanIndex;
+
+ let content = span.innerHTML;
+ let left="" , mid="" , right="";
+ let s1=0, s2=startOffset, s3 = endOffset, s4=content.length;
+ left = content.substring(s1, s2);
+ mid = content.substring(s2, s3);
+ right = content.substring(s3, s4);
+
+ let cont = "";
+ if(left!=""){
+ cont += "" + left + "";
+ }
+
+ if(mid!=""){
+ // let styleObj = {};
+ // styleObj[attr] = value;
+ // let s = getFontStyleByCell(styleObj, undefined, undefined, false);
+ // let ukey = textTrim(s.substr(0, s.indexOf(':')));
+ // let uvalue = textTrim(s.substr(s.indexOf(':')+1));
+ // uvalue = uvalue.substr(0, uvalue.length-1);
+ // let cssText = span.style.cssText;
+ // cssText = removeClassWidthCss(cssText, attr);
+
+ let cssText = getCssText(span.style.cssText, attr, value);
+
+ cont += "" + mid + "";
+ }
+
+ if(right!=""){
+ cont += "" + right + "";
+ }
+
if(startContainer.parentNode.tagName=="SPAN"){
- let span = startContainer.parentNode;
- let content = span.innerHTML;
- let left="" , mid="" , right="";
- let s1=0, s2=startOffset, s3 = endOffset, s4=content.length;
- left = content.substring(s1, s2);
- mid = content.substring(s2, s3);
- right = content.substring(s3, s4);
+ spanIndex = $textEditor.find("span").index(span);
+ $(span).replaceWith(cont);
+ }
+ else{
+ spanIndex = 0;
+ $(span).html(cont);
+ }
+
+ let seletedNodeIndex = 0;
+ if(s1==s2){
+ seletedNodeIndex = spanIndex;
+ }
+ else{
+ seletedNodeIndex = spanIndex+1;
+ }
+
+ selectTextContent($textEditor.find("span").get(seletedNodeIndex));
+ }
+ else{
+ if(startContainer.parentNode.tagName=="SPAN" && endContainer.parentNode.tagName=="SPAN"){
+ let startSpan = startContainer.parentNode, startSpanIndex;
+ let endSpan = endContainer.parentNode, endSpanIndex;
+
+ startSpanIndex = $textEditor.find("span").index(startSpan);
+ endSpanIndex = $textEditor.find("span").index(endSpan);
+
+ let startContent = startSpan.innerHTML, endContent = endSpan.innerHTML;
+ let sleft="" , sright="", eleft="" , eright="";
+ let s1=0, s2=startOffset, s3 = endOffset, s4=endContent.length;
+
+ sleft = startContent.substring(s1, s2);
+ sright = startContent.substring(s2, startContent.length);
+
+ eleft = endContent.substring(0, s3);
+ eright = endContent.substring(s3, s4);
+ let spans = $textEditor.find("span");
+ let replaceSpans = spans.slice(startSpanIndex, endSpanIndex+1);
let cont = "";
- if(left!=""){
- cont += "" + left + "";
+ for(let i=0;i" + content + "";
+ }
+ if(sleft!=""){
+ cont += "" + sleft + "";
}
- if(mid!=""){
- let styleObj = {};
- styleObj[attr] = value;
- let s = getFontStyleByCell(styleObj);
- let ukey = textTrim(s.substr(0, s.indexOf(':')));
- let uvalue = textTrim(s.substr(s.indexOf(':')+1));
- uvalue = uvalue.substr(0, uvalue.length-1);
- cont += "" + mid + "";
+ if(sright!=""){
+ let cssText = getCssText(startSpan.style.cssText, attr, value);
+ cont += "" + sright + "";
}
- if(right!=""){
- cont += "" + right + "";
+ if(startSpanIndex" + content + "";
+ }
}
- $(span).replaceWith(cont);
- }
- else{
+ if(eleft!=""){
+ let cssText = getCssText(endSpan.style.cssText, attr, value);
+ cont += "" + eleft + "";
+ }
+
+ if(eright!=""){
+ cont += "" + eright + "";
+ }
+
+ for(let i=endSpanIndex+1;i" + content + "";
+ }
+
+ $textEditor.html(cont);
+
+ // console.log(replaceSpans, cont);
+ // replaceSpans.replaceWith(cont);
+
+ let startSeletedNodeIndex, endSeletedNodeIndex;
+ if(s1==s2){
+ startSeletedNodeIndex = startSpanIndex;
+ endSeletedNodeIndex = endSpanIndex;
+ }
+ else{
+ startSeletedNodeIndex = startSpanIndex+1;
+ endSeletedNodeIndex = endSpanIndex+1;
+ }
+ spans = $textEditor.find("span");
+
+ selectTextContentCross(spans.get(startSeletedNodeIndex), spans.get(endSeletedNodeIndex));
}
}
- else{
-
- }
}
else if($functionbox.length>0){
}
}
+export function enterKeyControll(){
+ var w = window.getSelection();
+
+ if(w.type=="None"){
+ return
+ }
+ var range = w.getRangeAt(0);
+ let cac = range.commonAncestorContainer;
+ let $textEditor;
+ if(cac.id=="luckysheet-rich-text-editor"){
+ $textEditor = $(cac);
+ }
+ else{
+ $textEditor = $(cac).closest("#luckysheet-rich-text-editor");
+ }
+ let $functionbox = $(cac).closest("#luckysheet-functionbox-cell");
+
+ // if(range.collapsed===true){
+ // return;
+ // }
+
+ let endContainer = range.endContainer, startContainer = range.startContainer;
+ let endOffset = range.endOffset, startOffset = range.startOffset;
+
+ if($textEditor.length>0){
+ let startSpan = startContainer.parentNode;
+ let startSpanIndex = $textEditor.find("span").index(startSpan);
+ if(range.collapsed===false){
+ range.deleteContents();
+ }
+
+ let startContent = startSpan.innerHTML;
+ let sleft="" , sright="";
+ let s1=0, s2=startOffset;
+
+ sleft = startContent.substring(s1, s2);
+ sright = startContent.substring(s2, startContent.length);
+
+ let cont = "" + sleft + "\n" + sright + "";
+ let spanIndex;
+ if(startContainer.parentNode.tagName=="SPAN"){
+ spanIndex = $textEditor.find("span").index(startSpan);
+ $(startSpan).replaceWith(cont);
+ }
+ else{
+ spanIndex = 0;
+ $(startSpan).html(cont);
+ }
+
+ selectTextContentCollapse($textEditor.find("span").get(spanIndex), startOffset+1);
+
+ }
+ else if($functionbox.length>0){
+
+ }
+}
+
+export function updateInlineStringFormatOutside(cell, key, value){
+ let s = cell.ct.s;
+ for(let i=0;i-1){
+ for(let i=0;i-1){
for(let i=0;i0){
newCss += key + ":" + value + ";";
}
}
}
- else{
+ else if(ukey.length>0){
cssText += ukey + ":" + uvalue + ";";
+ newCss = cssText;
}
- return cssText;
+ return newCss;
}
function removeClassWidthCss(cssText, ukey){
let cssTextArray = cssText.split(";");
let newCss = "";
+ let oUkey = ukey;
+ if(ukey==null || ukey.length==0){
+ return cssText;
+ }
+ if(ukey in luckyToCssName){
+ ukey = luckyToCssName[ukey];
+ }
if(cssText.indexOf(ukey)>-1){
for(let i=0;i0){
newCss += key + ":" + value + ";";
}
}
}
+ else{
+ newCss = cssText;
+ }
+
+ return newCss;
+}
+
+function getCssText(cssText, attr, value){
+ let styleObj = {};
+ styleObj[attr] = value;
+ if(attr=="un"){
+ let fontColor = getClassWithcss(cssText,"color");
+ if(fontColor==""){
+ fontColor = "#000000";
+ }
+ let fs = getClassWithcss(cssText,"font-size");
+ if(fs==""){
+ fs = 11;
+ }
+ fs = parseInt(fs);
+ styleObj["_fontSize"] = fs;
+ styleObj["_color"] = fontColor;
+ }
+ let s = getFontStyleByCell(styleObj, undefined, undefined, false);
+ let ukey = textTrim(s.substr(0, s.indexOf(':')));
+ let uvalue = textTrim(s.substr(s.indexOf(':')+1));
+ uvalue = uvalue.substr(0, uvalue.length-1);
+ // let cssText = span.style.cssText;
+ cssText = removeClassWidthCss(cssText, attr);
+
+ cssText = upsetClassWithCss(cssText, ukey, uvalue);
return cssText;
}
+
+
diff --git a/src/controllers/keyboard.js b/src/controllers/keyboard.js
index 4db7733..5356c00 100644
--- a/src/controllers/keyboard.js
+++ b/src/controllers/keyboard.js
@@ -25,6 +25,7 @@ import formula from '../global/formula';
import cleargridelement from '../global/cleargridelement';
import tooltip from '../global/tooltip';
import locale from '../locale/locale';
+import {enterKeyControll} from './inlineString';
import Store from '../store';
@@ -300,10 +301,16 @@ export function keyboardInitial(){
return;
}
+
+
let $inputbox = $("#luckysheet-input-box");
- if (kcode == keycode.ENTER && parseInt($inputbox.css("top")) > 0) {
+ if((altKey || event.metaKey) && kcode == keycode.ENTER && parseInt($inputbox.css("top")) > 0){
+ enterKeyControll();
+ event.preventDefault();
+ }
+ else if (kcode == keycode.ENTER && parseInt($inputbox.css("top")) > 0) {
if ($("#luckysheet-formula-search-c").is(":visible") && formula.searchFunctionCell != null) {
formula.searchFunctionEnter($("#luckysheet-formula-search-c").find(".luckysheet-formula-search-item-active"));
}
diff --git a/src/controllers/menuButton.js b/src/controllers/menuButton.js
index 7cbab7a..0250c40 100644
--- a/src/controllers/menuButton.js
+++ b/src/controllers/menuButton.js
@@ -31,7 +31,7 @@ import { countfunc } from '../global/count';
import { hideMenuByCancel } from '../global/cursorPos';
import { getSheetIndex, getRangetxt, getluckysheetfile } from '../methods/get';
import { setluckysheetfile } from '../methods/set';
-import {isInlineStringCell,updateInlineStringFormat,convertCssToStyleList} from './inlineString';
+import {isInlineStringCell,updateInlineStringFormat,convertCssToStyleList,inlineStyleAffectAttribute,updateInlineStringFormatOutside} from './inlineString';
import { replaceHtml, getObjType, rgbTohex, mouseclickposition, luckysheetfontformat,luckysheetContainerFocus } from '../utils/util';
import Store from '../store';
import locale from '../locale/locale';
@@ -798,6 +798,15 @@ const menuButton = {
//字体大小
let luckysheet_fs_setTimeout = null;
$("#luckysheet-icon-font-size").mousedown(function(e){
+ if (parseInt($("#luckysheet-input-box").css("top")) > 0){
+ let w = window.getSelection();
+ if(w.type!="None"){
+ let range = w.getRangeAt(0);
+ if(!range.collapsed){
+ Store.inlineStringEditRange = range.cloneRange();
+ }
+ }
+ }
hideMenuByCancel(e);
e.stopPropagation();
}).click(function(){
@@ -861,6 +870,8 @@ const menuButton = {
menuleft = menuleft - tlen + userlen;
}
mouseclickposition($menuButton, menuleft, $(this).offset().top + 25, "lefttop");
+
+
})
.find("input.luckysheet-toolbar-textinput").keydown(function(e){
hideMenuByCancel(e);
@@ -2835,7 +2846,7 @@ const menuButton = {
let canvasElement = document.createElement('canvas');
let canvas = canvasElement.getContext("2d");
- if(attr in {"bl":1, "it":1 , "ff":1, "cl":1, "un":1,"fs":1,"fc":1} ){
+ if(attr in inlineStyleAffectAttribute ){
if (parseInt($("#luckysheet-input-box").css("top")) > 0 ) {
let value = $("#luckysheet-input-box").text();
if(value.substr(0,1)!="="){
@@ -2968,7 +2979,13 @@ const menuButton = {
let value = d[r][c];
if (getObjType(value) == "object") {
- d[r][c][attr] = foucsStatus;
+ if(attr in inlineStyleAffectAttribute && isInlineStringCell(value)){
+ updateInlineStringFormatOutside(value, attr, foucsStatus);
+ }
+ else{
+ d[r][c][attr] = foucsStatus;
+ }
+
}
else{
d[r][c] = { v: value };
@@ -2982,7 +2999,9 @@ const menuButton = {
}
}
- cfg = rowlenByRange(d, row_st, row_ed, cfg);
+ if(attr == "tb" || attr == "tr" || attr == "fs"){
+ cfg = rowlenByRange(d, row_st, row_ed, cfg);
+ }
}
let allParam = {};
@@ -3355,6 +3374,7 @@ const menuButton = {
var w = window.getSelection();
var range = w.getRangeAt(0);
let startContainer = range.startContainer;
+ Store.inlineStringEditRange = null;
const _locale = locale();
if(startContainer.parentNode.tagName=="SPAN"){
let cssText = startContainer.parentNode.style.cssText;
diff --git a/src/controllers/sheetBar.js b/src/controllers/sheetBar.js
index c048ee6..cfcb4cb 100644
--- a/src/controllers/sheetBar.js
+++ b/src/controllers/sheetBar.js
@@ -11,6 +11,8 @@ import { isEditMode } from '../global/validate';
import formula from '../global/formula';
import cleargridelement from '../global/cleargridelement';
import tooltip from '../global/tooltip';
+ selectTextDom
+import {selectTextDom} from '../global/cursorPos';
import locale from '../locale/locale';
import Store from '../store';
@@ -206,16 +208,7 @@ export function initialSheetBar(){
$t.attr("contenteditable", "true").addClass("luckysheet-mousedown-cancel").data("oldtxt", $t.text());
setTimeout(function () {
- if (document.selection) {
- let range = document.body.createTextRange();
- range.moveToElementText($t.get(0));
- range.select();
- } else if (window.getSelection) {
- let range = document.createRange();
- range.selectNodeContents($t.get(0));
- window.getSelection().removeAllRanges();
- window.getSelection().addRange(range);
- }
+ selectTextDom($t.get(0));
}, 1);
}
diff --git a/src/global/cursorPos.js b/src/global/cursorPos.js
index b0eabd3..c01209e 100644
--- a/src/global/cursorPos.js
+++ b/src/global/cursorPos.js
@@ -60,8 +60,64 @@ function hideMenuByCancel(event){
}
}
+function selectTextDom(ele){
+ if (window.getSelection) {
+ let range = document.createRange();
+ range.selectNodeContents(ele);
+ window.getSelection().removeAllRanges();
+ window.getSelection().addRange(range);
+ }
+ else if (document.selection) {
+ let range = document.body.createTextRange();
+ range.moveToElementText(ele);
+ range.select();
+ }
+}
+
+function selectTextContent(ele){
+ if (window.getSelection) {
+ let range = document.createRange();
+ var content=ele.firstChild;
+ range.setStart(content,0);
+ range.setEnd(content,content.length);
+ window.getSelection().removeAllRanges();
+ window.getSelection().addRange(range);
+ }
+ else if (document.selection) {
+ let range = document.body.createTextRange();
+ range.moveToElementText(ele);
+ range.select();
+ }
+}
+
+function selectTextContentCross(sEle, eEle){
+ if (window.getSelection) {
+ let range = document.createRange();
+ var sContent=sEle.firstChild, eContent=eEle.firstChild;
+ range.setStart(sContent,0);
+ range.setEnd(eContent,eContent.length);
+ window.getSelection().removeAllRanges();
+ window.getSelection().addRange(range);
+ }
+}
+
+function selectTextContentCollapse(sEle, index){
+ if (window.getSelection) {
+ let range = document.createRange();
+ var sContent=sEle.firstChild;
+ range.setStart(sContent,index);
+ range.collapse(true);
+ window.getSelection().removeAllRanges();
+ window.getSelection().addRange(range);
+ }
+}
+
export {
luckysheetRangeLast,
getCursortPosition,
hideMenuByCancel,
+ selectTextContent,
+ selectTextDom,
+ selectTextContentCross,
+ selectTextContentCollapse
}
\ No newline at end of file
diff --git a/src/global/draw.js b/src/global/draw.js
index 2938120..55443d9 100644
--- a/src/global/draw.js
+++ b/src/global/draw.js
@@ -2169,7 +2169,7 @@ function cellTextRender(textInfo, ctx, option){
Math.floor((pos_x +c.endX)/Store.zoomRatio)+0.5 ,
Math.floor((pos_y+c.endY)/Store.zoomRatio)+0.5 ,
);
- ctx.lineWidth = 1;
+ ctx.lineWidth = Math.floor(c.fs/9);
ctx.strokeStyle = ctx.fillStyle;
ctx.stroke();
ctx.closePath();
@@ -2188,7 +2188,7 @@ function cellTextRender(textInfo, ctx, option){
Math.floor((pos_x +item.endX)/Store.zoomRatio)+0.5,
Math.floor((pos_y+ item.endY)/Store.zoomRatio)+0.5
);
- ctx.lineWidth = 1;
+ ctx.lineWidth = Math.floor(item.fs/9);
ctx.strokeStyle = ctx.fillStyle;
ctx.stroke();
ctx.closePath();
diff --git a/src/global/formula.js b/src/global/formula.js
index f6be655..ae18fba 100644
--- a/src/global/formula.js
+++ b/src/global/formula.js
@@ -9,7 +9,7 @@ import luckysheetFreezen from '../controllers/freezen';
import { seletedHighlistByindex, luckysheet_count_show } from '../controllers/select';
import { isRealNum, isRealNull, valueIsError, isEditMode } from './validate';
import { isdatetime, isdatatype } from './datecontroll';
-import { getCellTextSplitArr } from '../global/getRowlen';
+import { getCellTextSplitArr,getCellTextInfo } from '../global/getRowlen';
import { getcellvalue,getcellFormula,getInlineStringNoStyle } from './getdata';
import { setcellvalue } from './setdata';
import { genarate, valueShowEs } from './format';
@@ -18,7 +18,7 @@ import tooltip from './tooltip';
import { rowLocation, colLocation, colLocationByIndex, mouseposition } from './location';
import { luckysheetRangeLast } from './cursorPos';
import { jfrefreshgrid } from './refresh';
-import { isInlineStringCell } from '../controllers/inlineString';
+import { isInlineStringCell,convertSpanToShareString } from '../controllers/inlineString';
// import luckysheet_function from '../function/luckysheet_function';
// import functionlist from '../function/functionlist';
import { luckysheet_compareWith, luckysheet_getarraydata, luckysheet_getcelldata, luckysheet_parseData, luckysheet_getValue, luckysheet_indirect_check, luckysheet_indirect_check_return, luckysheet_offset_check } from '../function/func';
@@ -1197,41 +1197,70 @@ const luckysheetformula = {
let _this = this;
let $input = $("#luckysheet-rich-text-editor");
-
- // API, we get value from user
- value = value || $input.text();
+ let inputText = $input.text(), inputHtml = $input.html();
+
+
+
if (_this.rangetosheet != null && _this.rangetosheet != Store.currentSheetIndex) {
sheetmanage.changeSheetExec(_this.rangetosheet);
}
let curv = Store.flowdata[r][c];
-
- if(isRealNull(value)){
- if(curv == null || (isRealNull(curv.v) && curv.spl == null)){
- _this.cancelNormalSelected();
- return;
- }
+ let isPrevInline = isInlineStringCell(curv);
+ let isCurInline = (inputText.slice(0, 1) != "=" && inputHtml.indexOf("span")>-1);
+ if(!value && !isCurInline && isPrevInline){
+ delete curv.ct.s;
+ curv.ct.t = "g";
+ curv.ct.fa = "General";
}
- else if(curv!=null && curv.qp != 1){
- if (getObjType(curv) == "object" && (value == curv.f || value == curv.v || value == curv.m)) {
- _this.cancelNormalSelected();
- return;
- }
- else if (value == curv) {
- _this.cancelNormalSelected();
- return;
+ else if(isCurInline){
+ if (getObjType(curv) != "object") {
+ curv = {};
}
- }
+ delete curv.f;
+ delete curv.v;
+ delete curv.m;
- if (getObjType(value) == "string" && value.slice(0, 1) == "=" && value.length > 1) {
+ if(curv.ct==null){
+ curv.ct = {};
+ curv.ct.fa = "General";
+ }
+ curv.ct.t = "inlineStr";
+ curv.ct.s = convertSpanToShareString($input.find("span"));
}
- else if(getObjType(curv) == "object" && curv.ct != null && curv.ct.fa != null && curv.ct.fa != "@" && !isRealNull(value)){
- delete curv.m;//更新时间m处理 , 会实际删除单元格数据的参数(flowdata时已删除)
- if(curv.f != null){ //如果原来是公式,而更新的数据不是公式,则把公式删除
- delete curv.f;
- delete curv.spl; //删除单元格的sparklines的配置串
+
+ // API, we get value from user
+ value = value || $input.text();
+
+ if(!isCurInline){
+ if(isRealNull(value)){
+ if(curv == null || (isRealNull(curv.v) && curv.spl == null)){
+ _this.cancelNormalSelected();
+ return;
+ }
+ }
+ else if(curv!=null && curv.qp != 1){
+ if (getObjType(curv) == "object" && (value == curv.f || value == curv.v || value == curv.m)) {
+ _this.cancelNormalSelected();
+ return;
+ }
+ else if (value == curv) {
+ _this.cancelNormalSelected();
+ return;
+ }
+ }
+
+ if (getObjType(value) == "string" && value.slice(0, 1) == "=" && value.length > 1) {
+
+ }
+ else if(getObjType(curv) == "object" && curv.ct != null && curv.ct.fa != null && curv.ct.fa != "@" && !isRealNull(value)){
+ delete curv.m;//更新时间m处理 , 会实际删除单元格数据的参数(flowdata时已删除)
+ if(curv.f != null){ //如果原来是公式,而更新的数据不是公式,则把公式删除
+ delete curv.f;
+ delete curv.spl; //删除单元格的sparklines的配置串
+ }
}
}
@@ -1243,49 +1272,15 @@ const luckysheetformula = {
let dynamicArrayItem = null; //动态数组
if (getObjType(curv) == "object") {
- if(getObjType(value) == "string" && value.slice(0, 1) == "=" && value.length > 1){
- let v = _this.execfunction(value, r, c, true);
- curv = _this.execFunctionGroupData[r][c];
- curv.f = v[2];
+ if(!isCurInline){
- //打进单元格的sparklines的配置串, 报错需要单独处理。
- if(v.length == 4 && v[3].type == "sparklines"){
- delete curv.m;
- delete curv.v;
-
- let curCalv = v[3].data;
-
- if(getObjType(curCalv) == "array" && getObjType(curCalv[0]) != "object"){
- curv.v = curCalv[0];
- }
- else{
- curv.spl = v[3].data;
- }
- }
- else if(v.length == 4 && v[3].type == "dynamicArrayItem"){
- dynamicArrayItem = v[3].data;
- }
- }
- // from API setCellValue,luckysheet.setCellValue(0, 0, {f: "=sum(D1)", bg:"#0188fb"}),value is an object, so get attribute f as value
- else if(getObjType(value) == "object"){
- let valueFunction = value.f;
+ if(getObjType(value) == "string" && value.slice(0, 1) == "=" && value.length > 1){
+ let v = _this.execfunction(value, r, c, true);
- if(getObjType(valueFunction) == "string" && valueFunction.slice(0, 1) == "=" && valueFunction.length > 1){
- let v = _this.execfunction(valueFunction, r, c, true);
-
- // get v/m/ct
curv = _this.execFunctionGroupData[r][c];
-
- // get f
curv.f = v[2];
- // get other cell style attribute
- delete value.v;
- delete value.m;
- delete value.f;
- Object.assign(curv,value);
-
//打进单元格的sparklines的配置串, 报错需要单独处理。
if(v.length == 4 && v[3].type == "sparklines"){
delete curv.m;
@@ -1304,26 +1299,92 @@ const luckysheetformula = {
dynamicArrayItem = v[3].data;
}
}
-
- }
- else{
- _this.delFunctionGroup(r, c);
- _this.execFunctionGroup(r, c, value);
- isRunExecFunction = false;
- curv = _this.execFunctionGroupData[r][c];
+ // from API setCellValue,luckysheet.setCellValue(0, 0, {f: "=sum(D1)", bg:"#0188fb"}),value is an object, so get attribute f as value
+ else if(getObjType(value) == "object"){
+ let valueFunction = value.f;
+
+ if(getObjType(valueFunction) == "string" && valueFunction.slice(0, 1) == "=" && valueFunction.length > 1){
+ let v = _this.execfunction(valueFunction, r, c, true);
- delete curv.f;
- delete curv.spl;
+ // get v/m/ct
- if(curv.qp == 1 && ('' + value).substr(0,1)!="'"){//if quotePrefix is 1, cell is force string, cell clear quotePrefix when it is updated
- curv.qp = 0;
- if(curv.ct!=null){
- curv.ct.fa = "General";
- curv.ct.t = "n";
+ curv = _this.execFunctionGroupData[r][c];
+ curv.f = v[2];
+
+ //打进单元格的sparklines的配置串, 报错需要单独处理。
+ if(v.length == 4 && v[3].type == "sparklines"){
+ delete curv.m;
+ delete curv.v;
+
+ let curCalv = v[3].data;
+
+ if(getObjType(curCalv) == "array" && getObjType(curCalv[0]) != "object"){
+ curv.v = curCalv[0];
+ }
+ else{
+ curv.spl = v[3].data;
+ }
+ }
+ else if(v.length == 4 && v[3].type == "dynamicArrayItem"){
+ dynamicArrayItem = v[3].data;
+ }
+ }
+ // from API setCellValue,luckysheet.setCellValue(0, 0, {f: "=sum(D1)", bg:"#0188fb"}),value is an object, so get attribute f as value
+ else if(getObjType(value) == "object"){
+ let valueFunction = value.f;
+
+ if(getObjType(valueFunction) == "string" && valueFunction.slice(0, 1) == "=" && valueFunction.length > 1){
+ let v = _this.execfunction(valueFunction, r, c, true);
+
+ // get v/m/ct
+ curv = _this.execFunctionGroupData[r][c];
+
+ // get f
+ curv.f = v[2];
+
+ // get other cell style attribute
+ delete value.v;
+ delete value.m;
+ delete value.f;
+ Object.assign(curv,value);
+
+ //打进单元格的sparklines的配置串, 报错需要单独处理。
+ if(v.length == 4 && v[3].type == "sparklines"){
+ delete curv.m;
+ delete curv.v;
+
+ let curCalv = v[3].data;
+
+ if(getObjType(curCalv) == "array" && getObjType(curCalv[0]) != "object"){
+ curv.v = curCalv[0];
+ }
+ else{
+ curv.spl = v[3].data;
+ }
+ }
+ }
+
+ }
+
+ }
+ else {
+ _this.delFunctionGroup(r, c);
+ _this.execFunctionGroup(r, c, value);
+ isRunExecFunction = false;
+ curv = _this.execFunctionGroupData[r][c];
+
+ delete curv.f;
+ delete curv.spl;
+
+ if(curv.qp == 1 && ('' + value).substr(0,1)!="'"){//if quotePrefix is 1, cell is force string, cell clear quotePrefix when it is updated
+ curv.qp = 0;
+ if(curv.ct!=null){
+ curv.ct.fa = "General";
+ curv.ct.t = "n";
+ }
}
}
}
-
value = curv;
}
else {
@@ -1400,42 +1461,62 @@ const luckysheetformula = {
cfg["rowlen"] = {};
}
- if(d[r][c].tb == "2" && d[r][c].v != null){//自动换行
- let defaultrowlen = 19;
+ if((d[r][c].tb == "2" && d[r][c].v != null) || isInlineStringCell(d[r][c])){//自动换行
+ let defaultrowlen = Store.defaultrowlen;;
- let offlinecanvas = $("#luckysheetTableContentF").get(0).getContext("2d");
- offlinecanvas.textBaseline = 'top'; //textBaseline以top计算
+ let canvas = $("#luckysheetTableContent").get(0).getContext("2d");
+ // offlinecanvas.textBaseline = 'top'; //textBaseline以top计算
- let fontset = luckysheetfontformat(d[r][c]);
- offlinecanvas.font = fontset;
+ // let fontset = luckysheetfontformat(d[r][c]);
+ // offlinecanvas.font = fontset;
- let currentRowLen = defaultrowlen;
- if(cfg["rowlen"][r] != null){
- currentRowLen = cfg["rowlen"][r];
+ if(cfg["customHeight"] && cfg["customHeight"][r]==1){
+
}
-
- let strValue = getcellvalue(r, c, d).toString();
- let measureText = offlinecanvas.measureText(strValue);
-
- let textMetrics = measureText.width;
- let cellWidth = colLocationByIndex(c)[1] - colLocationByIndex(c)[0] - 4;
- let oneLineTextHeight = measureText.actualBoundingBoxDescent - measureText.actualBoundingBoxAscent;
-
- if(textMetrics > cellWidth){
- let strArr = [];//文本截断数组
- strArr = getCellTextSplitArr(strValue, strArr, cellWidth, offlinecanvas);
-
- let computeRowlen = oneLineTextHeight * strArr.length + 4;
- //比较计算高度和当前高度取最大高度
- if(computeRowlen > currentRowLen){
- currentRowLen = computeRowlen;
+ else{
+ // let currentRowLen = defaultrowlen;
+ // if(cfg["rowlen"][r] != null){
+ // currentRowLen = cfg["rowlen"][r];
+ // }
+
+ let cellWidth = colLocationByIndex(c)[1] - colLocationByIndex(c)[0] - 2;
+
+ let textInfo = getCellTextInfo(d[r][c], canvas,{
+ r:r,
+ c:c,
+ cellWidth:cellWidth
+ });
+
+ let currentRowLen = defaultrowlen;
+ // console.log("rowlen", textInfo);
+ if(textInfo!=null){
+ currentRowLen = textInfo.textHeightAll+2;
+ }
+
+ // let strValue = getcellvalue(r, c, d).toString();
+ // let measureText = offlinecanvas.measureText(strValue);
+
+ // let textMetrics = measureText.width;
+ // let cellWidth = colLocationByIndex(c)[1] - colLocationByIndex(c)[0] - 4;
+ // let oneLineTextHeight = measureText.actualBoundingBoxDescent - measureText.actualBoundingBoxAscent;
+
+ // if(textMetrics > cellWidth){
+ // let strArr = [];//文本截断数组
+ // strArr = getCellTextSplitArr(strValue, strArr, cellWidth, offlinecanvas);
+
+ // let computeRowlen = oneLineTextHeight * strArr.length + 4;
+ // //比较计算高度和当前高度取最大高度
+ // if(computeRowlen > currentRowLen){
+ // currentRowLen = computeRowlen;
+ // }
+ // }
+
+ if(currentRowLen > defaultrowlen){
+ cfg["rowlen"][r] = currentRowLen;
+ RowlChange = true;
}
}
- if(currentRowLen != defaultrowlen){
- cfg["rowlen"][r] = currentRowLen;
- RowlChange = true;
- }
}
//动态数组
diff --git a/src/global/getRowlen.js b/src/global/getRowlen.js
index 8abc010..82aee2c 100644
--- a/src/global/getRowlen.js
+++ b/src/global/getRowlen.js
@@ -43,7 +43,7 @@ function rowlenByRange(d, r1, r2, cfg) {
continue;
}
- if(cell != null && cell.v != null){
+ if(cell != null && (cell.v != null || isInlineStringCell(cell)) ){
let cellWidth = colLocationByIndex(c)[1] - colLocationByIndex(c)[0] - 2;
let textInfo = getCellTextInfo(cell, canvas,{
@@ -55,7 +55,7 @@ function rowlenByRange(d, r1, r2, cfg) {
let computeRowlen = 0;
// console.log("rowlen", textInfo);
if(textInfo!=null){
- computeRowlen = textInfo.textHeightAll;
+ computeRowlen = textInfo.textHeightAll+2;
}
// let fontset = luckysheetfontformat(cell);
@@ -326,13 +326,13 @@ function getCellTextInfo(cell , ctx, option){
let textContent = {};
textContent.values = [];
- let fontset, cancelLine="0", underLine="0", isInline=false, value, inlineStringArr=[];
+ let fontset, cancelLine="0", underLine="0", fontSize=11, isInline=false, value, inlineStringArr=[];
if(isInlineStringCell(cell)){
let sharedStrings = cell.ct.s, similarIndex = 0;
for(let i=0;i 0 && startContainer.parentNode.tagName=="SPAN" && !range.collapsed) {
+ let span = startContainer.parentNode;
+ let styleList = convertCssToStyleList(span.style.cssText);
+ foucsStatus = styleList[a];
+ isInlineEdit = true;
+ }
}
+ if(!isInlineEdit){
+ if(isInlineStringCell(cell)){
+ foucsStatus = cell.ct.s[0][a];
+ }
+ else{
+ foucsStatus = foucsStatus[a];
+ }
+ }
if(foucsStatus == null){
foucsStatus = "0";
diff --git a/src/store/index.js b/src/store/index.js
index 5c69ca3..2c779a1 100644
--- a/src/store/index.js
+++ b/src/store/index.js
@@ -127,6 +127,7 @@ const Store = {
showGridLines:true,
inlineStringEditCache:null,
+ inlineStringEditRange:null,
}