Add functions to add and clear highlights.
This commit is contained in:
parent
66bfc2da25
commit
89b8b18fea
@ -39,5 +39,8 @@
|
|||||||
"last 1 firefox version",
|
"last 1 firefox version",
|
||||||
"last 1 safari version"
|
"last 1 safari version"
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
"prettier": {
|
||||||
|
"tabWidth": 2
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import React, { useState } from 'react';
|
import React, { useState } from 'react';
|
||||||
import './Editor.css';
|
import './Editor.css';
|
||||||
|
import {Highlight} from './highlight';
|
||||||
|
|
||||||
function Editor({
|
function Editor({
|
||||||
defaultValue = "I have a text value."
|
defaultValue = "I have a text value."
|
||||||
@ -11,6 +12,16 @@ function Editor({
|
|||||||
|
|
||||||
const [value, setValue] = useState(defaultValue);
|
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 (
|
return (
|
||||||
<div className="Editor">
|
<div className="Editor">
|
||||||
<div className="Editor-textwrapper">
|
<div className="Editor-textwrapper">
|
||||||
|
11
src/highlight.ts
Normal file
11
src/highlight.ts
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
class Highlight {
|
||||||
|
start: number;
|
||||||
|
end: number;
|
||||||
|
|
||||||
|
constructor(start: number, end: number) {
|
||||||
|
this.start = start;
|
||||||
|
this.end = end;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export { Highlight };
|
Loading…
x
Reference in New Issue
Block a user