Skip to content

Commit

Permalink
Merge pull request #255 from jphjsoares/fix-vod
Browse files Browse the repository at this point in the history
Mention verse of the day on readme.md and make it compatible with either ++ or --
  • Loading branch information
tim-hub authored Jan 16, 2025
2 parents 4b65918 + 4f63c2c commit ab3cea5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
2. In a note, for example type `--John1:1`
3. Select the suggestion

You can also get a "verse of the day" by typing `--vod`.

> Read more about [How to use](https://github.com/tim-hub/obsidian-bible-reference/blob/master/docs/howto.md)
> On iOS devices, there is a known issue about conflict between `Smart Punctuation` and double hyphens `--`.
Expand Down
19 changes: 16 additions & 3 deletions src/suggesetor/VerseOfDayEditorSuggester.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { BibleReferencePluginSettings } from '../data/constants'
import { getVod } from '../provider/VODProvider'
import { VerseOfDaySuggesting } from '../verse/VerseOfDaySuggesting'
import { splitBibleReference } from '../utils/splitBibleReference'
import { matchTriggerPrefix } from '../utils/verseMatch'
import { EventStats } from '../provider/EventStats'

export class VerseOfDayEditorSuggester extends EditorSuggest<VerseOfDaySuggesting> {
Expand Down Expand Up @@ -60,8 +61,20 @@ export class VerseOfDayEditorSuggester extends EditorSuggest<VerseOfDaySuggestin
editor: Editor,
file: TFile
): EditorSuggestTriggerInfo | null {
// this variable holds the full query content, in this case --vod or ++vod
const currentContent = editor.getLine(cursor.line).substring(0, cursor.ch)
if (currentContent === '--vod') {

// get first 2 characters
if (currentContent.length < 2) {
return null
}
const prefixTrigger = currentContent.substring(0, 2)
if (!matchTriggerPrefix(prefixTrigger)) {
return null
}
const queryContent = currentContent.substring(2) // remove the trigger prefix

if (queryContent === 'vod') {
EventStats.logUIOpen(
'vodEditorOpen',
{ key: `${this.settings.bibleVersion}-vod`, value: 1 },
Expand All @@ -71,9 +84,9 @@ export class VerseOfDayEditorSuggester extends EditorSuggest<VerseOfDaySuggestin
end: cursor,
start: {
line: cursor.line,
ch: currentContent.lastIndexOf('--vod'),
ch: currentContent.lastIndexOf(currentContent),
},
query: '--vod',
query: currentContent,
}
}
return null
Expand Down

0 comments on commit ab3cea5

Please sign in to comment.