mirror of
https://github.com/fluxerapp/fluxer
synced 2026-10-18 21:45:31 +09:00
fix(app): move the caret to the line edges on home and end (#1997)
This commit is contained in:
1 parent
e32c5b73a7
commit
3f5c8d8d0a
1 file changed
+19
@@ -156,6 +156,22 @@ export interface LexicalComposerInputProps {
|
|||||||
onSlashCommandStateChange?: (state: SlashCommandComposerState) => void;
|
onSlashCommandStateChange?: (state: SlashCommandComposerState) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function moveSelectionToLineBoundary(event: React.KeyboardEvent<HTMLElement>): boolean {
|
||||||
|
if (event.key !== 'Home' && event.key !== 'End') {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (event.ctrlKey || event.metaKey || event.altKey) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
const selection = event.currentTarget.ownerDocument.defaultView?.getSelection();
|
||||||
|
if (selection == null || selection.rangeCount === 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
selection.modify(event.shiftKey ? 'extend' : 'move', event.key === 'Home' ? 'backward' : 'forward', 'lineboundary');
|
||||||
|
event.preventDefault();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
export const LexicalComposerInput = observer((props: LexicalComposerInputProps) => {
|
export const LexicalComposerInput = observer((props: LexicalComposerInputProps) => {
|
||||||
const plainText = ChatInputSettings.renderComposerAsPlainText;
|
const plainText = ChatInputSettings.renderComposerAsPlainText;
|
||||||
const selectionToolbar = (props.selectionToolbar == null ? true : props.selectionToolbar) && !MobileLayout.enabled;
|
const selectionToolbar = (props.selectionToolbar == null ? true : props.selectionToolbar) && !MobileLayout.enabled;
|
||||||
@@ -626,6 +642,9 @@ const ComposerInner = ({
|
|||||||
const handleEditableKeyDown = useCallback(
|
const handleEditableKeyDown = useCallback(
|
||||||
(event: React.KeyboardEvent<HTMLElement>) => {
|
(event: React.KeyboardEvent<HTMLElement>) => {
|
||||||
if (!event.defaultPrevented && !isIMEComposing(event)) {
|
if (!event.defaultPrevented && !isIMEComposing(event)) {
|
||||||
|
if (moveSelectionToLineBoundary(event)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (onKeyDown != null) {
|
if (onKeyDown != null) {
|
||||||
onKeyDown(event);
|
onKeyDown(event);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user