32
32
33
33
<script setup lang="ts">
34
34
import { ref , toRef , reactive , toRaw , computed , watch , nextTick , getCurrentInstance , onMounted , onUnmounted , HTMLAttributes , h , watchEffect } from ' vue' ;
35
- import { Notice , MarkdownView , sanitizeHTMLToDom , HeadingCache } from ' obsidian' ;
35
+ import { Notice , MarkdownView , sanitizeHTMLToDom , HeadingCache , debounce } from ' obsidian' ;
36
36
import { NTree , TreeOption , NButton , NInput , NSlider , NConfigProvider , darkTheme , GlobalThemeOverrides , TreeDropInfo } from ' naive-ui' ;
37
37
import { Icon } from ' @vicons/utils' ;
38
38
import { SettingsBackupRestoreRound , ArrowCircleDownRound } from ' @vicons/material' ;
@@ -199,16 +199,16 @@ function _handleScroll(evt: Event) {
199
199
return ;
200
200
}
201
201
202
- if (plugin .settings .locate_by_cursor ) {
203
- return ;
204
- }
202
+ // if (plugin.settings.locate_by_cursor) {
203
+ // return;
204
+ // }
205
205
206
- onPosChange ();
206
+ onPosChange (true );
207
207
}
208
208
209
- function onPosChange() {
210
- let current = currentLine ();
211
- let index = nearestHeading (current );
209
+ function onPosChange(fromScroll : boolean ) {
210
+ const current = currentLine (fromScroll );
211
+ const index = nearestHeading (current );
212
212
if (index === undefined ) return ;
213
213
214
214
autoExpand (index );
@@ -226,16 +226,16 @@ onUnmounted(() => {
226
226
function handleCursorChange() {
227
227
228
228
if (plugin .settings .locate_by_cursor ) {
229
- onPosChange ();
229
+ onPosChange (false );
230
230
}
231
231
}
232
232
233
- function currentLine() {
233
+ function currentLine(fromScroll : boolean ) {
234
234
// const view = plugin.app.workspace.getActiveViewOfType(MarkdownView);
235
235
const view = plugin .current_note ;
236
236
if (! view || view .getViewType () !== " markdown" ) return ;
237
237
238
- if (plugin .settings .locate_by_cursor ) {
238
+ if (plugin .settings .locate_by_cursor && ! fromScroll ) {
239
239
return (view as MarkdownView ).editor .getCursor (" from" ).line ;
240
240
} else {
241
241
// @ts-ignore
@@ -367,11 +367,11 @@ function _openPopover(e: KeyboardEvent) {
367
367
}
368
368
}
369
369
370
- const openPopover = debounce (_openPopover , 100 );
370
+ const openPopover = customDebounce (_openPopover , 100 );
371
371
372
372
// excute on first time, and wait until next fresh
373
373
// ... or take a break when node pointed changes
374
- function debounce (func : (_ : any ) => void , delay : number ) {
374
+ function customDebounce (func : (_ : any ) => void , delay : number ) {
375
375
let fresh = true ;
376
376
let timeoutId: any ;
377
377
0 commit comments