Skip to content

Commit

Permalink
Fix editor syntax highlighting (bug #613089)
Browse files Browse the repository at this point in the history
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.1@2639 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
  • Loading branch information
michaelrsweet committed Sep 26, 2002
1 parent 0c00359 commit 7ef44a5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGES
Expand Up @@ -2,6 +2,8 @@ CHANGES IN FLTK 1.1.0

- Added some more range checking to the Fl_Text_Display
widget.
- The editor demo did not correctly update the style
(syntax highlighting) information.


CHANGES IN FLTK 1.1.0rc7
Expand Down
17 changes: 13 additions & 4 deletions test/editor.cxx
@@ -1,5 +1,5 @@
//
// "$Id: editor.cxx,v 1.2.2.3.2.14 2002/09/20 19:59:45 easysw Exp $"
// "$Id: editor.cxx,v 1.2.2.3.2.15 2002/09/26 20:43:03 easysw Exp $"
//
// A simple text editor program for the Fast Light Tool Kit (FLTK).
//
Expand Down Expand Up @@ -173,13 +173,17 @@ style_parse(const char *text,
const char *temp;

for (current = *style, col = 0, last = 0; length > 0; length --, text ++) {
if (current == 'B') current = 'A';
if (current == 'A') {
// Check for directives, comments, strings, and keywords...
if (col == 0 && *text == '#') {
// Set style to directive
current = 'E';
} else if (strncmp(text, "//", 2) == 0) {
current = 'B';
for (; length > 0 && *text != '\n'; length --, text ++) *style++ = 'B';

if (length == 0) break;
} else if (strncmp(text, "/*", 2) == 0) {
current = 'C';
} else if (strncmp(text, "\\\"", 2) == 0) {
Expand Down Expand Up @@ -319,7 +323,7 @@ style_update(int pos, // I - Position of update
int nInserted, // I - Number of inserted chars
int nDeleted, // I - Number of deleted chars
int /*nRestyled*/, // I - Number of restyled chars
const char * /*deletedText*/, // I - Text that was deleted
const char * /*deletedText*/,// I - Text that was deleted
void *cbArg) { // I - Callback data
int start, // Start of text
end; // End of text
Expand Down Expand Up @@ -358,13 +362,18 @@ style_update(int pos, // I - Position of update
// style character and keep updating if we have a multi-line
// comment character...
start = textbuf->line_start(pos);
end = textbuf->line_end(pos + nInserted - nDeleted);
end = textbuf->line_end(pos + nInserted);
text = textbuf->text_range(start, end);
style = stylebuf->text_range(start, end);
last = style[end - start - 1];

printf("start = %d, end = %d, text = \"%s\", style = \"%s\"...\n",
start, end, text, style);

style_parse(text, style, end - start);

printf("new style = \"%s\"...\n", style);

stylebuf->replace(start, end, style);
((Fl_Text_Editor *)cbArg)->redisplay_range(start, end);

Expand Down Expand Up @@ -762,5 +771,5 @@ int main(int argc, char **argv) {
}

//
// End of "$Id: editor.cxx,v 1.2.2.3.2.14 2002/09/20 19:59:45 easysw Exp $".
// End of "$Id: editor.cxx,v 1.2.2.3.2.15 2002/09/26 20:43:03 easysw Exp $".
//

0 comments on commit 7ef44a5

Please sign in to comment.