Skip to content

Commit

Permalink
Update mark done to do toggle similar to native functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
Stvad committed Jun 27, 2024
1 parent 005c617 commit 25a4100
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/ts/core/features/vim-mode/commands/edit-commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,19 @@ const rescheduleSelectedNote = (signal: SRSSignal) => {
RoamDb.updateBlockText(uid, new AnkiScheduler().schedule(new SM2Node(originalText), signal).text)
}

const markDone = () => {
const toggleDone = () => {
const uid = selectedUid()
const originalText = getBlockText(uid)
RoamDb.updateBlockText(uid, '{{[[DONE]]}} ' + originalText)
let newText = originalText
if (originalText.startsWith('{{[[DONE]]}} ')) {
newText = originalText.replace('{{[[DONE]]}} ', '')
} else if (originalText.startsWith('{{[[TODO]]}} ')) {
newText = originalText.replace('{{[[TODO]]}} ', '{{[[DONE]]}} ')
} else {
newText = '{{[[DONE]]}} ' + originalText
}

RoamDb.updateBlockText(uid, newText)
}

const modifyBlockDate = (modifier: (input: number) => number) => {
Expand All @@ -48,7 +57,7 @@ const modifyBlockDate = (modifier: (input: number) => number) => {
}

export const EditCommands = [
nmap('cmd+enter', 'Mark done', markDone),
nmap('cmd+enter', 'Toggle done', toggleDone),
...SRSSignals.map(it =>
nmap(`ctrl+shift+${it}`, `Reschedule Current Note (${SRSSignal[it]})`, () => rescheduleSelectedNote(it))
),
Expand Down

0 comments on commit 25a4100

Please sign in to comment.