Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: undo slide behavior for text component (fixed #315 #310) #314

Merged
merged 24 commits into from
Feb 4, 2020

Conversation

jinwoo-kim-nhn
Copy link
Contributor

@jinwoo-kim-nhn jinwoo-kim-nhn commented Jan 29, 2020

Please check if the PR fulfills these requirements

  • It's submitted to right branch according to our branching model
  • It's right issue type on title
  • When resolving a specific issue, it's referenced in the PR's title (e.g. fix #xxx[,#xxx], where "xxx" is the issue number)
  • The commit message follows our guidelines
  • Tests for the changes have been added (for bug fixes/features)
  • Docs have been added/updated (for bug fixes/features)
  • It does not introduce a breaking change or has description for the breaking change

issue

문제점 파악 및 수정

1. 슬라이더 UI의 drag도중에는 undo 스택에 반영 안되도록 개선

  • rotate 기능에 구현된 부분을 참고하여 변경 (isSilent 플래그를 추가하여 운영)
  • fontSize가 변경될때는 마지막 스택의 텍스트 스타일 값을 항상 알고 있도록 변경하고, 그 값을 기준으로 동작 하도록 변경

2. redo 실행시 이미 저장되어 있는 undoData가 새로운 잘못된 값으로 변질 되면서 재차 undo, redo 를 실행하면 정확한 동작을 보장하지 않는 버그 수정

  • redo 실행시 이미 undoData가 있으면 값이 변경되지 않도록 수정

3. 텍스트 객체를 선택하면 UI에 반영이 안되는 현상 개선

  • ui/text.js에 setTextStyleStateOnAction 을 구현하여 요소가 선택되면 UI에 반영되도록 개선

4. underline 변경은 되돌려지지가 않는 현상 개선

5. undo, redo 실행시 텍스트 객체가 선택되어 있으면 텍스트 객체가 변하면서 UI상태도 변해야 하지만 변하지 않는 버그 수정

  • undo, redo 실행시 deactivateAll() 을 실행 함으로서 버그처럼 보이던 원인을 제거 (선택된 객체의 변경만 UI에 반영되면 되므로)

@jinwoo-kim-nhn jinwoo-kim-nhn changed the title Feat/undo slide behavior feat undo slide behavior for text component Jan 30, 2020
@jinwoo-kim-nhn jinwoo-kim-nhn changed the title feat undo slide behavior for text component fix: undo slide behavior for text component Jan 30, 2020
@jinwoo-kim-nhn jinwoo-kim-nhn changed the title fix: undo slide behavior for text component fix: undo slide behavior for text component (fixed #315) Jan 30, 2020
@jinwoo-kim-nhn jinwoo-kim-nhn changed the base branch from fix/incorrectedUndoAngleForUndoData to master January 30, 2020 03:22
@jinwoo-kim-nhn jinwoo-kim-nhn changed the title fix: undo slide behavior for text component (fixed #315) fix: undo slide behavior for text component (fixed #315 #310) Jan 30, 2020
return new Promise((resolve, reject) => {
if (!graphics.contains(this.undoData.object)) {
graphics.add(this.undoData.object);
resolve(this.undoData.object);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this.undoData.object는 캐싱할 수 있겠네요. 그리고 this.undoData가 없는 상황의 optional 처리는 필요하지 않을까요?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

interface/command.js 의 생성자에서 this.undoData = {} 를 만들어 주고 있어서 딱히 optional 처리를 안해줘도 될것같습니다.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this.undoData.object 는 캐싱하도록 하겠습니다. 감사합니다

return textComp.add(text, options).then(objectProps => {
this.undoData.object = graphics.getObject(objectProps.id);
const textObject = graphics.getObject(objectProps.id);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

objectProps.id는 그냥 디스트럭쳐링 해도 될 것 같아요

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

넵 반영하겠습니다. 감사합니다.

targetObj.lastfontSizeUndoStack = targetObj[key];
undoData.styles[key] = undoValue;
} else {
undoData.styles[key] = undoValue;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 코드는 두 분기 모두에서 실행되니, else 문은 필요 없어보입니다.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

그렇네요. 감사합니다. 반영하겠습니다.

const textComp = graphics.getComponent(TEXT);
const targetObj = graphics.getObject(id);
const isRedo = Object.keys(this.undoData).length;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Object.keys()를 사용해야 하나요? 특정 프로퍼티가 있는지를 확인하는게 더 안전하지 않을까 생각됩니다.

makeUndoData()내부를 보니 object, styles 프로퍼티가 있는지만 보면 되겠네요.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isRedo는 command.isRedo 함수로 빼서 Command의 기능으로 공통화 시키면 좋게습니다.

Copy link
Contributor Author

@jinwoo-kim-nhn jinwoo-kim-nhn Feb 4, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

넵 그렇네요. shape쪽 pr에 같은 리뷰를 달아 주셔서 그쪽에서 일괄 처리해보겠습니다.

src/js/action.js Outdated
fontFamily: 'Noto Sans',
fontStyle: this.ui.text.fontStyle,
fontWeight: this.ui.text.fontWeight,
underline: this.ui.text.underline
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this.ui.text를 캐싱할 수 있을 것 같습니다.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

제 의견은, destructuring하고 shorthand property를 쓰면 코드가 좀 더 깔끔해 질 것 같아요.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이부분은 동식 책임님 의견으로 고치겠습니다.

Copy link
Contributor

@dongsik-yoo dongsik-yoo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[02/04] 리뷰 완료했습니다. 수고하셨습니다.

@@ -264,9 +266,9 @@ export default {
*/
_textAction() {
return extend({
changeTextStyle: styleObj => {
changeTextStyle: (styleObj, isSilent) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

파라미터 이름이 isSilent인 것이 잘 와닿지 않습니다. undo 스택에 쌓지 않는다는 의미를 담고 있지 못한 것 같아요. undoable과 같은 이름은 어떨까요?

Copy link
Contributor Author

@jinwoo-kim-nhn jinwoo-kim-nhn Feb 4, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 부분은 undoable이 더 명확할것 같네요. 다른 작업의 브랜치들에서 같은 이름으로 작업중이어서 이번 pr에 고치지 않고 마지막 filter쪽 연관 이슈가 작업된 pr에서 일괄적으로 고치겠습니다.

src/js/action.js Outdated
fontFamily: 'Noto Sans',
fontStyle: this.ui.text.fontStyle,
fontWeight: this.ui.text.fontWeight,
underline: this.ui.text.underline
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

제 의견은, destructuring하고 shorthand property를 쓰면 코드가 좀 더 깔끔해 질 것 같아요.

return textComp.add(text, options).then(objectProps => {
this.undoData.object = graphics.getObject(objectProps.id);
const textObject = graphics.getObject(objectProps.id);
textObject.lastfontSizeUndoStack = textObject.fontSize;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

각 오브젝트나 클래스에 last~~ 를 추가하는 패턴이 계속 추가될 것 같은데요, 각 객체마다 값을 들고 있지 않고, undo 쪽에 구조를 만들어서 undo에 필요한 데이터를 들고 있는 것은 어떨까요?

Copy link
Contributor Author

@jinwoo-kim-nhn jinwoo-kim-nhn Feb 4, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

텍스트 쪽은 여러개의 텍스트 객체가 생길 수 있고 텍스트 객체마다 다른 상태의 last~~ 값을 가져야 하므로 객체마다 값을 들고 있게 하였습니다.

this.undoData에서 관리하는것은 command의 인스턴스가 들고 있으므로 데이터를 필요할때 commandStack을 전부 뒤져서 써야 하므로 적합하지 않은것 같고.

다른 구조를 만들더라도 텍스트 객체가 추가되거나 삭제될때마다 텍스트객체 아이디 별로 값을 관리해 줘야 하는 관리하기 복잡한 코드가 생길것 같습니다. 현재로서는 target 객체가 last 값을 알고 있는게 가장 효율적이라고 생각이 듭니다. 작업하면서 해당 부분이 거슬리긴 했지만... 더 좋은 방법이 생각나기 전까지는 이 방법이 가장 효율적일것 같습니다.

Copy link
Contributor Author

@jinwoo-kim-nhn jinwoo-kim-nhn Feb 4, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 부분은 구두로 논의한 방식으로 커멘드의 undoData 를 활용하는 방식으로 수정하겠습니다. 다른 pr에서도 다 같은 방식으로 사용중이어서 이슈를만들어 한꺼번에 처리하겠습니다.

function makeUndoData(styles, targetObj, isSilent) {
const undoData = {};

undoData.object = targetObj;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 두 줄은 변수 선언할 때 같이 작성하면 코드가 줄겠네요.

Copy link
Contributor Author

@jinwoo-kim-nhn jinwoo-kim-nhn Feb 4, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

넵 이 부분 저도 고치려고 생각만 하고 있다가. 아직까지 못고쳤네요.. 반영하겠습니다.감사합니다.

const textComp = graphics.getComponent(TEXT);
const targetObj = graphics.getObject(id);
const isRedo = Object.keys(this.undoData).length;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isRedo는 command.isRedo 함수로 빼서 Command의 기능으로 공통화 시키면 좋게습니다.

* @param {string} textDecoration - text decoration option string
* @returns {object} adapt object for override
*/
_getTextDecorationAdaptObject(textDecoration) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

질문입니다. textDecoration가 문자열이라 이 함수가 리턴하는 객체의 프러퍼티는 1개만 true일거 같은데요, 그러면 3가지 속성을 동시에 설정할 수는 없는 거예요?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

예전 fabricjs버전에서는 안되었었기 때문에 현재 imageEditor에서도 하나씩 뿐이 선택 안되도록 되어있고, 업데이트된 fabricjs버전에서는 3개 동시에 적용 가능하지만, 저희 옵션도 수정해야되서 옵션 인터페이스 수정이 필요합니다. 이 이슈의 작업과는 직접적인 관계가 없으므로 새로운 이슈를 만들어서 추후에 개선하겠습니다.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

히스토리가 있었군요. 더 멋진 이미지 에디터를 위해 애써 주셔서 감사합니다.

changeTextStyle(id, styleObj) {
return this.execute(commands.CHANGE_TEXT_STYLE, id, styleObj);
changeTextStyle(id, styleObj, isSilent) {
const executeMethodName = isSilent ? 'executeSilent' : 'execute';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

silent는 네이밍이 좀 안 맞는거 같아요 ㅠ

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

넵 이 부분은 다음 이슈에서 일괄 수정해보겠습니다.


setAlignState(value) {
const button = this._els.textAlignButton;
button.classList.remove(this.align);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

우리가 IE9+ 이상 지원이라 classList를 쓸 수가 없을 것 같은데요, 확인 부탁 드립니다.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

코드에 폴리필을 'src/js/polyfill.js' 넣어서 사용중입니다.

@jinwoo-kim-nhn jinwoo-kim-nhn merged commit 73c528d into master Feb 4, 2020
@jinwoo-kim-nhn jinwoo-kim-nhn deleted the feat/undoSlideBehavior branch March 20, 2020 08:13
HerlinMatos pushed a commit to EveryMundo/tui.image-editor that referenced this pull request Jul 2, 2020
…hn#314)

* middle commit

* feat: apply input ui in range component

* feat: appy value with change input

* feat: some refactoring (change naming, added jsdoc)

* fix: added jsdoc for missing jsdoc

* feat: some refactoring for remove event binding

* fix: rotation setAngle undo bug

* feat: improve undo slide behavior for text component - middle commit

* fix: undo redo bug for text menu - prototype commit

* feat: added test for text change undo redo

* middle commit

* feat: apply input ui in range component

* feat: appy value with change input

* feat: some refactoring (change naming, added jsdoc)

* feat: some refactoring for remove event binding

* feat: improve undo slide behavior for text component - middle commit

* fix: undo redo bug for text menu - prototype commit

* feat: added test for text change undo redo

* fix: incorrected rebase line delete

* fix: unnessary text style property (textDecoration)

* fixed: some refactoring

* fix: fixed incorrected text option

* fix: apply codereview

Co-authored-by: superlucky84 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants