Page MenuHomePhabricator

[web][fix] Fixed cursor issue in the message editing
ClosedPublic

Authored by kuba on May 31 2023, 12:39 AM.
Tags
None
Referenced Files
Unknown Object (File)
Mon, Apr 22, 2:23 PM
Unknown Object (File)
Mon, Apr 22, 2:23 PM
Unknown Object (File)
Mon, Apr 22, 2:23 PM
Unknown Object (File)
Mon, Apr 22, 2:23 PM
Unknown Object (File)
Mon, Apr 22, 2:19 PM
Unknown Object (File)
Mar 16 2024, 7:10 AM
Unknown Object (File)
Mar 16 2024, 7:10 AM
Unknown Object (File)
Mar 16 2024, 7:10 AM
Subscribers

Details

Summary

There was a bug, where after typing the character the cursor was moved to the end of the text area. It made editing the middle of the content very cumbersome. This address this issue, now focusAndUpdateText() method is called only once, not after every text change.

Raised in https://linear.app/comm/issue/ENG-3981/[web]-fix-cursor-moving-to-the-end-of-the-textbox-after-character

Test Plan
  • Entered edit mode on the web
  • Checked if the textarea is focused
  • Edited the message in the middle, checked if the cursor is not moved to the end

Diff Detail

Repository
rCOMM Comm
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

kuba edited the summary of this revision. (Show Details)
web/chat/chat-input-text-area.react.js
69 ↗(On Diff #27292)

Would it be bad to add updateHeight to the dep list here?

web/chat/chat-input-text-area.react.js
69 ↗(On Diff #27292)

This results in this warning thrown all the time:

Warning: Maximum update depth exceeded. This can happen when a component calls setState inside useEffect, but useEffect either doesn't have a dependency array, or one of the dependencies changes on every render.
web/chat/chat-input-text-area.react.js
69 ↗(On Diff #27292)

Can you investigate why adding updateHeight to the dep list causes a stack overflow? In particular, I'd like to understand why onChangePosition is getting changed when the height changes

kuba added inline comments.
web/chat/chat-input-text-area.react.js
69 ↗(On Diff #27292)

I believe that this is why it causes a stack overflow:

  • updateHeight() depend on onChangePosition() which calls updateDimensions() in edit-text-message.react.js.
  • updateDimensions() then recalculates the position of the background edit box and updates the edit state by calling updatePosition().
  • When the edit state is updated, the updatePosition (in edit-message-provider.js) is recalculated, causing the recalculation of updateDimensions() which is passed to onChangePosition().
ashoat added inline comments.
web/chat/chat-input-text-area.react.js
69 ↗(On Diff #27292)

Makes sense! Can you add this code comment for clarity? (Make sure lines are <=80 chars each)

// We want to update the height when the text changes. We can't include
// updateHeight in the dep list because it causes a stack overflow... see
// comments on D8035 for more details
This revision is now accepted and ready to land.Jun 1 2023, 11:05 AM
kuba marked an inline comment as done.
kuba edited the summary of this revision. (Show Details)

Add comment

This revision was landed with ongoing or failed builds.Jun 2 2023, 3:07 AM
This revision was automatically updated to reflect the committed changes.