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

Commit

Permalink
refactor(inline string): develop
Browse files Browse the repository at this point in the history
  • Loading branch information
DR-Univer committed Sep 20, 2020
1 parent 4c16847 commit 46b5b06
Show file tree
Hide file tree
Showing 14 changed files with 443 additions and 143 deletions.
8 changes: 4 additions & 4 deletions src/controllers/formulaBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ export function formulaBarInitial(){

let row_index = last["row_focus"], col_index = last["column_focus"];

let $input = $("#luckysheet-rich-text-editor"),value = $input.text();
if(value) {
formula.updatecell(row_index, col_index);
}
// let $input = $("#luckysheet-rich-text-editor"),value = $input.text();
// if(value) {
// formula.updatecell(row_index, col_index);
// }
luckysheetupdateCell(row_index, col_index, Store.flowdata, null, true);
formula.rangeResizeTo = $("#luckysheet-functionbox-cell");
}
Expand Down
16 changes: 6 additions & 10 deletions src/controllers/handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { selectHightlightShow, selectIsOverlap, selectionCopyShow, luckysheet_co
import selection from './selection';
import controlHistory from './controlHistory';
import splitColumn from './splitColumn';
import {hideMenuByCancel} from '../global/cursorPos';
import { luckysheetdefaultstyle } from './constant';

import {
Expand Down Expand Up @@ -232,6 +233,10 @@ export default function luckysheetHandler() {
}
});

$("#luckysheet-rich-text-editor").mouseup(function(e){
menuButton.inputMenuButtonFocus(e.target);
});

//表格mousedown
$("#luckysheet-cell-main, #luckysheetTableContent").mousedown(function (event) {
if($(event.target).hasClass('luckysheet-mousedown-cancel')){
Expand Down Expand Up @@ -4397,16 +4402,7 @@ export default function luckysheetHandler() {
//有批注在编辑时
luckysheetPostil.removeActivePs();

if (!$(event.target).hasClass("luckysheet-mousedown-cancel") && $(event.target).filter("[class*='sp-palette']").length == 0 && $(event.target).filter("[class*='sp-thumb']").length == 0 && $(event.target).filter("[class*='sp-']").length == 0) {
$("#luckysheet-rightclick-menu").hide();
$("#luckysheet-cols-h-hover").hide();
$("#luckysheet-cols-menu-btn").hide();
$("#luckysheet-rightclick-menu").hide();
$("#luckysheet-sheet-list, #luckysheet-rightclick-sheet-menu, #luckysheet-user-menu").hide();
$("body > .luckysheet-filter-menu, body > .luckysheet-filter-submenu, body > .luckysheet-cols-menu").hide();
//$("body > luckysheet-menuButton").hide();
Store.luckysheet_cols_menu_status = false;
}
hideMenuByCancel(event);

//点击功能栏时 如果是单元格编辑模式 则退出编辑模式
if ($(event.target).closest("#luckysheet-wa-editor").length > 0 && parseInt($("#luckysheet-input-box").css("top")) > 0) {
Expand Down
228 changes: 228 additions & 0 deletions src/controllers/inlineString.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,228 @@
import {getFontStyleByCell, textTrim} from "../global/getdata";
import locale from '../locale/locale';
import Store from '../store';

export function isInlineStringCell(cell){
let isIs = cell.ct!=null && cell.ct.t=="inlineStr" && cell.ct.s!=null && cell.ct.s.length>0;
return isIs;
}

export function isInlineStringCT(ct){
let isIs = ct!=null && ct.t=="inlineStr" && ct.s!=null && ct.s.length>0;
return isIs;
}

export function updateInlineStringFormat(cell, attr, value, $input){



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));
}
}
else{
Store.inlineStringEditCache = [{
v:cell.v
}];
}

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");

let endContainer = range.endContainer, startContainer = range.startContainer;
let endOffset = range.endOffset, startOffset = range.startOffset;

if($textEditor.length>0){
if(startContainer===endContainer){
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);

let cont = "";
if(left!=""){
cont += "<span style='"+ span.style.cssText +"'>" + left + "</span>";
}

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 += "<span style='"+ upsetClassWithCss(span.style.cssText, ukey, uvalue) +"'>" + mid + "</span>";
}

if(right!=""){
cont += "<span style='"+ span.style.cssText +"'>" + right + "</span>";
}

$(span).replaceWith(cont);
}
else{

}
}
else{

}
}
else if($functionbox.length>0){

}
}


export function convertCssToStyleList(cssText){
if(cssText==null || cssText.length==0){
return {};
}
let cssTextArray = cssText.split(";");
let styleList = {
"ff":"Arial", //font family
"fc":"#000000",//font color
"fs":12,//font size
"cl":0,//strike
"un":0,//underline
"bl":0,//blod
"it":0,//italic
};

const _locale = locale();
const locale_fontarray = _locale.fontarray;
const locale_fontjson = _locale.fontjson;

cssTextArray.forEach(s => {
s = s.toLowerCase();
let key = textTrim(s.substr(0, s.indexOf(':')));
let value = textTrim(s.substr(s.indexOf(':') + 1));
if(key=="font-weight"){
if(value=="bold"){
styleList["bl"] = 1;
}
else{
styleList["bl"] = 0;
}
}

if(key=="font-style"){
if(value=="italic"){
styleList["it"] = 1;
}
else{
styleList["it"] = 0;
}
}

if(key=="font-family"){
let ff = locale_fontjson[value];
if(ff==null){
styleList["ff"] = value;
}
else{
styleList["ff"] = ff;
}
}

if(key=="font-size"){
styleList["fs"] = parseInt(value);
}

if(key=="color"){
styleList["fc"] = value;
}

if(key=="text-decoration"){
if(value=="line-through"){
styleList["cl"] = 1;
}
else{
if(value=="underline"){
styleList["un"] = 1;
}
else{
styleList["cl"] = 0;
}
}
}

if(key=="lucky-strike"){
styleList["cl"] = value;
}

if(key=="lucky-underline"){
styleList["un"] = value;
}

});

return styleList;
}

function upsetClassWithCss(cssText, ukey, uvalue){
let cssTextArray = cssText.split(";");
let newCss = "";
if(cssText.indexOf(ukey)>-1){
for(let i=0;i<cssTextArray.length;i++){
let s = cssTextArray[i];
s = s.toLowerCase();
let key = textTrim(s.substr(0, s.indexOf(':')));
let value = textTrim(s.substr(s.indexOf(':') + 1));
if(ukey==key){
newCss += key + ":" + uvalue + ";";
}
else{
newCss += key + ":" + value + ";";
}
}
}
else{
cssText += ukey + ":" + uvalue + ";";
}

return cssText;
}

function removeClassWidthCss(cssText, ukey){
let cssTextArray = cssText.split(";");
let newCss = "";
if(cssText.indexOf(ukey)>-1){
for(let i=0;i<cssTextArray.length;i++){
let s = cssTextArray[i];
s = s.toLowerCase();
let key = textTrim(s.substr(0, s.indexOf(':')));
let value = textTrim(s.substr(s.indexOf(':') + 1));
if(ukey==key){
continue;
}
else{
newCss += key + ":" + value + ";";
}
}
}

return cssText;
}



2 changes: 1 addition & 1 deletion src/controllers/insertFormula.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const insertFormula = {
let _this = this;
let _locale = locale();
let locale_formulaMore = _locale.formulaMore;
let locale_button = _locale.button
let locale_button = _locale.button;

$(document).off("keyup.fxSFLI").on("keyup.fxSFLI", "#searchFormulaListInput", function(){
$("#formulaTypeList").empty();
Expand Down
Loading

0 comments on commit 46b5b06

Please sign in to comment.