@@ -143,9 +143,9 @@ export default class FindWidget extends NoteContextAwareWidget {
143143 this . $currentFound = this . $widget . find ( ".find-widget-current-found" ) ;
144144 this . $totalFound = this . $widget . find ( ".find-widget-total-found" ) ;
145145 this . $caseSensitiveCheckbox = this . $widget . find ( ".find-widget-case-sensitive-checkbox" ) ;
146- this . $caseSensitiveCheckbox . change ( ( ) => this . performFind ( ) ) ;
146+ this . $caseSensitiveCheckbox . on ( "change" , ( ) => this . performFind ( ) ) ;
147147 this . $matchWordsCheckbox = this . $widget . find ( ".find-widget-match-words-checkbox" ) ;
148- this . $matchWordsCheckbox . change ( ( ) => this . performFind ( ) ) ;
148+ this . $matchWordsCheckbox . on ( "change" , ( ) => this . performFind ( ) ) ;
149149 this . $previousButton = this . $widget . find ( ".find-widget-previous-button" ) ;
150150 this . $previousButton . on ( "click" , ( ) => this . findNext ( - 1 ) ) ;
151151 this . $nextButton = this . $widget . find ( ".find-widget-next-button" ) ;
@@ -160,7 +160,7 @@ export default class FindWidget extends NoteContextAwareWidget {
160160 this . $replaceButton = this . $widget . find ( ".replace-widget-replace-button" ) ;
161161 this . $replaceButton . on ( "click" , ( ) => this . replace ( ) ) ;
162162
163- this . $input . keydown ( async ( e ) => {
163+ this . $input . on ( "keydown" , async ( e ) => {
164164 if ( ( e . metaKey || e . ctrlKey ) && ( e . key === "F" || e . key === "f" ) ) {
165165 // If ctrl+f is pressed when the findbox is shown, select the
166166 // whole input to find
@@ -172,7 +172,7 @@ export default class FindWidget extends NoteContextAwareWidget {
172172 }
173173 } ) ;
174174
175- this . $widget . keydown ( async ( e ) => {
175+ this . $widget . on ( "keydown" , async ( e ) => {
176176 if ( e . key === "Escape" ) {
177177 await this . closeSearch ( ) ;
178178 }
@@ -197,9 +197,14 @@ export default class FindWidget extends NoteContextAwareWidget {
197197 const isReadOnly = await this . noteContext ?. isReadOnly ( ) ;
198198
199199 let selectedText = "" ;
200- if ( this . note ?. type === "code" && ! isReadOnly && this . noteContext ) {
201- const codeEditor = await this . noteContext . getCodeEditor ( ) ;
202- selectedText = codeEditor . getSelection ( ) ;
200+ if ( this . note ?. type === "code" && this . noteContext ) {
201+ if ( isReadOnly ) {
202+ const $content = await this . noteContext . getContentElement ( ) ;
203+ selectedText = $content . find ( '.cm-matchhighlight' ) . first ( ) . text ( ) ;
204+ } else {
205+ const codeEditor = await this . noteContext . getCodeEditor ( ) ;
206+ selectedText = codeEditor . getSelection ( ) ;
207+ }
203208 } else {
204209 selectedText = window . getSelection ( ) ?. toString ( ) || "" ;
205210 }
0 commit comments