-
Notifications
You must be signed in to change notification settings - Fork 0
Add Syntax Highlighting binding for TextBuffer #87
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
cf2f7bf
add TableIterator (#79)
defname 6314f66
Add early-exit guards to table lookup functions (#80)
defname 6802145
Add CodeRabbit configuration template
defname c42caad
Merge branch 'main' into feat/71-syntax-highlighting
defname b7fce6c
add SyntaxHighlightingBinding to connect SyntaxHighlighting with the …
defname c0f1c11
fix some obvious bugs in SyntaxHighlighingBinding
defname 5d44d53
fix memory leak
defname c28e50e
add basic test
defname f5e0b14
add Stack_Size()
defname 57bc8db
rename test function
defname 1f598f8
add Stack_CopyTo()
defname 517e941
save open_blocks_at_begin and open_blocks_at_end to SyntaxHighlightin…
defname 6229560
Merge branch 'feat/71-syntax-highlighting' into feat/sh-tb-bindings
defname f748bb5
adept code to the changed SyntaxHighlighingString scheme
defname c13c280
improve tests
defname 154937f
Compare the open_blocks_at_begin with the open_blocks parameter for a…
defname 558c925
add testcases and improve test framework's flexibility
defname f412a0d
fix coderabbit config
defname 0b223a6
fix resizing in Stack_CopyTo()
defname cb33a8f
add NULL guard to SyntaxHighlighting_HighlightString()
defname 6b6703b
change multiline string to valid C string
defname 811b0e2
change multiline strings to valid C strings
defname b0a7167
set shs->tags_capacity correctly in SyntaxHighlioghtingString_Create()
defname File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,51 @@ | ||
| #include "textlayoutbindings.h" | ||
|
|
||
| void SyntaxHighlightingBinding_Init(SyntaxHighlightingBinding *binding, const TextLayout *tl, SyntaxHighlighting *sh) { | ||
| binding->tl = tl; | ||
| binding->sh = sh; | ||
| } | ||
|
|
||
| void SyntaxHighlightingBinding_Deinit(SyntaxHighlightingBinding *binding) { | ||
| binding->tl = NULL; | ||
| binding->sh = NULL; | ||
| } | ||
|
|
||
| static void update_lines(SyntaxHighlightingBinding *binding, const Line *line, const Line *last_line, const Stack *open_blocks) { | ||
| const Stack *open_blocks_begin = open_blocks; | ||
| while (line) { | ||
| // open_blocks == NULL is also handled by the function | ||
| const Stack *open_blocks_end = SyntaxHighlighting_HighlightString(binding->sh, &line->text, open_blocks_begin); | ||
| open_blocks_begin = open_blocks_end; | ||
| if (line == last_line) { | ||
| break; | ||
| } | ||
| line = line->next; | ||
| } | ||
| } | ||
|
|
||
| void SyntaxHighlightingBinding_Update(SyntaxHighlightingBinding *binding, const Line *line, const Line *last_line) { | ||
| Line *prev_line = line->prev; | ||
| Stack *open_blocks = NULL; | ||
| if (prev_line) { | ||
| // check if highlighting for the previous line is already calculated | ||
| SyntaxHighlightingString *shs = Table_Get(binding->sh->strings, &prev_line->text); | ||
| if (shs) { | ||
| // use the open_blocks from the end of previous line | ||
| open_blocks = &shs->open_blocks_at_end; | ||
| } | ||
| else { | ||
| // highlighting for the line is not calculated so far | ||
| // so run this function for thr previous line | ||
| SyntaxHighlightingBinding_Update(binding, prev_line, last_line); | ||
| return; | ||
| } | ||
| } | ||
| if (line == binding->tl->tb->current_line) { | ||
| // this is super dirty cause the gap funcitonality is totally disabled this way!!! | ||
| // NEED A BETTER SOLUTION | ||
| TextBuffer_MergeGap((TextBuffer*)binding->tl->tb); | ||
| } | ||
|
|
||
| // update all lines until last_line (including) | ||
| update_lines(binding, line, last_line, open_blocks); | ||
| } |
This file contains hidden or 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,17 @@ | ||
| #ifndef SYNTAX_TEXTLAYOUTBINDINGS_H | ||
| #define SYNTAX_TEXTLAYOUTBINDINGS_H | ||
|
|
||
| #include "highlighting.h" | ||
| #include "document/textlayout.h" | ||
|
|
||
| typedef struct _SyntaxHighlightingBinding { | ||
| const TextLayout *tl; | ||
| SyntaxHighlighting *sh; | ||
| } SyntaxHighlightingBinding; | ||
|
|
||
| void SyntaxHighlightingBinding_Init(SyntaxHighlightingBinding *binding, const TextLayout *tl, SyntaxHighlighting *sh); | ||
| void SyntaxHighlightingBinding_Deinit(SyntaxHighlightingBinding *binding); | ||
|
|
||
| void SyntaxHighlightingBinding_Update(SyntaxHighlightingBinding *binding, const Line *line, const Line *last_line); | ||
|
|
||
| #endif |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.