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

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
wpxp123456 committed Sep 22, 2020
2 parents 735d1c8 + e980cd9 commit 606e054
Show file tree
Hide file tree
Showing 10 changed files with 689 additions and 212 deletions.
384 changes: 325 additions & 59 deletions src/controllers/inlineString.js

Large diffs are not rendered by default.

9 changes: 8 additions & 1 deletion src/controllers/keyboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';


Expand Down Expand Up @@ -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"));
}
Expand Down
28 changes: 24 additions & 4 deletions src/controllers/menuButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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(){
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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)!="="){
Expand Down Expand Up @@ -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 };
Expand All @@ -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 = {};
Expand Down Expand Up @@ -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;
Expand Down
13 changes: 3 additions & 10 deletions src/controllers/sheetBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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);
}

Expand Down
56 changes: 56 additions & 0 deletions src/global/cursorPos.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
4 changes: 2 additions & 2 deletions src/global/draw.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
Expand Down
Loading

0 comments on commit 606e054

Please sign in to comment.