Skip to content

Commit ff15f2f

Browse files
committed
💥:fix: Get both Cursor and Selection at once
1 parent 4ab7543 commit ff15f2f

File tree

3 files changed

+18
-29
lines changed

3 files changed

+18
-29
lines changed

browser/dom/cursor.ts

Lines changed: 0 additions & 13 deletions
This file was deleted.

browser/dom/selection.ts

Lines changed: 0 additions & 13 deletions
This file was deleted.

browser/dom/stores.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { textInput } from "./dom.ts";
66
import { Cursor } from "./cursor.d.ts";
77
import { Selection } from "./selection.d.ts";
88

9-
export const takeStores = (): (Cursor | Selection)[] => {
9+
export const takeStores = (): { cursor: Cursor; selection: Selection } => {
1010
const textarea = textInput();
1111
if (!textarea) {
1212
throw Error(`#text-input is not found.`);
@@ -21,9 +21,24 @@ export const takeStores = (): (Cursor | Selection)[] => {
2121
}
2222

2323
// @ts-ignore DOMを無理矢理objectとして扱っている
24-
return (textarea[
24+
const stores = (textarea[
2525
reactKey
26-
] as ReactFiber).return.return.stateNode._stores;
26+
] as ReactFiber).return.return.stateNode._stores as (Cursor | Selection)[];
27+
28+
const cursor = stores.find((store) =>
29+
store.constructor.name === "Cursor"
30+
) as (Cursor | undefined);
31+
if (!cursor) {
32+
throw Error('#text-input must has a "Cursor" store.');
33+
}
34+
const selection = stores.find((store) =>
35+
store.constructor.name === "Selection"
36+
) as (Selection | undefined);
37+
if (!selection) {
38+
throw Error('#text-input must has a "Selection" store.');
39+
}
40+
41+
return { cursor, selection };
2742
};
2843

2944
interface ReactFiber {

0 commit comments

Comments
 (0)