-
-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'roam-js' into roam-js-vim-colemak
- Loading branch information
Showing
5 changed files
with
80 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import {nmap} from 'src/core/features/vim-mode/vim' | ||
import {RoamBlock} from 'src/core/features/vim-mode/roam/roam-block' | ||
import {SRSSignal, SRSSignals} from 'src/core/srs/scheduler' | ||
import {AnkiScheduler} from 'src/core/srs/AnkiScheduler' | ||
import {SM2Node} from 'src/core/srs/SM2Node' | ||
import {RoamDb} from 'src/core/roam/roam-db' | ||
import {getBlockUid} from 'src/core/roam/block' | ||
import {RoamDate} from 'src/core/roam/date' | ||
import {createModifier, modifyDate} from 'src/core/features/inc-dec-value' | ||
|
||
const getBlockText = (uid: string): string => { | ||
const block = RoamDb.getBlockByUid(uid) | ||
return block[':block/string'] | ||
} | ||
|
||
function selectedUid() { | ||
const htmlId = RoamBlock.selected().id | ||
return getBlockUid(htmlId) | ||
} | ||
|
||
const rescheduleSelectedNote = (signal: SRSSignal) => { | ||
console.log('rescheduleSelectedNote', signal) | ||
const uid = selectedUid() | ||
const originalText = getBlockText(uid) | ||
RoamDb.updateBlockText(uid, new AnkiScheduler().schedule(new SM2Node(originalText), signal).text) | ||
} | ||
|
||
const toggleDone = () => { | ||
const uid = selectedUid() | ||
const originalText = getBlockText(uid) | ||
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) => { | ||
const uid = selectedUid() | ||
const originalText = getBlockText(uid) | ||
|
||
const datesInContent = originalText.match(RoamDate.regex) | ||
if (!datesInContent || datesInContent.length !== 1) return | ||
|
||
RoamDb.updateBlockText( | ||
uid, | ||
originalText.replace( | ||
datesInContent[0], | ||
RoamDate.formatPage(modifyDate(RoamDate.parseFromReference(datesInContent[0]), modifier)) | ||
) | ||
) | ||
} | ||
|
||
export const EditCommands = [ | ||
nmap('cmd+enter', 'Toggle done', toggleDone), | ||
...SRSSignals.map(it => | ||
nmap(`ctrl+shift+${it}`, `Reschedule Current Note (${SRSSignal[it]})`, () => rescheduleSelectedNote(it)) | ||
), | ||
nmap('ctrl+alt+up', 'Increment Date', () => modifyBlockDate(createModifier(1))), | ||
nmap('ctrl+alt+down', 'Decrement Date', () => modifyBlockDate(createModifier(-1))), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters