안녕하세요:) 개발자 우디입니다! 아래 내용 관련하여 작업 중이신 분들께 도움이되길 바라며 글을 공유하니 참고 부탁드립니다😊
(이번에 벨로그로 이사오면서 예전 글을 옮겨적었습니다. 이 점 양해 부탁드립니다!)
마커 변경사항을 관리하는 History 생성
constructor(props, context) {
this.markerHistory = [];
this.redoHistory = [];
}
History에 작업 내역을 추가하는 함수
addToMarkerHistory = (reset = true) => {
let prevMarkerInfo = this.getMarkerInfo();
let currentMarkerHistory = this.getMarkerHistory();
currentMarkerHistory.push(prevMarkerInfo);
if (currentMarkerHistory.length > 50) {
currentMarkerHistory.shift();
}
if (reset) {
this.resetRedoHistory();
}
};
설명
추가적인 관련 함수들
getMarkerHistory = () => {
return this.markerHistory;
};
resetRedoHistory = () => {
this.redoHistory = [];
};
getRedoHistory = () => {
return this.redoHistory;
};
마커가 조작되는 모든 경우에 addToMarkerHistory 함수 추가
addMarker = (targetTime, duration, addOption) => {
...생략...
this.addToMarkerHistory(); //to save prevMarkerInfo
...생략...
};
사용자가 '실행 취소' 및 '되돌리기' 버튼을 눌렀을 때 실행되는 함수
undoHandler = cb => {
let currentMarkerHistory = this.getMarkerHistory();
let currentRedoHistory = this.getRedoHistory();
let currentMarkerInfo = this.getMarkerInfo();
if (currentMarkerHistory.length > 0) {
currentRedoHistory.push(currentMarkerInfo);
let undoResult = currentMarkerHistory[currentMarkerHistory.length - 1];
this.setState(
{
markerInfo: undoResult,
},
() => {
cb();
this.callUpdateTitleAfterChange(this.state.savedProjectFilePath);
},
);
currentMarkerHistory.pop();
}
};
redoHandler = cb => {
let currentMarkerHistory = this.getMarkerHistory();
let currentRedoHistory = this.getRedoHistory();
let currentMarkerInfo = this.getMarkerInfo();
if (currentRedoHistory.length > 0) {
currentMarkerHistory.push(currentMarkerInfo);
let redoResult = currentRedoHistory[currentRedoHistory.length - 1];
this.setState(
{
markerInfo: redoResult,
},
() => {
cb();
this.callUpdateTitleAfterChange(this.state.savedProjectFilePath);
},
);
currentRedoHistory.pop();
}
};