~ubuntu-branches/ubuntu/saucy/bluefish/saucy

« back to all changes in this revision

Viewing changes to src/doc_comments.c

  • Committer: Package Import Robot
  • Author(s): Daniel Leidert
  • Date: 2013-05-09 14:36:58 UTC
  • mfrom: (17.1.1 experimental)
  • Revision ID: package-import@ubuntu.com-20130509143658-kgqxj5c23oi0lk20
Tags: 2.2.4-2
* debian/control (Standards-Version): Bumped to 3.9.4.
* debian/copyright: Updated.

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
#include "undo_redo.h"
26
26
 
27
27
 
28
 
static void add_line_comment(Tdocument *doc, const gchar *commentstring, gint start, gint end) {
29
 
        gint i=0,coffset,commentstring_len;
 
28
static gint
 
29
add_line_comment(Tdocument *doc, const gchar *commentstring, gint start, gint end) {
 
30
        gint i=0,coffset=0,commentstring_len;
30
31
        gchar *buf;
31
32
 
32
33
        if (start!=0)   
38
39
        buf = doc_get_chars(doc,start,end);
39
40
        utf8_offset_cache_reset();
40
41
        
41
 
        coffset=start;
42
42
        doc_unre_new_group(doc);
43
43
        while (buf[i] != '\0') {
44
44
                if (i==0 || (buf[i]=='\n' && buf[i+1]!='\0')) {
45
45
                        gint cstart;
46
46
                        cstart = utf8_byteoffset_to_charsoffset_cached(buf, i+1);
47
 
                        doc_replace_text_backend(doc, commentstring, coffset+cstart, coffset+cstart);
 
47
                        doc_replace_text_backend(doc, commentstring, coffset+start+cstart, coffset+start+cstart);
48
48
                        coffset += commentstring_len;
49
49
                }
50
50
                i++;
51
51
        }
52
52
        g_free(buf);
53
53
        doc_unre_new_group(doc);
 
54
        return coffset;
54
55
}
55
56
 
56
57
static void remove_line_comment(Tdocument *doc, const gchar *buf, const gchar *commentstring, gint start, gint end) {
120
121
        
121
122
        doc_unre_new_group(doc);
122
123
        cstart = utf8_byteoffset_to_charsoffset_cached(buf, so);
123
 
        cend = so+strlen(so_commentstring);
 
124
        cend = cstart+strlen(so_commentstring);
 
125
        DEBUG_MSG("remove_block_comment, remove start-of-comment %d:%d\n",coffset+cstart, coffset+cend);
124
126
        doc_replace_text_backend(doc, NULL, coffset+cstart, coffset+cend);
125
127
        coffset -= (cend-cstart); 
126
128
        
148
150
        }
149
151
        if (n==0) {
150
152
                cstart = utf8_byteoffset_to_charsoffset_cached(buf, so);
151
 
                cend = so+strlen(eo_commentstring);
 
153
                cend = cstart+strlen(eo_commentstring);
 
154
                DEBUG_MSG("remove_block_comment, remove end-of-comment %d:%d\n",coffset+cstart, coffset+cend);
152
155
                doc_replace_text_backend(doc, NULL, coffset+cstart, coffset+cend);
153
156
        }
154
157
        
205
208
                offsete = gtk_text_iter_get_offset(&ite);
206
209
                DEBUG_MSG("got comment with type %d, so=%s\n",comment->type, comment->so);
207
210
                if (comment->type == comment_type_line) {
208
 
                        add_line_comment(doc, comment->so, offsets,offsete);
209
 
                        extraoffset = strlen(comment->so);
 
211
                        extraoffset = add_line_comment(doc, comment->so, offsets,offsete);
 
212
                        /*extraoffset = strlen(comment->so);*/
210
213
                } else {
211
214
                        add_block_comment(doc, comment->so, comment->eo, gtk_text_iter_get_offset(&its), gtk_text_iter_get_offset(&ite));
212
215
                        extraoffset = strlen(comment->so) + strlen(comment->eo);
215
218
                        /* the buffer has changes, so we have to re-set the iters from the offsets */
216
219
                        gtk_text_buffer_get_iter_at_offset(doc->buffer, &its, offsets);
217
220
                        gtk_text_buffer_get_iter_at_offset(doc->buffer, &ite, offsete+extraoffset);
 
221
                        DEBUG_MSG("toggle_comment, reset selection to %d:%d\n", gtk_text_iter_get_offset(&its), gtk_text_iter_get_offset(&ite));
218
222
                        gtk_text_buffer_select_range(doc->buffer,&its,&ite);
219
223
                }
220
224
        }