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)
Sat, Dec 7, 12:05 PM
Unknown Object (File)
Tue, Nov 19, 6:54 AM
Unknown Object (File)
Tue, Nov 19, 6:54 AM
Unknown Object (File)
Tue, Nov 19, 6:54 AM
Unknown Object (File)
Tue, Nov 19, 6:54 AM
Unknown Object (File)
Tue, Nov 19, 6:53 AM
Unknown Object (File)
Nov 17 2024, 8:46 AM
Unknown Object (File)
Oct 21 2024, 8:01 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
Branch
kuba/fix-web-cursor
Lint
No Lint Coverage
Unit
No Test Coverage

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.