Skip to content
Permalink
Browse files
Add decoration for link
  • Loading branch information
Seunguk Shin committed Nov 28, 2021
1 parent e5d4c2d commit 0917911413de08604b14568b95f314ab40630b77
Showing with 77 additions and 2 deletions.
  1. +16 −1 README.md
  2. +41 −0 src/decoration.ts
  3. +14 −0 src/parser.ts
  4. +6 −1 syntaxes/org.tmLanguage.json
@@ -28,4 +28,19 @@ Integrates [Org](https://orgmode.org) into VS Code.
| Head Level | Maximum head level | 6 |
| Update Delay | Update UI delay for indent and fold in ms | 10 |
| Indent | Indent heads | true |
| Fold | Fold by heads | true |
| Fold | Fold by heads | true |

## Fetures
- [x] Highlight for Org syntax
- [x] Hide leading stars
- [x] Start up indented
- [x] Promotion or demotion for a haed or a tree of head
- [x] Set a state
- [x] Calculate the state of children
- [x] Configure for a state
- [x] Insert schedule or deadline date
- [x] Folding source block
- [ ] Handling a link
- [ ] Start up folded
- [ ] Inline image
- [ ] Highlight for source syntax
@@ -12,6 +12,9 @@ export class Decoration implements vscode.Disposable {
private doneState: string;
private todoType: vscode.TextEditorDecorationType;
private doneType: vscode.TextEditorDecorationType;
private descRegex: RegExp;
private linkType: vscode.TextEditorDecorationType;
private hideType: vscode.TextEditorDecorationType;

constructor(parser: Parser) {
this.config = Config.getInstance();
@@ -67,6 +70,27 @@ export class Decoration implements vscode.Disposable {
'color': 'rgba(0, 255, 0, 1.0)'
}
});

// links
this.descRegex = new RegExp('\\]\\[', 'g');
this.linkType = vscode.window.createTextEditorDecorationType({
'light': {
'color': 'rgba(0, 128, 255, 1.0)'
},
'dark': {
'color': 'rgba(0, 128, 255, 1.0)'
}
});
this.hideType = vscode.window.createTextEditorDecorationType({
'light': {
'color': 'rgba(0, 128, 255, 0.0)',
'letterSpacing': '-256px'
},
'dark': {
'color': 'rgba(0, 128, 255, 0.0)',
'letterSpacing': '-256px'
}
});
}

dispose(): void {
@@ -129,11 +153,28 @@ export class Decoration implements vscode.Disposable {

h = h.nextHead;
}

// links
const link: vscode.Range[] = [];
const hide: vscode.Range[] = [];
for (let range of this.parser.getLinks()) {
const start = range.start;
const end = range.end;
const text = editor.document.getText(range);
const match = this.descRegex.exec(text);
const offset = (match) ? match.index + 2 : 2;
hide.push(new vscode.Range(start.line, start.character, start.line, start.character + offset))
hide.push(new vscode.Range(end.line, end.character - 2, end.line, end.character));
link.push(new vscode.Range(start.line, start.character + offset, end.line, end.character - 2));
}

for (i = 0; i < this.level; i++) {
editor.setDecorations(this.headType[i], head[i]);
editor.setDecorations(this.bodyType[i], body[i]);
}
editor.setDecorations(this.todoType, todo);
editor.setDecorations(this.doneType, done);
editor.setDecorations(this.linkType, link);
editor.setDecorations(this.hideType, hide);
}
}
@@ -8,15 +8,19 @@ export class Parser implements vscode.Disposable {
private state: string[];
private headRegex: RegExp;
private countRegex: RegExp;
private linkRegex: RegExp;
private first: Head | undefined;
private links: vscode.Range[];

constructor(context: vscode.ExtensionContext) {
this.config = Config.getInstance();
this.level = this.config.get('headLevel');
this.state = (this.config.get('todoState') + ' ' + this.config.get('doneState')).split(' ');
this.headRegex = new RegExp('\\n[*]{1,' + this.level.toString() + '}\\s+|[\\s\\S]$', 'g');
this.countRegex = new RegExp('\\[\\d*\\/\\d*\\]', 'g');
this.linkRegex = new RegExp('\\[\\[[^\\n]+\\]\\]', 'g');
this.first = undefined;
this.links = [];
}

dispose(): void {
@@ -28,6 +32,7 @@ export class Parser implements vscode.Disposable {
return Promise.resolve();
}
this.first = undefined;
this.links = [];
const text = editor.document.getText();
let match;
const parent: Head[] = [];
@@ -111,6 +116,11 @@ export class Parser implements vscode.Disposable {
prevHead = head;
}
}
while (match = this.linkRegex.exec(text)) {
const start = editor.document.positionAt(match.index);
const end = editor.document.positionAt(match.index + match[0].length);
this.links.push(new vscode.Range(start, end));
}
return Promise.resolve();
}

@@ -129,4 +139,8 @@ export class Parser implements vscode.Disposable {
}
return h;
}

getLinks(): vscode.Range[] {
return this.links;
}
}
@@ -5,7 +5,7 @@
{
"comment": "org metadata",
"name": "keyword.control",
"match": "^#+\\S+:"
"match": "^#+\\S+:?"
},
{
"comment": "org level 1",
@@ -70,6 +70,7 @@
{ "include": "#done" },
{ "include": "#count" },
{ "include": "#tag" },
{ "include": "#link"},
{ "include": "#common" }
]
},
@@ -102,6 +103,10 @@
"name": "markup.bold",
"match": "(:)\\b(\\S+)\\b(:)"
},
"link": {
"name": "markup.underline",
"match": "\\[\\[[^\\n]+\\]\\]"
},
"time-prop": {
"name": "keyword.control",
"match": "\\b(SCHEDULED|DEADLINE)\\b:"

0 comments on commit 0917911

Please sign in to comment.