Skip to content

Commit

Permalink
stars, todo keyword and priority end after the whitespaces (#221)
Browse files Browse the repository at this point in the history
* [orga] stars, todo keyword and priority end after the whitespaces

* add changeset
  • Loading branch information
xiaoxinghu authored Nov 15, 2023
1 parent 54a1163 commit 7cfff79
Show file tree
Hide file tree
Showing 16 changed files with 86 additions and 71 deletions.
6 changes: 6 additions & 0 deletions .changeset/warm-seals-peel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'orga': minor
'@orgajs/editor': patch
---

headline elements (stars, todo keywords and priority) end after the whitespaces
4 changes: 2 additions & 2 deletions packages/editor/lib/plugins/cleanup.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export const cleanupPlugin = ViewPlugin.define(
})
},
},
}
},
)

/**
Expand Down Expand Up @@ -134,7 +134,7 @@ function createDecorations(view, decorations = Decoration.none) {
add: [
Decoration.replace({
revealRange,
}).range(node.from, node.to + 1), // hide the space too
}).range(node.from, node.to),
],
})
}
Expand Down
4 changes: 2 additions & 2 deletions packages/orga/src/__tests__/footnote/stopped by headline.json
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@
},
"end": {
"line": 3,
"column": 2,
"offset": 59
"column": 3,
"offset": 60
}
}
},
Expand Down
4 changes: 2 additions & 2 deletions packages/orga/src/__tests__/headline/broken drawer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
},
"end": {
"line": 1,
"column": 2,
"offset": 1
"column": 3,
"offset": 2
}
}
},
Expand Down
8 changes: 4 additions & 4 deletions packages/orga/src/__tests__/headline/drawers.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
},
"end": {
"line": 1,
"column": 2,
"offset": 1
"column": 3,
"offset": 2
}
}
},
Expand Down Expand Up @@ -237,8 +237,8 @@
},
"end": {
"line": 7,
"column": 2,
"offset": 77
"column": 3,
"offset": 78
}
}
},
Expand Down
24 changes: 12 additions & 12 deletions packages/orga/src/__tests__/headline/keyword.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@
},
"end": {
"line": 3,
"column": 2,
"offset": 27
"column": 3,
"offset": 28
}
}
},
Expand All @@ -71,8 +71,8 @@
},
"end": {
"line": 3,
"column": 7,
"offset": 32
"column": 8,
"offset": 33
}
}
},
Expand Down Expand Up @@ -142,8 +142,8 @@
},
"end": {
"line": 4,
"column": 2,
"offset": 47
"column": 3,
"offset": 48
}
}
},
Expand All @@ -159,8 +159,8 @@
},
"end": {
"line": 4,
"column": 7,
"offset": 52
"column": 8,
"offset": 53
}
}
},
Expand Down Expand Up @@ -230,8 +230,8 @@
},
"end": {
"line": 5,
"column": 2,
"offset": 67
"column": 3,
"offset": 68
}
}
},
Expand All @@ -247,8 +247,8 @@
},
"end": {
"line": 5,
"column": 7,
"offset": 72
"column": 8,
"offset": 73
}
}
},
Expand Down
24 changes: 12 additions & 12 deletions packages/orga/src/__tests__/headline/nested.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
},
"end": {
"line": 1,
"column": 2,
"offset": 1
"column": 3,
"offset": 2
}
}
},
Expand Down Expand Up @@ -127,8 +127,8 @@
},
"end": {
"line": 3,
"column": 3,
"offset": 25
"column": 4,
"offset": 26
}
}
},
Expand Down Expand Up @@ -183,8 +183,8 @@
},
"end": {
"line": 4,
"column": 4,
"offset": 42
"column": 5,
"offset": 43
}
}
},
Expand Down Expand Up @@ -331,8 +331,8 @@
},
"end": {
"line": 7,
"column": 3,
"offset": 69
"column": 4,
"offset": 70
}
}
},
Expand Down Expand Up @@ -415,8 +415,8 @@
},
"end": {
"line": 8,
"column": 2,
"offset": 84
"column": 3,
"offset": 85
}
}
},
Expand Down Expand Up @@ -471,8 +471,8 @@
},
"end": {
"line": 9,
"column": 3,
"offset": 98
"column": 4,
"offset": 99
}
}
},
Expand Down
8 changes: 4 additions & 4 deletions packages/orga/src/__tests__/headline/planning.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
},
"end": {
"line": 1,
"column": 2,
"offset": 1
"column": 3,
"offset": 2
}
}
},
Expand Down Expand Up @@ -162,8 +162,8 @@
},
"end": {
"line": 4,
"column": 2,
"offset": 45
"column": 3,
"offset": 46
}
}
},
Expand Down
12 changes: 6 additions & 6 deletions packages/orga/src/__tests__/headline/with tags.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
},
"end": {
"line": 1,
"column": 2,
"offset": 1
"column": 3,
"offset": 2
}
}
},
Expand Down Expand Up @@ -78,8 +78,8 @@
},
"end": {
"line": 2,
"column": 3,
"offset": 14
"column": 4,
"offset": 15
}
}
},
Expand Down Expand Up @@ -157,8 +157,8 @@
},
"end": {
"line": 3,
"column": 4,
"offset": 40
"column": 5,
"offset": 41
}
}
},
Expand Down
8 changes: 4 additions & 4 deletions packages/orga/src/__tests__/keyword/multiple todo.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@
},
"end": {
"line": 5,
"column": 2,
"offset": 87
"column": 3,
"offset": 88
}
}
},
Expand All @@ -105,8 +105,8 @@
},
"end": {
"line": 5,
"column": 8,
"offset": 93
"column": 9,
"offset": 94
}
}
},
Expand Down
8 changes: 4 additions & 4 deletions packages/orga/src/__tests__/keyword/todo.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@
},
"end": {
"line": 3,
"column": 2,
"offset": 27
"column": 3,
"offset": 28
}
}
},
Expand All @@ -71,8 +71,8 @@
},
"end": {
"line": 3,
"column": 7,
"offset": 32
"column": 8,
"offset": 33
}
}
},
Expand Down
2 changes: 2 additions & 0 deletions packages/orga/src/parse/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@ export function parser(lexer: Lexer, options: ParserOptions): Parser {
function finish() {
context.exitTo('document')
context.exit('document')
// algin the end position
context.tree.position.end = lexer.toPoint(lexer.now)
return context.tree
}

Expand Down
22 changes: 11 additions & 11 deletions packages/orga/src/tokenize/headline.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import tokenize from './__tests__/tok'
describe('tokenize headline', () => {
it('knows headlines', () => {
assert.deepEqual(tokenize('** a headline'), [
{ _text: '**', level: 2, type: 'stars' },
{ _text: '** ', level: 2, type: 'stars' },
{ _text: 'a headline', type: 'text', value: 'a headline' },
])

assert.deepEqual(tokenize('** _headline_'), [
{ _text: '**', level: 2, type: 'stars' },
{ _text: '** ', level: 2, type: 'stars' },
{
_text: '_headline_',
style: 'underline',
Expand All @@ -20,29 +20,29 @@ describe('tokenize headline', () => {
])

assert.deepEqual(tokenize('** a headline'), [
{ _text: '**', level: 2, type: 'stars' },
{ _text: '** ', level: 2, type: 'stars' },
{ _text: 'a headline', type: 'text', value: 'a headline' },
])

assert.deepEqual(tokenize('***** a headline'), [
{ _text: '*****', level: 5, type: 'stars' },
{ _text: '***** ', level: 5, type: 'stars' },
{ _text: 'a headline', type: 'text', value: 'a headline' },
])

assert.deepEqual(tokenize('* a 😀line'), [
{ _text: '*', level: 1, type: 'stars' },
{ _text: '* ', level: 1, type: 'stars' },
{ _text: 'a 😀line', type: 'text', value: 'a 😀line' },
])

assert.deepEqual(tokenize('* TODO [#A] a headline :tag1:tag2:'), [
{ _text: '*', level: 1, type: 'stars' },
{ _text: '* ', level: 1, type: 'stars' },
{
_text: 'TODO',
_text: 'TODO ',
actionable: true,
keyword: 'TODO',
type: 'todo',
},
{ _text: '[#A]', type: 'priority', value: '[#A]' },
{ _text: '[#A] ', type: 'priority', value: '[#A]' },
{ _text: 'a headline', type: 'text', value: 'a headline' },
{
_text: ':tag1:tag2:',
Expand All @@ -56,14 +56,14 @@ describe('tokenize headline', () => {
'* TODO [#A] a headline :tag1:123:#hash:@at:org-mode:under_score:98%:'
),
[
{ _text: '*', level: 1, type: 'stars' },
{ _text: '* ', level: 1, type: 'stars' },
{
_text: 'TODO',
_text: 'TODO ',
actionable: true,
keyword: 'TODO',
type: 'todo',
},
{ _text: '[#A]', type: 'priority', value: '[#A]' },
{ _text: '[#A] ', type: 'priority', value: '[#A]' },
{ _text: 'a headline', type: 'text', value: 'a headline' },
{
_text: ':tag1:123:#hash:@at:org-mode:under_score:98%:',
Expand Down
Loading

0 comments on commit 7cfff79

Please sign in to comment.