From e214feb61d20a30f286892cc7fdeabcd40e1504f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Ska=C5=82ka?= <39538890+Skalakid@users.noreply.github.com> Date: Thu, 7 Mar 2024 10:18:15 +0100 Subject: [PATCH] Add selection variables to web implementation (#208) --- example/src/App.tsx | 13 ++++ src/MarkdownTextInput.web.tsx | 120 +++++++++++++++++++++------------- src/web/cursorUtils.ts | 109 +++++++++++++++--------------- src/web/parserUtils.ts | 22 +++---- 4 files changed, 150 insertions(+), 114 deletions(-) diff --git a/example/src/App.tsx b/example/src/App.tsx index 39aae5be..ebde39b4 100644 --- a/example/src/App.tsx +++ b/example/src/App.tsx @@ -62,6 +62,7 @@ function getRandomColor() { export default function App() { const [value, setValue] = React.useState(DEFAULT_TEXT); const [markdownStyle, setMarkdownStyle] = React.useState({}); + const [selection, setSelection] = React.useState({start: 0, end: 0}); // TODO: use MarkdownTextInput ref instead of TextInput ref const ref = React.useRef(null); @@ -98,6 +99,8 @@ export default function App() { ref={ref} markdownStyle={markdownStyle} placeholder="Type here..." + onSelectionChange={(e) => setSelection(e.nativeEvent.selection)} + selection={selection} /> {/* TextInput singleline +