mirror of
https://github.com/friebetill/obsidian-file-diff.git
synced 2026-07-22 07:40:25 +00:00
Wait for the dispatch event to be handled
This commit is contained in:
parent
0de8d41f77
commit
572cfbc790
3 changed files with 13 additions and 3 deletions
|
|
@ -1,5 +1,6 @@
|
|||
import { structuredPatch } from 'diff'
|
||||
import { ItemView, TFile, WorkspaceLeaf } from 'obsidian'
|
||||
import { delay } from 'src/utils/delay'
|
||||
import { Difference } from '../data/difference'
|
||||
import { FileDifferences } from '../data/file_differences'
|
||||
import { preventEmptyString } from '../utils/string_utils'
|
||||
|
|
@ -151,7 +152,7 @@ export class DifferencesView extends ItemView {
|
|||
|
||||
async showDeleteModal(): Promise<void> {
|
||||
// Wait a moment to avoid appearing overly aggressive with the modal
|
||||
await this.delay(200)
|
||||
await delay(200)
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
new DeleteFileModal({
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ import { Plugin, TFile } from 'obsidian'
|
|||
import { DifferencesView } from './components/differences_view'
|
||||
import { RiskyActionModal } from './components/modals/risky_action_modal'
|
||||
import { SelectFileModal } from './components/modals/select_file_modal'
|
||||
import { delay } from './utils/delay'
|
||||
|
||||
export default class FileDiffPlugin extends Plugin {
|
||||
fileDiffMergeWarningKey = 'file-diff-merge-warning'
|
||||
|
|
@ -43,7 +44,7 @@ export default class FileDiffPlugin extends Plugin {
|
|||
editorCallback: async () => {
|
||||
// Show warning when this option is selected for the first time
|
||||
if (!localStorage.getItem(this.fileDiffMergeWarningKey)) {
|
||||
this.showRiskyActionModal()
|
||||
await this.showRiskyActionModal()
|
||||
if (!localStorage.getItem(this.fileDiffMergeWarningKey)) {
|
||||
return
|
||||
}
|
||||
|
|
@ -97,7 +98,7 @@ export default class FileDiffPlugin extends Plugin {
|
|||
showRiskyActionModal(): Promise<void> {
|
||||
return new Promise((resolve, reject) => {
|
||||
new RiskyActionModal({
|
||||
onAccept: (e: Error | null) => {
|
||||
onAccept: async (e: Error | null) => {
|
||||
if (e) {
|
||||
reject(e)
|
||||
} else {
|
||||
|
|
@ -105,6 +106,9 @@ export default class FileDiffPlugin extends Plugin {
|
|||
this.fileDiffMergeWarningKey,
|
||||
'true'
|
||||
)
|
||||
// Wait for the set item dispatch event to be processed
|
||||
await delay(50)
|
||||
|
||||
resolve()
|
||||
}
|
||||
},
|
||||
|
|
|
|||
5
src/utils/delay.ts
Normal file
5
src/utils/delay.ts
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
export function delay(ms: number): Promise<void> {
|
||||
return new Promise((resolve) => {
|
||||
setTimeout(resolve, ms)
|
||||
})
|
||||
}
|
||||
Loading…
Reference in a new issue