Add functions to add and clear highlights.

This commit is contained in:
Tom Alexander 2024-01-21 15:51:40 -05:00
parent 66bfc2da25
commit 89b8b18fea
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
3 changed files with 25 additions and 0 deletions

View File

@ -39,5 +39,8 @@
"last 1 firefox version",
"last 1 safari version"
]
},
"prettier": {
"tabWidth": 2
}
}

View File

@ -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<Array<Highlight>>([]);
function addHighlight(start: number, end: number) {
setHighlights([...highlights, new Highlight(start, end)]);
}
function clearHighlights() {
setHighlights([]);
}
return (
<div className="Editor">
<div className="Editor-textwrapper">

11
src/highlight.ts Normal file
View File

@ -0,0 +1,11 @@
class Highlight {
start: number;
end: number;
constructor(start: number, end: number) {
this.start = start;
this.end = end;
}
}
export { Highlight };