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

Commit

Permalink
fix(fix wrap bug): alt + enter twice bug
Browse files Browse the repository at this point in the history
  • Loading branch information
DR-Univer committed Sep 24, 2020
1 parent b9b474b commit 789bab5
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 20 deletions.
52 changes: 45 additions & 7 deletions src/controllers/inlineString.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ export function updateInlineStringFormat(cell, attr, value, $input){
}
}

export function enterKeyControll(){
export function enterKeyControll(cell){
var w = window.getSelection();

if(w.type=="None"){
Expand All @@ -228,7 +228,12 @@ export function enterKeyControll(){

if($textEditor.length>0){
let startSpan = startContainer.parentNode;
let startSpanIndex = $textEditor.find("span").index(startSpan);
if(startContainer.id=="luckysheet-rich-text-editor"){
startSpan = $(startContainer).find("span");
startSpan = startSpan.get(startSpan.length-1);
startOffset = startSpan.innerHTML.length;
}
// let startSpanIndex = $textEditor.find("span").index(startSpan);
if(range.collapsed===false){
range.deleteContents();
}
Expand All @@ -240,15 +245,48 @@ export function enterKeyControll(){
sleft = startContent.substring(s1, s2);
sright = startContent.substring(s2, startContent.length);

let cont = "<span style='"+ startSpan.style.cssText +"'>" + sleft + "\n" + sright + "</span>";
let spanIndex;

let spanIndex,cont;
if(startContainer.parentNode.tagName=="SPAN"){
spanIndex = $textEditor.find("span").index(startSpan);
let textSpan = $textEditor.find("span");
spanIndex = textSpan.index(startSpan);
if((spanIndex==textSpan.length-1) && sright==""){
let txt = textSpan[spanIndex].innerHTML;
if(txt.substr(txt.length-1, 1)=="\n"){
cont = "<span style='"+ startSpan.style.cssText +"'>" + sleft + "\n" + "</span>";
}
else{
cont = "<span style='"+ startSpan.style.cssText +"'>" + sleft + "\n\n" + "</span>";
}

}
else{
cont = "<span style='"+ startSpan.style.cssText +"'>" + sleft + "\n" + sright + "</span>";
}

$(startSpan).replaceWith(cont);
}
else{
spanIndex = 0;
$(startSpan).html(cont);

let cssText = getFontStyleByCell(cell);
if(sright==""){
cont = "<span style='"+ cssText +"'>" + sleft + "\n\n" + "</span>";
}
else{
cont = "<span style='"+ cssText +"'>" + sleft + "\n" + sright + "</span>";
}

if(startContainer.id=="luckysheet-rich-text-editor"){
$(startSpan).replaceWith(cont);
let textSpan = $textEditor.find("span");
spanIndex = textSpan.length-1;
startOffset = textSpan.get(spanIndex).innerHTML.length-1;
}
else{
$(startSpan).html(cont);
spanIndex = 0;
}

}

selectTextContentCollapse($textEditor.find("span").get(spanIndex), startOffset+1);
Expand Down
4 changes: 3 additions & 1 deletion src/controllers/keyboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,9 @@ export function keyboardInitial(){
let $inputbox = $("#luckysheet-input-box");

if((altKey || event.metaKey) && kcode == keycode.ENTER && parseInt($inputbox.css("top")) > 0){
enterKeyControll();
let last = Store.luckysheet_select_save[Store.luckysheet_select_save.length - 1];
let row_index = last["row_focus"], col_index = last["column_focus"];
enterKeyControll(Store.flowdata[row_index][col_index]);
event.preventDefault();
}
else if (kcode == keycode.ENTER && parseInt($inputbox.css("top")) > 0) {
Expand Down
35 changes: 27 additions & 8 deletions src/global/cursorPos.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,10 @@ function selectTextDom(ele){
if (window.getSelection) {
let range = document.createRange();
range.selectNodeContents(ele);
window.getSelection().removeAllRanges();
window.getSelection().addRange(range);
if(range.startContainer && isInPage(range.startContainer)){
window.getSelection().removeAllRanges();
window.getSelection().addRange(range);
}
}
else if (document.selection) {
let range = document.body.createTextRange();
Expand All @@ -80,8 +82,10 @@ function selectTextContent(ele){
var content=ele.firstChild;
range.setStart(content,0);
range.setEnd(content,content.length);
window.getSelection().removeAllRanges();
window.getSelection().addRange(range);
if(range.startContainer && isInPage(range.startContainer)){
window.getSelection().removeAllRanges();
window.getSelection().addRange(range);
}
}
else if (document.selection) {
let range = document.body.createTextRange();
Expand All @@ -96,22 +100,37 @@ function selectTextContentCross(sEle, eEle){
var sContent=sEle.firstChild, eContent=eEle.firstChild;
range.setStart(sContent,0);
range.setEnd(eContent,eContent.length);
window.getSelection().removeAllRanges();
window.getSelection().addRange(range);
if(range.startContainer && isInPage(range.startContainer)){
window.getSelection().removeAllRanges();
window.getSelection().addRange(range);
}
}
}

function selectTextContentCollapse(sEle, index){
if (window.getSelection) {
let range = document.createRange();
var sContent=sEle.firstChild;
if(index>sContent.length){
index=sContent.length;
}
else if(index<0){
index = 0;
}
range.setStart(sContent,index);
range.collapse(true);
window.getSelection().removeAllRanges();
window.getSelection().addRange(range);
if(range.startContainer && isInPage(range.startContainer)){
window.getSelection().removeAllRanges();
window.getSelection().addRange(range);
}

}
}

function isInPage(node) {
return (node === document.body) ? false : document.body.contains(node);
}

export {
luckysheetRangeLast,
getCursortPosition,
Expand Down
6 changes: 4 additions & 2 deletions src/global/formula.js
Original file line number Diff line number Diff line change
Expand Up @@ -888,14 +888,16 @@ const luckysheetformula = {
let $cell = _this.getrangeseleciton();
_this.searchFunctionCell = $cell;



if ($cell == null || $editer == null) {
return;
}

let inputContent = $editer.text();
let searchtxt = $cell.text().toUpperCase();
let reg = /^[a-zA-Z]|[a-zA-Z_]+$/;

if (!reg.test(searchtxt)) {
if (!reg.test(searchtxt) || inputContent.substr(0, 1)!="=") {
return;
}

Expand Down
4 changes: 2 additions & 2 deletions src/global/getRowlen.js
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ function getCellTextInfo(cell , ctx, option){
for(let x=0;x<splitArr.length;x++){
let newValue = splitArr[x];

if(newValue==""){
if(newValue=="" && x!=splitArr.length-1){
inlineStringArr.push({
fontset:scfontset,
fc:fc==null?"#000":fc,
Expand Down Expand Up @@ -366,7 +366,7 @@ function getCellTextInfo(cell , ctx, option){

}

if(x!=splitArr.length-1 && !(preNewValue=="" && newValue=="") ){
if(x!=splitArr.length-1 && preNewValue!="" ){
inlineStringArr.push({
fontset:scfontset,
fc:fc==null?"#000":fc,
Expand Down

0 comments on commit 789bab5

Please sign in to comment.