Skip to content

Commit

Permalink
Add Edit#getState() to returned Edit handle
Browse files Browse the repository at this point in the history
  • Loading branch information
kitten committed Apr 12, 2021
1 parent da2023f commit 98cb706
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/useEditable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@ export interface Edit {
insert(append: string, offset?: number): void;
/** Positions the caret where specified */
move(pos: number | { row: number; column: number }): void;
/** Returns the current editor state, as usually received in onChange */
getState(): { text: string; position: Position };
}

export const useEditable = (
Expand Down Expand Up @@ -239,6 +241,12 @@ export const useEditable = (
setCurrentRange(makeRange(element, position));
}
},
getState() {
const { current: element } = elementRef;
const text = toString(element!);
const position = getPosition(element!);
return { text, position };
},
}),
[]
);
Expand Down

0 comments on commit 98cb706

Please sign in to comment.