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

Commit

Permalink
feat(inline string): operation like excel
Browse files Browse the repository at this point in the history
support inline string
  • Loading branch information
tubiaoge committed Sep 21, 2020
1 parent 46b5b06 commit 9ac9f08
Show file tree
Hide file tree
Showing 9 changed files with 548 additions and 183 deletions.
325 changes: 276 additions & 49 deletions src/controllers/inlineString.js

Large diffs are not rendered by default.

9 changes: 8 additions & 1 deletion src/controllers/keyboard.js
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
16 changes: 15 additions & 1 deletion src/controllers/menuButton.js
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 @@ -2982,7 +2993,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);
}
}

if(attr == "tb" || attr == "tr" || attr == "fs"){
Expand Down Expand Up @@ -3352,6 +3365,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
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
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
}

0 comments on commit 9ac9f08

Please sign in to comment.