-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
feat: smart task marker in markdown #1080
Conversation
for (let index = startLine, len = endLine; index <= len; index += 1) { | ||
mdNode = toastMark.findFirstNodeAtLine(index + 1); | ||
|
||
const { type } = mdNode; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이 부분은 두번만 쓰여서 할당하지 않고 바로쓰는게 더 깔끔하지 않을까요?
mdNode = toastMark.findFirstNodeAtLine(index + 1);
if (mdNode.type === 'list' || mdNode.type === 'item') {
changeTaskState(mdNode, index, cm);
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
요건 항상 고민이네요. 프로퍼티에 여러 번 접근하고 싶지않아서 보통 변수에 할당해서 사용하는데
여기선 한줄로 줄이는게 더 깔끔해보이네요ㅎ
return findClosestNode( | ||
mdNode, | ||
node => | ||
(node.type === 'paragraph' || node.type === 'codeBlock') && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
codeBlock
도 체크할 필요가 있나요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
item
노드에 자식으로 올 수 있는 블록 요소가 파라그래프, 코드 블럭이 있어서 둘 다 체크했습니다~
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
음 테스트해보니 그런 경우 제대로 동작안하는 것 같은대요. task list 자식 노드로 코드블럭이 오는 경우를 제대로 고려하려면 지금보다 더 복잡해질 것 같은데.. 사실 거의 없는 사용성일 것 같은데 이런 케이스는 아예 제외하는게 어떨까요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const taskMarkerLen = spaces + stateChar.length; | ||
const hasOnlySpaces = taskMarkerLen > 1 && !stateChar; | ||
|
||
if (!hasOnlySpaces) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
긍정조건으로 만들어 체크하는게 더 가독성에 좋을 것 같습니다~!
if (hasTaskMarker) {
// ...
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이 두 가지 케이스를 모두 커버하는 조건이라 변수명이라던지 조금 애매하네요. 요것도 다시 정리해보겠습니다~
[ x] -> [x]
[] -> [ ]
taskMarkerLen ? stateChar : ' ', | ||
startPos, | ||
addChPos(startPos, spaces ? spaces + 1 : 0) | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
아래처럼은 어떨까요?
const char = stateChar || ' ';
cm.replaceRange(char, startPos, addChPos(startPos, spaces ? spaces + 1 : 0));
apps/editor/src/js/markdownEditor.js
Outdated
const { from, to, text } = ev; | ||
|
||
const changed = text.map(line => { | ||
const list = LIST_RX.exec(line); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
아.. 여긴 이렇게 정규식으로 체크할 수 밖에 없군요..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
음 그런데 생각해보니까 붙여넣기 하고나서 change
이벤트가 발생하면 그 때 알아서 처리되지않나요? 현재는 changeTextToTaskMarker
내의 로직이 커서 기준으로 처리되어서 마지막 줄만 처리되는데 change
이벤트에서 cmEvent
기준으로 처리하면 붙여넣기 할때 사전처리없이 알아서 변환될 것 같아요
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
그 방법을 시도를 안해본것은 아닙니다만.. 붙여넣기를 하는 경우에는 cm.replaceRange()
가 라인 수만큼 발생해서 무한 루프에 빠지더라고요. 일단 정규식으로 선처리하는 방식이 아름답지 않은게 코드블럭 안에 리스트가 들어가는 경우를 체크할 수 없어서.. 요건 좀 더 확인해볼게요~
현재 task marker 안에서 스페이스를 입력하면 자동으로 변환해주는 로직 때문에 아무 동작을 안하는대요. 이런 경우는 버그처럼 보일 수도 있을 것 같아요. 공백이나 탭키가 입력되었을 때는 변환되지 않도록 막는게 맞지 않을까요? 편의를 위해서 자동으로 변환해주는 것은 좋지만 사용자의 키 입력 동작을 막아버리면 안될 것 같아요. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
리뷰 완료입니다. 단축키가 생기니까 훨씬 편하네요~! :)
[07/08] 리뷰완료. |
2e01a7b
to
69d92e7
Compare
7057fba
to
6fecca5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
깔끔하게 끝났네요. 고생하셨습니다! 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[07/14] 리뷰완료.
고생하셨습니다~!
Please check if the PR fulfills these requirements
fix #xxx[,#xxx]
, where "xxx" is the issue number)Description
What is the smart task marker?
The smart task marker is a function that changes the marker syntax of the task according to user convenience in the Markdown editor.
Use case 1: entering key
Change the marker according to the value entered in the marker syntax.
When a value is entered in empty square brackets
Spaces are deleted only when the value entered in square brackets is
x
orX
.When there is no value in the square brackets or it is deleted
Add one space in square brackets.
Use case 2: using shortcut
Change the marker when
Shift + Ctrl + X
is pressed in the task syntax. If the line is a task regardless of the cursor position, the state of the marker is toggled. If there are multiple lines of selection, the state of the markers should all change.Thank you for your contribution to TOAST UI product. 🎉 😘 ✨