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

Commit

Permalink
feat(zoom redo undo suport): redo undo
Browse files Browse the repository at this point in the history
  • Loading branch information
tubiaoge committed Aug 19, 2020
1 parent 11ba536 commit 4d03906
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 19 deletions.
13 changes: 13 additions & 0 deletions src/controllers/controlHistory.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import server from './server';
import pivotTable from './pivotTable';
import conditionformat from './conditionformat';
import luckysheetPostil from './postil';
import {zoomRefreshView,zoomNumberDomBind} from './zoom';
import { createFilter, createFilterOptions, labelFilterOptionState } from './filter';
import formula from '../global/formula';
import json from '../global/json';
Expand Down Expand Up @@ -322,6 +323,12 @@ const controlHistory = {
}
}
}
else if (ctr.type=="zoomChange"){
Store.zoomRatio = ctr.zoomRatio;
server.saveParam("all", ctr.currentSheetIndex, ctr.zoomRatio, { "k": "zoomRatio" });
zoomNumberDomBind();
zoomRefreshView();
}

cleargridelement(e);
Store.clearjfundo = true;
Expand Down Expand Up @@ -542,6 +549,12 @@ const controlHistory = {
}
}
}
else if (ctr.type=="zoomChange"){
Store.zoomRatio = ctr.curZoomRatio;
server.saveParam("all", ctr.currentSheetIndex, ctr.curZoomRatio, { "k": "zoomRatio" });
zoomNumberDomBind();
zoomRefreshView();
}

Store.clearjfundo = true;
}
Expand Down
51 changes: 32 additions & 19 deletions src/controllers/zoom.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import locale from '../locale/locale';
import { replaceHtml } from '../utils/util';
import {changeSheetContainerSize} from './resize';
import { jfrefreshgrid_rhcw } from '../global/refresh';
import server from './server';



Expand All @@ -13,27 +14,39 @@ export function zoomChange(ratio){
return;
}

Store.zoomRatio = ratio;

clearTimeout(luckysheetZoomTimeout);
luckysheetZoomTimeout = setTimeout(() => {
if (Store.clearjfundo) {
Store.jfredo.push({
"type": "zoomChange",
"zoomRatio": Store.zoomRatio,
"curZoomRatio": ratio,
"sheetIndex": Store.currentSheetIndex,
});
}

Store.zoomRatio = ratio;

server.saveParam("all", Store.currentSheetIndex, Store.zoomRatio, { "k": "zoomRatio" });

let $scrollLeft = $("#luckysheet-scrollbar-x"), $scrollTop = $("#luckysheet-scrollbar-y");
let sl = $scrollLeft.scrollLeft(), st = $scrollTop.scrollTop();
zoomRefreshView();
}, 100);

}

let wp = $scrollLeft.find("div").width(), hp = $scrollTop.find("div").height();
export function zoomRefreshView(){
let $scrollLeft = $("#luckysheet-scrollbar-x"), $scrollTop = $("#luckysheet-scrollbar-y");
let sl = $scrollLeft.scrollLeft(), st = $scrollTop.scrollTop();

jfrefreshgrid_rhcw(Store.flowdata.length, Store.flowdata[0].length);
changeSheetContainerSize();
let wp = $scrollLeft.find("div").width(), hp = $scrollTop.find("div").height();

let wc = $scrollLeft.find("div").width(), hc = $scrollTop.find("div").height();
jfrefreshgrid_rhcw(Store.flowdata.length, Store.flowdata[0].length);
changeSheetContainerSize();

$scrollLeft.scrollLeft(sl+wc-wp);
$scrollTop.scrollTop(st+hc-hp);
let wc = $scrollLeft.find("div").width(), hc = $scrollTop.find("div").height();

}, 100);


$scrollLeft.scrollLeft(sl+wc-wp);
$scrollTop.scrollTop(st+hc-hp);
}


Expand All @@ -58,7 +71,7 @@ export function zoomInitial(){
currentRatio = 0.1;
}

Store.zoomRatio = currentRatio;
// Store.zoomRatio = currentRatio;
zoomChange(currentRatio);
zoomNumberDomBind(currentRatio);
});
Expand All @@ -82,16 +95,16 @@ export function zoomInitial(){
currentRatio = 4;
}

Store.zoomRatio = currentRatio;
// Store.zoomRatio = currentRatio;
zoomChange(currentRatio);
zoomNumberDomBind(currentRatio);
});

$("#luckysheet-zoom-slider").click(function(e){
$("#luckysheet-zoom-slider").mousedown(function(e){
let xoffset = $(this).offset().left, pageX = e.pageX;

let currentRatio = positionToRatio(pageX-xoffset);
Store.zoomRatio = currentRatio;
// Store.zoomRatio = currentRatio;
zoomChange(currentRatio);
zoomNumberDomBind(currentRatio);
});
Expand All @@ -118,7 +131,7 @@ export function zoomInitial(){
pos = 0;
}

Store.zoomRatio = currentRatio;
// Store.zoomRatio = currentRatio;
zoomChange(currentRatio);
let r = Math.round(currentRatio*100) + "%";
$("#luckysheet-zoom-ratioText").html(r);
Expand All @@ -136,7 +149,7 @@ export function zoomInitial(){
});

$("#luckysheet-zoom-ratioText").click(function(){
Store.zoomRatio = 1;
// Store.zoomRatio = 1;
zoomChange(1);
zoomNumberDomBind(1);
});
Expand Down

0 comments on commit 4d03906

Please sign in to comment.