Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
zbeyens committed Oct 13, 2024
1 parent 84ae58e commit 5bb3c67
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
10 changes: 5 additions & 5 deletions apps/www/content/docs/api/utils.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -327,11 +327,11 @@ Selects a point from the previous or next sibling node of the specified node.
<APISubListItem parent="options" name="at" type="Path" optional>
The path of the reference node. If not provided, `node` must be specified.
</APISubListItem>
<APISubListItem parent="options" name="position" type="'previous' | 'next'" optional>
Which sibling node to select from.
- `'previous'`: Select the end point of the previous sibling node.
- `'next'`: Select the start point of the next sibling node.
- **Default:** `'next'`
<APISubListItem parent="options" name="reverse" type="boolean" optional>
Whether to select the previous sibling instead of the next.
- `false`: Select the start point of the next sibling node.
- `true`: Select the end point of the previous sibling node.
- **Default:** `false`
</APISubListItem>
<APISubListItem parent="options" name="focus" type="boolean" optional>
Whether to focus the editor after selection.
Expand Down
5 changes: 4 additions & 1 deletion packages/math/src/react/hooks/useEquationInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,10 @@ export const useEquationInput = ({
selectionEnd === 0 &&
isHotkey('ArrowLeft')(e)
) {
selectSiblingNodePoint(editor, { edge: 'start', node: element });
selectSiblingNodePoint(editor, {
node: element,
reverse: true,
});
}
// at the right edge
if (
Expand Down
11 changes: 5 additions & 6 deletions packages/plate-utils/src/react/selectSiblingNodePoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,22 @@ export const selectSiblingNodePoint = (
at,
focus = true,
node,
position = 'after',
reverse,
}: {
at?: Path;
focus?: boolean;
node?: TNode;
position?: 'after' | 'before';
reverse?: boolean;
} = {}
) => {
if (node) {
at = findNodePath(editor, node);
}
if (!at) return;

const point =
position === 'before'
? getPreviousNodeEndPoint(editor, at)
: getNextNodeStartPoint(editor, at);
const point = reverse
? getPreviousNodeEndPoint(editor, at)
: getNextNodeStartPoint(editor, at);

if (!point) return;

Expand Down

0 comments on commit 5bb3c67

Please sign in to comment.