Skip to content

Commit

Permalink
Merge pull request #5 from hron/skip-now-doing
Browse files Browse the repository at this point in the history
Add "Skip NOW/DOING?" setting
  • Loading branch information
hron authored Dec 3, 2024
2 parents ce5ac66 + 0c8c579 commit 67d70d6
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 5 deletions.
3 changes: 2 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.vscode
.vscode
CHANGELOG.md
38 changes: 37 additions & 1 deletion e2e-tests/cycle-todo-dwim.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { expect } from '@playwright/test'
import { expect, Page } from '@playwright/test'
import { test } from './fixtures'
import { createRandomPage, modKey } from './utils'

test('cycling TODO state', async ({ page, block }) => {
await setSkipDoingSettingTo(page, false)
await createRandomPage(page)

await block.mustFill('foo')
Expand All @@ -28,6 +29,7 @@ test('cycling TODO state', async ({ page, block }) => {
})

test('cycling TODO state while editing', async ({ page, block }) => {
await setSkipDoingSettingTo(page, false)
await createRandomPage(page)

await block.activeEditing(0)
Expand All @@ -43,6 +45,7 @@ test('cycling TODO state while editing', async ({ page, block }) => {
})

test('cycling TODO state (SCHEDULED)', async ({ page, block }) => {
await setSkipDoingSettingTo(page, false)
await createRandomPage(page)

await block.mustFill(`LATER foobar\nSCHEDULED: <2000-01-01 Sat .+73y>`)
Expand All @@ -68,6 +71,7 @@ test('cycling TODO state (SCHEDULED) while editing', async ({
page,
block,
}) => {
await setSkipDoingSettingTo(page, false)
await createRandomPage(page)

await block.activeEditing(0)
Expand All @@ -90,6 +94,7 @@ test('cycling TODO state (SCHEDULED, but not repeating)', async ({
page,
block,
}) => {
await setSkipDoingSettingTo(page, false)
await createRandomPage(page)

await block.mustFill(`LATER foobar\nSCHEDULED: <2000-01-01 Sat>`)
Expand All @@ -110,3 +115,34 @@ test('cycling TODO state (SCHEDULED, but not repeating)', async ({
).toContainText(`SCHEDULED: ${expected.scheduled}`)
}
})

test('skipping NOW/DOING when this option is enabled', async ({
page,
block,
}) => {
await setSkipDoingSettingTo(page, true)
await createRandomPage(page)

await block.mustFill(`LATER foobar`)
await block.escapeEditing()
await page.keyboard.press('ArrowDown', { delay: 10 })
await page.keyboard.press(modKey + '+Shift+Enter', { delay: 10 })
await expect(page.locator('.block-content span >> nth=0')).toHaveClass(
`inline done`
)
})

async function setSkipDoingSettingTo(page: Page, enabled: boolean) {
await page.click('#head .toolbar-dots-btn')
await page.click('#head .dropdown-wrapper >> text=Settings')
await page.click('.settings-modal [data-id=plugins] a')

const setting = page.locator(
'[data-key=cycleTODOdwimSkipDoing] >> input[type=checkbox]'
)

await setting.setChecked(enabled)
await page.waitForTimeout(1000)
await page.keyboard.press('Escape')
await page.keyboard.press('Escape')
}
2 changes: 1 addition & 1 deletion e2e-tests/install.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ test('verifying the plugin is installed', async ({ page }) => {
await page.keyboard.press('Escape')
await page.keyboard.press('t+p')
await expect(page.locator('.installed h3 span')).toHaveText(
'logseq-cycle-todo-dwim'
'Cycle TODO (Do What I Mean)'
)
})
22 changes: 21 additions & 1 deletion index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,16 @@ function setMarker(block: BlockEntity, newMarker: Marker) {
async function computeNextMarker(currentMarker: Marker) {
const userPreferredStyle = await preferredTodoStyle()
const todoSeq = todoSequences[userPreferredStyle] as readonly Marker[]
return todoSeq[(todoSeq.indexOf(currentMarker) + 1) % todoSeq.length]
const nextMarker =
todoSeq[(todoSeq.indexOf(currentMarker) + 1) % todoSeq.length]
if (
['NOW', 'DOING'].includes(nextMarker) &&
logseq.settings!['cycleTODOdwimSkipDoing']
) {
return computeNextMarker(nextMarker)
} else {
return nextMarker
}
}

type Timestamp = {
Expand Down Expand Up @@ -153,6 +162,17 @@ async function cycleTODOdwim(): Promise<void[]> {
}

async function main() {
logseq.useSettingsSchema([
{
key: 'cycleTODOdwimSkipDoing',
type: 'boolean',
title: 'Skip NOW/DOING State',
description:
'<p>Determines whether the Cycle TODO (Do What I Mean) feature skips the NOW/DOING state</p>',
default: false,
},
])

logseq.App.registerCommandPalette(
{
label: 'Cycle TODO (Do What I Mean)',
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
"logseq": {
"main": "dist/index.html",
"icon": "./logo.webp",
"id": "cycle-todo-dwim"
"id": "cycle-todo-dwim",
"title": "Cycle TODO (Do What I Mean)"
},
"dependencies": {
"@logseq/libs": "^0.2.0",
Expand Down

0 comments on commit 67d70d6

Please sign in to comment.