# 도구 모드로 이미지를 업로드하면 커서가 줄 끝으로 이동

**URL:** https://meta.discourse.org/t/caret-moves-to-end-of-line-when-uploading-an-image-via-toolbar/214822
**Category:** Bug
**Created:** [1월 14, 2022, 4:08오전 UTC](https://meta.discourse.org/t/caret-moves-to-end-of-line-when-uploading-an-image-via-toolbar/214822 "2022-01-14T04:08:24Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [1월 14, 2022, 4:08오전 UTC](https://meta.discourse.org/t/caret-moves-to-end-of-line-when-uploading-an-image-via-toolbar/214822/1 "2022-01-14T04:08:24Z")

</div>

하지만 업로드할 때 포커스가 이동하는 것을 확인했어요. 예를 들어 특정 위치에 포커스 커서가 있는데 업로드를 하면 이상한 위치로 이동하거든요? 제가 확인하고 싶은 주요 부분이 바로 이겁니다.

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [1월 14, 2022, 4:19오전 UTC](https://meta.discourse.org/t/caret-moves-to-end-of-line-when-uploading-an-image-via-toolbar/214822/2 "2022-01-14T04:19:04Z")

</div>

@martin 잠깐 확인해 줄 수 있을까요? 다만, 여기서 재현 방법을 알려주면 정말 좋겠습니다. 어떻게 업로드하시나요 (잘라 붙여넣기, 드래그 앤 드롭, 툴바)? 브라우저는 무엇인가요 (크롬이라고 가정하고)? … 이전의 본문 + 커서는 어떻게 되고, 이후에는 어떻게 되나요?

---

<div class="post-metadata">

### Author: ![martin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/martin/32/491371_2.png) [@martin](https://meta.discourse.org/u/martin)
#### Post date: [1월 14, 2022, 4:36오전 UTC](https://meta.discourse.org/t/caret-moves-to-end-of-line-when-uploading-an-image-via-toolbar/214822/3 "2022-01-14T04:36:09Z")

</div>

제가 이해한 대로, 업로드가 완료된 후에도 커서를 원래 위치에 유지해야 한다는 뜻인가요? 문제를 재현할 수 있습니다:

1. 문장 중간을 클릭합니다.
2. 파일을 업로드합니다.
3. 커서가 문장 끝에 위치하게 됩니다.

![Peek 2022-01-14 14-32](https://global.discourse-cdn.com/meta/original/3X/2/3/23cd3dc2dccc93f86ae4648822a41a52188d87b8.gif)

제 GIF에서 볼 수 있듯이, 처리가 시작되는 즉시 커서가 문장 끝으로 이동합니다. 참고로 업로드 및 마크다운 처리는 적어도 올바른 위치에 삽입됩니다.

드래그 앤 드롭을 사용할 때는 커서가 있어야 할 위치에 그대로 유지되며, 붙여넣기할 때도 마찬가지입니다. 따라서 업로드 버튼 클릭 시에만 이 문제가 발생하는 것으로 보입니다.

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [1월 14, 2022, 4:37오전 UTC](https://meta.discourse.org/t/caret-moves-to-end-of-line-when-uploading-an-image-via-toolbar/214822/4 "2022-01-14T04:37:23Z")

</div>

네, 맞습니다. 아주 잘 설명해 주셨네요! 커서 위치만 유지하면 됩니다. 감사합니다!

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [1월 14, 2022, 4:45오전 UTC](https://meta.discourse.org/t/caret-moves-to-end-of-line-when-uploading-an-image-via-toolbar/214822/5 "2022-01-14T04:45:17Z")

</div>

> [@martin](#):
>
> 그러니까 업로드 버튼을 클릭할 때만 이 문제가 발생하는 건가요?

@zogstrip @andrei가 이 일을 맡을 수 있을까요? 줄바꿈을 삽입하는 다른 기능과 관련이 있을 가능성이 높습니다.

또한 버그가 플레이스홀더를 처음 삽입할 때 발생하는지, 아니면 플레이스홀더를 업로드로 교체한 후에 발생하는지 신중하게 판단해야 합니다. 제 직감으로는 플레이스홀더가 추가된 시점에 문제가 발생하는 것 같습니다.

전용 버그 티켓으로 이동합니다.

---

<div class="post-metadata">

### Author: ![zogstrip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zogstrip/32/512781_2.png) [@zogstrip](https://meta.discourse.org/u/zogstrip)
#### Post date: [1월 14, 2022, 9:39오전 UTC](https://meta.discourse.org/t/caret-moves-to-end-of-line-when-uploading-an-image-via-toolbar/214822/6 "2022-01-14T09:39:26Z")

</div>

@andrei 이걸 목록에 추가할 수 있을까요?

사용자가 업로드를 추가할 수 있는 방법이 다양해서 다소 까다로운 작업이 될 수 있어요.

---

<div class="post-metadata">

### Author: ![andrei](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/andrei/32/205142_2.png) [@andrei](https://meta.discourse.org/u/andrei)
#### Post date: [1월 14, 2022, 11:41오전 UTC](https://meta.discourse.org/t/caret-moves-to-end-of-line-when-uploading-an-image-via-toolbar/214822/7 "2022-01-14T11:41:14Z")

</div>

> [@zogstrip](#):
>
> @andrei 이걸 목록에 추가해 줄 수 있어?

네, 처리하겠습니다. 샘이 말한 것처럼 이건 아마 [줄바꿈 문제](https://meta.discourse.org/t/faster-and-smaller-uploads-in-discourse-with-rust-webassembly-and-mozjpeg-blog/196998/20)와 관련이 있을 겁니다.

---

<div class="post-metadata">

### Author: ![andrei](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/andrei/32/205142_2.png) [@andrei](https://meta.discourse.org/u/andrei)
#### Post date: [2월 3, 2022, 10:03오후 UTC](https://meta.discourse.org/t/caret-moves-to-end-of-line-when-uploading-an-image-via-toolbar/214822/8 "2022-02-03T22:03:50Z")

</div>

문제를 수정하는 방법은 다음과 같습니다:

> <https://github.com/discourse/discourse/pull/15684>
>
> When uploading an image, we change the uploading placeholder several times. Ever…y time, we correct the position of the cursor after replacing. But we schedule repositioning of cursor to the \`afterRender\` queue in Ember Run Loop. As a result, sometimes we replace the placeholder several times but correct the cursor position only once at the end. 
> 
> It just cannot work correctly with scheduling, we'll always be dealing with cumulative error. Removing scheduling fixes the problem.
> 
> Sadly, I cannot make the test work, I skipped it for now, going to give it another try later.

---

<div class="post-metadata">

### Author: ![zogstrip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zogstrip/32/512781_2.png) [@zogstrip](https://meta.discourse.org/u/zogstrip)
#### Post date: [10월 5, 2023, 3:33오후 UTC](https://meta.discourse.org/t/caret-moves-to-end-of-line-when-uploading-an-image-via-toolbar/214822/11 "2023-10-05T15:33:26Z")

</div>

여기서 회귀(regression)가 발생한 것 같습니다 🤔

도구 모음, 드래그 앤 드롭, 복사 & 붙여넣기 중 어떤 방식으로 업로드를 하든, 커서가 게시물(줄)의 끝으로 이동합니다.

최소 최신 macOS / Safari에서는 그렇습니다.

@cvx 이 문제를 아시는 분이 있을까요? 수정이 어렵다면 이 이슈를 포기하는 것도 괜찮습니다.
