mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-07-27 18:12:29 +08:00
fix(code/find): crashes at dialog shown
This commit is contained in:
parent
ac49c0f59b
commit
f20232c077
@ -11,6 +11,7 @@ import type { ViewScope } from "../services/link.js";
|
|||||||
import type FNote from "../entities/fnote.js";
|
import type FNote from "../entities/fnote.js";
|
||||||
import type TypeWidget from "../widgets/type_widgets/type_widget.js";
|
import type TypeWidget from "../widgets/type_widgets/type_widget.js";
|
||||||
import type { CKTextEditor } from "@triliumnext/ckeditor5";
|
import type { CKTextEditor } from "@triliumnext/ckeditor5";
|
||||||
|
import type CodeMirror from "@triliumnext/codemirror";
|
||||||
|
|
||||||
export interface SetNoteOpts {
|
export interface SetNoteOpts {
|
||||||
triggerSwitchEvent?: unknown;
|
triggerSwitchEvent?: unknown;
|
||||||
@ -312,7 +313,7 @@ class NoteContext extends Component implements EventListener<"entitiesReloaded">
|
|||||||
|
|
||||||
async getCodeEditor() {
|
async getCodeEditor() {
|
||||||
return this.timeout(
|
return this.timeout(
|
||||||
new Promise<CodeMirrorInstance>((resolve) =>
|
new Promise<CodeMirror>((resolve) =>
|
||||||
appContext.triggerCommand("executeWithCodeEditor", {
|
appContext.triggerCommand("executeWithCodeEditor", {
|
||||||
resolve,
|
resolve,
|
||||||
ntxId: this.ntxId
|
ntxId: this.ntxId
|
||||||
|
@ -203,7 +203,7 @@ export default class FindWidget extends NoteContextAwareWidget {
|
|||||||
selectedText = $content.find('.cm-matchhighlight').first().text();
|
selectedText = $content.find('.cm-matchhighlight').first().text();
|
||||||
} else {
|
} else {
|
||||||
const codeEditor = await this.noteContext.getCodeEditor();
|
const codeEditor = await this.noteContext.getCodeEditor();
|
||||||
selectedText = codeEditor.getSelection();
|
selectedText = codeEditor.getSelectedText();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
selectedText = window.getSelection()?.toString() || "";
|
selectedText = window.getSelection()?.toString() || "";
|
||||||
|
@ -104,6 +104,17 @@ export default class CodeMirror extends EditorView {
|
|||||||
return this.state.doc.toString();
|
return this.state.doc.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the currently selected text.
|
||||||
|
*
|
||||||
|
* If there are multiple selections, all of them will be concatenated.
|
||||||
|
*/
|
||||||
|
getSelectedText() {
|
||||||
|
return this.state.selection.ranges
|
||||||
|
.map((range) => this.state.sliceDoc(range.from, range.to))
|
||||||
|
.join("");
|
||||||
|
}
|
||||||
|
|
||||||
setText(content: string) {
|
setText(content: string) {
|
||||||
this.dispatch({
|
this.dispatch({
|
||||||
changes: {
|
changes: {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user