Skip to content

Commit

Permalink
Fix text expander not working correctly in lists
Browse files Browse the repository at this point in the history
  • Loading branch information
kizu committed Dec 26, 2024
1 parent 0f6e2b0 commit 1d37484
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 53 deletions.
36 changes: 34 additions & 2 deletions src/components/compose.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -1840,8 +1840,13 @@ const Textarea = forwardRef((props, ref) => {

const textExpanderRef = useRef();
const textExpanderTextRef = useRef('');
const hasTextExpanderRef = useRef(false);
useEffect(() => {
let handleChange, handleValue, handleCommited;
let handleChange,
handleValue,
handleCommited,
handleActivate,
handleDeactivate;
if (textExpanderRef.current) {
handleChange = (e) => {
// console.log('text-expander-change', e);
Expand Down Expand Up @@ -2022,6 +2027,24 @@ const Textarea = forwardRef((props, ref) => {
'text-expander-committed',
handleCommited,
);

handleActivate = () => {
hasTextExpanderRef.current = true;
};

textExpanderRef.current.addEventListener(
'text-expander-activate',
handleActivate,
);

handleDeactivate = () => {
hasTextExpanderRef.current = false;
};

textExpanderRef.current.addEventListener(
'text-expander-deactivate',
handleDeactivate,
);
}

return () => {
Expand All @@ -2038,6 +2061,14 @@ const Textarea = forwardRef((props, ref) => {
'text-expander-committed',
handleCommited,
);
textExpanderRef.current.removeEventListener(
'text-expander-activate',
handleActivate,
);
textExpanderRef.current.removeEventListener(
'text-expander-deactivate',
handleDeactivate,
);
}
};
}, []);
Expand Down Expand Up @@ -2127,7 +2158,8 @@ const Textarea = forwardRef((props, ref) => {
onKeyDown={(e) => {
// Get line before cursor position after pressing 'Enter'
const { key, target } = e;
if (key === 'Enter' && !(e.ctrlKey || e.metaKey)) {
const hasTextExpander = hasTextExpanderRef.current;
if (key === 'Enter' && !(e.ctrlKey || e.metaKey || hasTextExpander)) {
try {
const { value, selectionStart } = target;
const textBeforeCursor = value.slice(0, selectionStart);
Expand Down
102 changes: 51 additions & 51 deletions src/locales/en.po

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 1d37484

Please sign in to comment.