Add functions to add and clear highlights.

Bu işleme şunda yer alıyor:
Tom Alexander 2024-01-21 15:51:40 -05:00
ebeveyn 66bfc2da25
işleme 89b8b18fea
Veri tabanında bu imza için bilinen anahtar bulunamadı
GPG Anahtar Kimliği: D3A179C9A53C0EDE
3 değiştirilmiş dosya ile 25 ekleme ve 0 silme

Dosyayı Görüntüle

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

Dosyayı Görüntüle

@ -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 dosya
Dosyayı Görüntüle

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