Skip to content

Commit

Permalink
impl home and end key move to start/end
Browse files Browse the repository at this point in the history
  • Loading branch information
potatowagon committed Sep 19, 2024
1 parent deb5894 commit 3c00c3a
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions packages/lexical/src/LexicalUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -966,6 +966,14 @@ function isArrowDown(key: string): boolean {
return key === 'ArrowDown';
}

function isHomeKey(key: string): boolean {
return key === 'Home';
}

function isEndKey(key: string): boolean {
return key === 'End';
}

export function isMoveBackward(
key: string,
ctrlKey: boolean,
Expand All @@ -982,7 +990,12 @@ export function isMoveToStart(
altKey: boolean,
metaKey: boolean,
): boolean {
return isArrowLeft(key) && !altKey && !shiftKey && (ctrlKey || metaKey);
return (
(isArrowLeft(key) || isHomeKey(key)) &&
!altKey &&
!shiftKey &&
(ctrlKey || metaKey)
);
}

export function isMoveForward(
Expand All @@ -1001,7 +1014,12 @@ export function isMoveToEnd(
altKey: boolean,
metaKey: boolean,
): boolean {
return isArrowRight(key) && !altKey && !shiftKey && (ctrlKey || metaKey);
return (
(isArrowRight(key) || isEndKey(key)) &&
!altKey &&
!shiftKey &&
(ctrlKey || metaKey)
);
}

export function isMoveUp(
Expand Down Expand Up @@ -1668,17 +1686,6 @@ export function isHTMLElement(x: Node | EventTarget): x is HTMLElement {
return x.nodeType === 1;
}

/**
* @param x - The element being testing
* @returns Returns true if x is a document fragment, false otherwise.
*/
export function isDocumentFragment(
x: Node | EventTarget,
): x is DocumentFragment {
// @ts-ignore-next-line - strict check on nodeType here should filter out non-Element EventTarget implementors
return x.nodeType === 11;
}

/**
*
* @param node - the Dom Node to check
Expand Down

0 comments on commit 3c00c3a

Please sign in to comment.