wanglin2_obsidian-simplemin.../plugin/ob/SuggestionModal.js
2025-07-05 23:22:25 +08:00

40 lines
979 B
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { SuggestModal } from 'obsidian'
export class SuggestionModal extends SuggestModal {
constructor({ plugin, app, getSuggestions, onSelect, type }) {
super(app)
this.plugin = plugin
this.emptyStateText = this.plugin._t('tip.noMatchResult')
this.type = type // folder选择目录
if (this.type === 'folder') {
this.getSuggestions = this._queryFolders.bind(this)
} else {
this.getSuggestions = getSuggestions
}
this.onSelect = onSelect
}
// 查询目录
_queryFolders(query) {
const list = this.app.vault.getAllFolders()
return list
.filter(item => {
return item.path.toLowerCase().includes(query)
})
.map(item => {
return item.path
})
}
getSuggestions(query) {
return this.getSuggestions(query)
}
renderSuggestion(suggestion, el) {
el.createEl('div', { text: suggestion })
}
onChooseSuggestion(suggestion) {
this.onSelect(suggestion)
}
}