Fix find_widget bugs

This commit is contained in:
SiriusXT 2024-11-12 10:56:54 +08:00
parent d63baa1503
commit a0c6d695b0
3 changed files with 11 additions and 3 deletions

View File

@ -159,8 +159,10 @@ export default class FindWidget extends NoteContextAwareWidget {
this.handler = await this.getHandler();
const isReadOnly = await this.noteContext.isReadOnly();
let selectedText = '';
if (this.note.type === 'code'){
if (this.note.type === 'code' && !isReadOnly){
const codeEditor = await this.noteContext.getCodeEditor();
selectedText = codeEditor.getSelection();
}else{
@ -168,7 +170,6 @@ export default class FindWidget extends NoteContextAwareWidget {
}
this.$widget.show();
this.$input.focus();
const isReadOnly = await this.noteContext.isReadOnly();
if (['text', 'code'].includes(this.note.type) && !isReadOnly) {
this.$replaceWidgetBox.show();
}else{

View File

@ -171,6 +171,10 @@ export default class FindInCode {
codeEditor.focus();
}
async replace(replaceText) {
// this.findResult may be undefined and null
if (!this.findResult || this.findResult.length===0){
return;
}
let currentFound = -1;
this.findResult.forEach((marker, index) => {
const pos = marker.find();
@ -202,6 +206,9 @@ export default class FindInCode {
}
}
async replaceAll(replaceText) {
if (!this.findResult || this.findResult.length===0){
return;
}
const codeEditor = await this.getCodeEditor();
const doc = codeEditor.doc;
codeEditor.operation(() => {

View File

@ -51,7 +51,7 @@ export default class ReadOnlyCodeTypeWidget extends AbstractCodeTypeWidget {
await this.initialized;
resolve(this.$content);
resolve(this.$editor);
}
format(html) {