From 405d90bfec0c7b47dee64e2034aeec8686c53e32 Mon Sep 17 00:00:00 2001 From: liuyang Date: Sun, 27 Sep 2020 18:00:12 +0800 Subject: [PATCH] fix(inline string bug): style lost when change cell to inline string, input error fix --- src/controllers/inlineString.js | 101 +++++++++++++++++++++++++++++--- src/controllers/keyboard.js | 8 ++- src/global/formula.js | 67 +++++++++++++-------- 3 files changed, 140 insertions(+), 36 deletions(-) diff --git a/src/controllers/inlineString.js b/src/controllers/inlineString.js index d989f26..3015299 100644 --- a/src/controllers/inlineString.js +++ b/src/controllers/inlineString.js @@ -2,8 +2,10 @@ import {getFontStyleByCell, textTrim} from "../global/getdata"; import {selectTextContent,selectTextContentCross,selectTextContentCollapse} from '../global/cursorPos'; import locale from '../locale/locale'; import Store from '../store'; +import { connect } from "net"; export const inlineStyleAffectAttribute = {"bl":1, "it":1 , "ff":1, "cl":1, "un":1,"fs":1,"fc":1}; +export const inlineStyleAffectCssName = {"font-weight":1, "font-style":1 , "font-family":1, "text-decoration":1, "border-bottom":1,"font-size":1,"color":1}; export function isInlineStringCell(cell){ let isIs = cell && cell.ct!=null && cell.ct.t=="inlineStr" && cell.ct.s!=null && cell.ct.s.length>0; @@ -68,10 +70,16 @@ export function updateInlineStringFormat(cell, attr, value, $input){ let endOffset = range.endOffset, startOffset = range.startOffset; if($textEditor.length>0){ - if(startContainer===endContainer){ - let span = startContainer.parentNode, spanIndex; + if(startContainer===endContainer){ + let span = startContainer.parentNode, spanIndex, inherit=false; let content = span.innerHTML; + + let fullContent = $textEditor.html(); + if(fullContent.substr(0,5) != "" + left + ""; + let cssText = span.style.cssText; + if(inherit){ + let box = $(span).closest("#luckysheet-input-box").get(0); + if(box!=null){ + cssText = extendCssText(box.style.cssText, cssText); + } + } + cont += "" + left + ""; } if(mid!=""){ @@ -94,12 +109,26 @@ export function updateInlineStringFormat(cell, attr, value, $input){ // cssText = removeClassWidthCss(cssText, attr); let cssText = getCssText(span.style.cssText, attr, value); + + if(inherit){ + let box = $(span).closest("#luckysheet-input-box").get(0); + if(box!=null){ + cssText = extendCssText(box.style.cssText, cssText); + } + } cont += "" + mid + ""; } if(right!=""){ - cont += "" + right + ""; + let cssText = span.style.cssText; + if(inherit){ + let box = $(span).closest("#luckysheet-input-box").get(0); + if(box!=null){ + cssText = extendCssText(box.style.cssText, cssText); + } + } + cont += "" + right + ""; } if(startContainer.parentNode.tagName=="SPAN"){ @@ -121,8 +150,8 @@ export function updateInlineStringFormat(cell, attr, value, $input){ } selectTextContent($textEditor.find("span").get(seletedNodeIndex)); - } - else{ + } + else{ if(startContainer.parentNode.tagName=="SPAN" && endContainer.parentNode.tagName=="SPAN"){ let startSpan = startContainer.parentNode, startSpanIndex; let endSpan = endContainer.parentNode, endSpanIndex; @@ -195,7 +224,7 @@ export function updateInlineStringFormat(cell, attr, value, $input){ selectTextContentCross(spans.get(startSeletedNodeIndex), spans.get(endSeletedNodeIndex)); } - } + } } else if($functionbox.length>0){ @@ -526,6 +555,64 @@ function getCssText(cssText, attr, value){ return cssText; } +function extendCssText(origin, cover, isLimit=true){ + let originArray = origin.split(";"); + let coverArray = cover.split(";"); + let newCss = ""; + + let addKeyList = {}; + for(let i=0;i= 112 && kcode <= 123) || kcode <= 46 || kcode == 144 || kcode == 108 || event.ctrlKey || event.altKey || (event.shiftKey && (kcode == 37 || kcode == 38 || kcode == 39 || kcode == 40 || kcode == keycode.WIN || kcode == keycode.WIN_R || kcode == keycode.MENU))) || kcode == 8 || kcode == 32 || kcode == 46 || (event.ctrlKey && kcode == 86)) { - if(event.target.id!="luckysheet-input-box" && event.target.id!="luckysheet-rich-text-editor"){ + // if(event.target.id!="luckysheet-input-box" && event.target.id!="luckysheet-rich-text-editor"){ formula.functionInputHanddler($("#luckysheet-functionbox-cell"), $("#luckysheet-rich-text-editor"), kcode); setCenterInputPosition(Store.luckysheetCellUpdate[0], Store.luckysheetCellUpdate[1], Store.flowdata); - } + // } } }).keyup(function (e) { @@ -872,7 +872,9 @@ export function keyboardInitial(){ //输入框中文输入后 shift 和 空格 处理 if(parseInt($("#luckysheet-input-box").css("top")) > 0 && (kcode == 13 || kcode == 16 || kcode == 32)){ - formula.functionInputHanddler($("#luckysheet-functionbox-cell"), $("#luckysheet-rich-text-editor"), kcode); + // if(event.target.id=="luckysheet-input-box" || event.target.id=="luckysheet-rich-text-editor"){ + // formula.functionInputHanddler($("#luckysheet-functionbox-cell"), $("#luckysheet-rich-text-editor"), kcode); + // } } e.preventDefault(); diff --git a/src/global/formula.js b/src/global/formula.js index 5f3ce09..b8fe635 100644 --- a/src/global/formula.js +++ b/src/global/formula.js @@ -1220,11 +1220,12 @@ const luckysheetformula = { let curv = Store.flowdata[r][c]; let isPrevInline = isInlineStringCell(curv); - let isCurInline = (inputText.slice(0, 1) != "=" && inputHtml.indexOf("span")>-1); + let isCurInline = (inputText.slice(0, 1) != "=" && inputHtml.substr(0,5) == "-1 // $editer.html(value1); - let w = window.getSelection(); - if(w!=null && w.type!="None"){ - let range = w.getRangeAt(0); - let c = range.startContainer; - if(c.id=="luckysheet-rich-text-editor" || $(c).closest("#luckysheet-rich-text-editor")){ - $functionbox.html(value); - } - else if(c.id=="luckysheet-functionbox-cell" || $(c).closest("#luckysheet-functionbox-cell")){ - if(value1.indexOf("span")>-1){ + // let w = window.getSelection(); + // if(w!=null && w.type!="None"){ + // let range = w.getRangeAt(0); + // let c = range.startContainer; - } - else{ - $editer.html(value); - } - } + // if(c.id=="luckysheet-rich-text-editor" || $(c).closest("#luckysheet-rich-text-editor")){ + // $functionbox.html(value); + // } + // else if(c.id=="luckysheet-functionbox-cell" || $(c).closest("#luckysheet-functionbox-cell")){ + // if(value1.indexOf("span")>-1){ + + // } + // else{ + // $editer.html(value); + // } + // } + // } + // console.trace(); + // console.log(value, $copy.attr("id")); + + if($copy.attr("id")=="luckysheet-rich-text-editor"){ + if($copy.html().substr(0,5) == "