mirror of https://github.com/fantasticit/think.git
client: fix js error
This commit is contained in:
parent
8d910cf8b4
commit
a56ff665c0
|
@ -232,11 +232,8 @@ export const SearchNReplace = Extension.create<SearchOptions>({
|
||||||
this.options.searchTerm = searchTerm;
|
this.options.searchTerm = searchTerm;
|
||||||
this.options.results = [];
|
this.options.results = [];
|
||||||
this.options.currentIndex = 0;
|
this.options.currentIndex = 0;
|
||||||
|
(editor as Editor).eventEmitter && (editor as Editor).eventEmitter.emit(ON_SEARCH_RESULTS);
|
||||||
(editor as Editor).eventEmitter.emit(ON_SEARCH_RESULTS);
|
|
||||||
|
|
||||||
updateView(state, dispatch);
|
updateView(state, dispatch);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
setReplaceTerm:
|
setReplaceTerm:
|
||||||
|
@ -316,6 +313,7 @@ export const SearchNReplace = Extension.create<SearchOptions>({
|
||||||
addProseMirrorPlugins() {
|
addProseMirrorPlugins() {
|
||||||
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
||||||
const extensionThis = this;
|
const extensionThis = this;
|
||||||
|
const editor = this.editor as Editor;
|
||||||
|
|
||||||
return [
|
return [
|
||||||
new Plugin({
|
new Plugin({
|
||||||
|
@ -337,7 +335,7 @@ export const SearchNReplace = Extension.create<SearchOptions>({
|
||||||
searchResultClass
|
searchResultClass
|
||||||
);
|
);
|
||||||
extensionThis.options.results = results;
|
extensionThis.options.results = results;
|
||||||
(extensionThis.editor as Editor).eventEmitter.emit(ON_SEARCH_RESULTS);
|
editor.eventEmitter && editor.eventEmitter.emit(ON_SEARCH_RESULTS);
|
||||||
if (ctx.getMeta('directDecoration')) {
|
if (ctx.getMeta('directDecoration')) {
|
||||||
const { fromPos, toPos, attrs } = ctx.getMeta('directDecoration');
|
const { fromPos, toPos, attrs } = ctx.getMeta('directDecoration');
|
||||||
decorationsToReturn.push(Decoration.inline(fromPos, toPos, attrs));
|
decorationsToReturn.push(Decoration.inline(fromPos, toPos, attrs));
|
||||||
|
|
|
@ -44,6 +44,8 @@ export const Search: React.FC<{ editor: Editor }> = ({ editor }) => {
|
||||||
}, [replaceValue, editor]);
|
}, [replaceValue, editor]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
if (!editor) return;
|
||||||
|
|
||||||
const searchExtension = editor.extensionManager.extensions.find((ext) => ext.name === SearchNReplace.name);
|
const searchExtension = editor.extensionManager.extensions.find((ext) => ext.name === SearchNReplace.name);
|
||||||
|
|
||||||
if (!searchExtension) return;
|
if (!searchExtension) return;
|
||||||
|
@ -55,11 +57,11 @@ export const Search: React.FC<{ editor: Editor }> = ({ editor }) => {
|
||||||
setResults(results);
|
setResults(results);
|
||||||
};
|
};
|
||||||
|
|
||||||
editor.eventEmitter.on(ON_SEARCH_RESULTS, listener);
|
editor.eventEmitter && editor.eventEmitter.on(ON_SEARCH_RESULTS, listener);
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
if (!searchExtension) return;
|
if (!searchExtension) return;
|
||||||
editor.eventEmitter.off(ON_SEARCH_RESULTS, listener);
|
editor.eventEmitter && editor.eventEmitter.off(ON_SEARCH_RESULTS, listener);
|
||||||
};
|
};
|
||||||
}, [editor]);
|
}, [editor]);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue