From 89b8b18feab761ebdeb76a5feff71479085bd9f4 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Sun, 21 Jan 2024 15:51:40 -0500 Subject: [PATCH] Add functions to add and clear highlights. --- package.json | 3 +++ src/Editor.tsx | 11 +++++++++++ src/highlight.ts | 11 +++++++++++ 3 files changed, 25 insertions(+) create mode 100644 src/highlight.ts diff --git a/package.json b/package.json index 004ef32..684fd76 100644 --- a/package.json +++ b/package.json @@ -39,5 +39,8 @@ "last 1 firefox version", "last 1 safari version" ] + }, + "prettier": { + "tabWidth": 2 } } diff --git a/src/Editor.tsx b/src/Editor.tsx index c37fcb9..e4632b0 100644 --- a/src/Editor.tsx +++ b/src/Editor.tsx @@ -1,5 +1,6 @@ import React, { useState } from 'react'; import './Editor.css'; +import {Highlight} from './highlight'; function Editor({ defaultValue = "I have a text value." @@ -11,6 +12,16 @@ function Editor({ const [value, setValue] = useState(defaultValue); + const [highlights, setHighlights] = useState>([]); + + function addHighlight(start: number, end: number) { + setHighlights([...highlights, new Highlight(start, end)]); + } + + function clearHighlights() { + setHighlights([]); + } + return (
diff --git a/src/highlight.ts b/src/highlight.ts new file mode 100644 index 0000000..a9700ee --- /dev/null +++ b/src/highlight.ts @@ -0,0 +1,11 @@ +class Highlight { + start: number; + end: number; + + constructor(start: number, end: number) { + this.start = start; + this.end = end; + } +} + +export { Highlight };