mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-30 10:29:48 +02:00
Fix when clear search text, all text split by blank (#3072)
in search-highlighting example, when search text is empty, no need to split text and addAnnotation
This commit is contained in:
@@ -185,23 +185,25 @@ class SearchHighlighting extends React.Component {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
for (const [node, path] of document.texts()) {
|
if (string) {
|
||||||
const { key, text } = node
|
for (const [node, path] of document.texts()) {
|
||||||
const parts = text.split(string)
|
const { key, text } = node
|
||||||
let offset = 0
|
const parts = text.split(string)
|
||||||
|
let offset = 0
|
||||||
|
|
||||||
parts.forEach((part, i) => {
|
parts.forEach((part, i) => {
|
||||||
if (i !== 0) {
|
if (i !== 0) {
|
||||||
editor.addAnnotation({
|
editor.addAnnotation({
|
||||||
key: getHighlightKey(),
|
key: getHighlightKey(),
|
||||||
type: 'highlight',
|
type: 'highlight',
|
||||||
anchor: { path, key, offset: offset - string.length },
|
anchor: { path, key, offset: offset - string.length },
|
||||||
focus: { path, key, offset },
|
focus: { path, key, offset },
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
offset = offset + part.length + string.length
|
offset = offset + part.length + string.length
|
||||||
})
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user