-
Notifications
You must be signed in to change notification settings - Fork 1.4k
feature: improved bullets functionality in message composer #6810
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
Open
divyanshu-patil
wants to merge
4
commits into
RocketChat:develop
Choose a base branch
from
divyanshu-patil:feature/autobullets
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
92b599a
feature: improved bullets functionality in message composer
divyanshu-patil bd8054b
Merge branch 'develop' into feature/autobullets
divyanshu-patil 4131faa
Merge branch 'develop' into feature/autobullets
divyanshu-patil ed87fe3
Merge branch 'develop' into feature/autobullets
divyanshu-patil File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| import React, { forwardRef, memo, useCallback, useEffect, useImperativeHandle } from 'react'; | ||
| import React, { forwardRef, memo, useCallback, useEffect, useImperativeHandle, useState } from 'react'; | ||
| import { TextInput, StyleSheet, type TextInputProps, InteractionManager } from 'react-native'; | ||
| import { useDebouncedCallback } from 'use-debounce'; | ||
| import { useDispatch } from 'react-redux'; | ||
|
|
@@ -47,6 +47,7 @@ const defaultSelection: IInputSelection = { start: 0, end: 0 }; | |
|
|
||
| export const ComposerInput = memo( | ||
| forwardRef<IComposerInput, IComposerInputProps>(({ inputRef }, ref) => { | ||
| const [inputValue, setInputValue] = useState(''); | ||
| const { colors, theme } = useTheme(); | ||
| const { rid, tmid, sharing, action, selectedMessages, setQuotesAndText, room } = useRoomContext(); | ||
| const focused = useFocused(); | ||
|
|
@@ -168,14 +169,17 @@ export const ComposerInput = memo( | |
| })); | ||
|
|
||
| const setInput: TSetInput = (text, selection, forceUpdateDraftMessage) => { | ||
| const message = text.trim(); | ||
| // const message = forceUpdateDraftMessage ? text : text.trim(); | ||
| const message = text; | ||
| textRef.current = message; | ||
|
|
||
| setInputValue(message); | ||
|
|
||
| if (forceUpdateDraftMessage) { | ||
| saveMessageDraft(''); | ||
| } | ||
|
|
||
| inputRef.current?.setNativeProps?.({ text }); | ||
| inputRef.current?.setNativeProps?.({ text: message }); | ||
|
|
||
| if (selection) { | ||
| // setSelection won't trigger onSelectionChange, so we need it to be ran after new text is set | ||
|
|
@@ -195,10 +199,40 @@ export const ComposerInput = memo( | |
| }, 300); | ||
| }; | ||
|
|
||
| const handleAutoBullet = useCallback((text: string, prevText: string): string => { | ||
| if (text.endsWith('\n')) { | ||
| const lines = text.split('\n'); | ||
|
|
||
| // check for deletion | ||
| if (text.length < prevText.length) { | ||
| return text; | ||
| } | ||
| const prevLine = lines[lines.length - 2]; | ||
| console.log('prevline', prevLine); | ||
|
|
||
| const regex = /^((?:\d+\.|-\s)).*/; | ||
|
|
||
| if (prevLine && regex.test(prevLine)) { | ||
| if (prevLine.startsWith('- ')) { | ||
| const newText = `${text}- `; | ||
| console.log('new text', newText); | ||
| return newText; | ||
| } | ||
| const prevNumber = parseInt(prevLine.split('.')[0], 10); | ||
| const nextNumber = prevNumber + 1; | ||
| const newText = `${text}${nextNumber}. `; | ||
| console.log('new text', newText); | ||
| return newText; | ||
| } | ||
| } | ||
| return text; | ||
| }, []); | ||
|
Comment on lines
+202
to
+229
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove debug console.log statements and fix regex pattern. The function has several issues:
Apply this diff to fix the regex and remove debug logs: const handleAutoBullet = useCallback((text: string, prevText: string): string => {
if (text.endsWith('\n')) {
const lines = text.split('\n');
// check for deletion
if (text.length < prevText.length) {
return text;
}
const prevLine = lines[lines.length - 2];
- console.log('prevline', prevLine);
- const regex = /^((?:\d+\.|-\s)).*/;
+ const regex = /^(\d+\.|-)(\s)/;
if (prevLine && regex.test(prevLine)) {
if (prevLine.startsWith('- ')) {
+ // Don't add bullet if previous line is empty bullet
+ if (prevLine.trim() === '-') {
+ return text.slice(0, -1); // Remove the newline, exit bullet mode
+ }
const newText = `${text}- `;
- console.log('new text', newText);
return newText;
}
const prevNumber = parseInt(prevLine.split('.')[0], 10);
const nextNumber = prevNumber + 1;
const newText = `${text}${nextNumber}. `;
- console.log('new text', newText);
return newText;
}
}
return text;
}, []);
🤖 Prompt for AI Agents |
||
|
|
||
| const onChangeText: TextInputProps['onChangeText'] = text => { | ||
| textRef.current = text; | ||
| debouncedOnChangeText(text); | ||
| setInput(text); | ||
| const newText = handleAutoBullet(text, textRef.current); | ||
| textRef.current = newText; | ||
| debouncedOnChangeText(newText); | ||
| setInput(newText); | ||
| }; | ||
|
|
||
| const onSelectionChange: TextInputProps['onSelectionChange'] = e => { | ||
|
|
@@ -366,6 +400,7 @@ export const ComposerInput = memo( | |
|
|
||
| return ( | ||
| <TextInput | ||
| value={inputValue} | ||
| style={[styles.textInput, { color: colors.fontDefault }]} | ||
| placeholder={placeholder} | ||
| placeholderTextColor={colors.fontAnnotation} | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
🧩 Analysis chain
Verify the controlled input behavior.
Converting the
TextInputfrom uncontrolled to controlled by introducing theinputValuestate is a significant change. Ensure that this doesn't introduce issues with cursor positioning, text selection, or input performance, especially for longer messages.Run the following script to check if there are any related issues or tests that might be affected:
🏁 Script executed:
Length of output: 4333
is NOT appropriate here as we need repository files
Length of output: 302
🏁 Script executed:
Length of output: 341
🏁 Script executed:
Length of output: 8444
Remove
setNativePropscall when using controlled input with state.The conversion to controlled input (via
inputValuestate on line 403) conflicts with the direct native manipulation viasetNativePropson line 182. This mixed pattern creates inconsistency between React state and native layer, causing the exact issues mentioned: cursor positioning, text selection, and performance problems.In a controlled input, React state is the single source of truth. Remove the
setNativePropscall on line 182 and rely solely on the state-driven value binding.🤖 Prompt for AI Agents