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