~ubuntu-branches/ubuntu/trusty/bluefish/trusty-proposed

« back to all changes in this revision

Viewing changes to src/doc_text_tools.c

  • Committer: Package Import Robot
  • Author(s): Daniel Leidert
  • Date: 2014-02-11 16:52:23 UTC
  • mfrom: (18.1.1 sid)
  • Revision ID: package-import@ubuntu.com-20140211165223-biu27kqbayqhfxu5
Tags: 2.2.5-1
* New upstream release.
  - Fixes a highlighting bug (LP: #1242387, #1263967).
* debian/control (Standards-Version): Bumped to 3.9.5.
  (Build-Depends): Added dh-autoreconf and some GTK related version info.
* debian/copyright: Fixed unversioned-copyright-format-uri.
* debian/rules: Use the autoreconf addon (closes: #737671).
* debian/upstream-signing-key.pgp: Added upstream keyring.
* debian/watch: Added signature URL.
* debian/source/include-binaries: Added debian/upstream-signing-key.pgp.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* Bluefish HTML Editor
2
2
 * doc_text_tools.c - text tools
3
3
 *
4
 
 * Copyright (C) 2008-2012 Olivier Sessink
 
4
 * Copyright (C) 2008-2013 Olivier Sessink
5
5
 *
6
6
 * This program is free software; you can redistribute it and/or modify
7
7
 * it under the terms of the GNU General Public License as published by
126
126
        doc_unre_new_group(doc);
127
127
}
128
128
 
 
129
#define WS_POS_UNDEFINED G_MAXINT
129
130
static void
130
131
split_lines_backend(Tdocument * doc, gint start, gint end)
131
132
{
132
133
        gint coffset = 0; /* the offset that we have introduced since the start of this function call */
133
134
        gint count = 0, tabsize;
134
 
        gint startws = 0, endws = 0, starti = start, endi = -1, requested_size; 
 
135
        gint startws = 0, endws = 0, starti = start, endi = -1, requested_size;
135
136
        /* ws= whitespace, i=indenting, these are character positions in the GtkTextBufferr !!!!!!!! */
136
137
        gint charpos;
137
138
        gchar *buf, *p;
146
147
        DEBUG_MSG("split_lines_backend, from %d:%d on right margin %d\n",start,end, requested_size);
147
148
        c = g_utf8_get_char(p);
148
149
        while (c != '\0') {
149
 
                if (count > requested_size) {
 
150
#ifdef DEBUGSPLIT
 
151
                g_print("%d '%c'\n",charpos,c<128?c:'Q');
 
152
#endif
 
153
                if (count > requested_size && startws!=WS_POS_UNDEFINED) {
150
154
                        gchar *new_indenting, *tmp1, *tmp2;
151
155
                        if (startws >= endws)
152
156
                                endws = charpos;
153
 
                        DEBUG_MSG("split_lines, count=%d, startws=%d, endws=%d, coffset=%d c='%c'\n", count, startws,
 
157
                        DEBUG_MSG("split_lines, count=%d(>%d), startws=%d, endws=%d, coffset=%d c='%c'\n", count,requested_size, startws,
154
158
                                          endws, coffset, c);
155
159
                        if (starti == endi || endi==-1) {
156
160
                                new_indenting = g_strdup("\n");
165
169
                        }
166
170
                        DEBUG_MSG("split_lines_backend, replace from startws=%d to endws=%d with offset %d with new indenting\n", startws, endws, coffset);
167
171
                        count = charpos - endws;
 
172
#ifdef DEBUGSPLIT
 
173
                        tmp1 = doc_get_chars(doc, startws + coffset, endws + coffset);
 
174
                        g_print("replace '%s' with newline + identing\n",tmp1);
 
175
                        g_free(tmp1);
 
176
#endif
168
177
                        doc_replace_text_backend(doc, new_indenting, startws + coffset, endws + coffset);
169
178
                        coffset += (g_utf8_strlen(new_indenting, -1) - (endws - startws));
170
 
                        DEBUG_MSG("split_lines_backend, new coffset=%d, new count=%d\n", coffset, count);
171
 
                        startws = charpos;
172
 
                        endws = charpos;
 
179
                        DEBUG_MSG("split_lines_backend, new coffset=%d, new count=%d, set startws=%d and endws=%d\n", coffset, count, 0,charpos);
 
180
                        startws = WS_POS_UNDEFINED;
 
181
                        endws = WS_POS_UNDEFINED;
173
182
                        g_free(new_indenting);
174
183
                }
175
184
                if (c == '\t') {
176
185
                        count += tabsize;
177
 
                        if (startws < endws) {
 
186
                        if (startws < endws || startws==WS_POS_UNDEFINED) {
178
187
                                startws = charpos;
179
188
                                endws = charpos;
180
189
                                DEBUG_MSG("split_lines_backend, tab, set startws to %d\n", startws);
181
190
                        }
182
191
                } else if (c == ' ') {
183
192
                        count++;
184
 
                        if (startws < endws) {
 
193
                        if (startws < endws || startws==WS_POS_UNDEFINED) {
185
194
                                startws = charpos;
186
195
                                endws = charpos;
187
196
                                DEBUG_MSG("split_lines_backend, space, set startws to %d\n", startws);
195
204
                        count++;
196
205
                        if (starti > endi) {
197
206
                                endi = charpos;
198
 
                                DEBUG_MSG("split_lines_backend, non-whitespace, set endi to %d, starti=%d\n", endi, starti);
199
 
                        } else if (startws >= endws) {
 
207
                                DEBUG_MSG("split_lines_backend, non-whitespace (%c) and no valid endi, set endi to %d, starti=%d\n", c<128?c:'Q',endi, starti);
 
208
                        } else if (startws >= endws && startws!=WS_POS_UNDEFINED) {
200
209
                                endws = charpos;
201
 
                                DEBUG_MSG("split_lines_backend, non-whitespace, set endws to %d\n", endws);
 
210
                                DEBUG_MSG("split_lines_backend, non-whitespace (%c) and no valid endws, set endws to %d\n", c<128?c:'Q', endws);
202
211
                        }
203
212
                }
204
213
                p = g_utf8_next_char(p);
434
443
        } else {
435
444
                innerblock = !innerblock;
436
445
        }
437
 
        
 
446
 
438
447
        gtk_text_buffer_get_iter_at_mark(doc->buffer, &cursor, gtk_text_buffer_get_insert(doc->buffer));
439
448
        DEBUG_MSG("select_between_matching_block_boundaries, innerblock=%d, location=%d\n", innerblock, gtk_text_iter_get_offset(&cursor));
440
449
        offset = gtk_text_iter_get_offset(&cursor);
441
 
        if (!bluefish_text_view_get_active_block_boundaries(BLUEFISH_TEXT_VIEW(doc->view), 
 
450
        if (!bluefish_text_view_get_active_block_boundaries(BLUEFISH_TEXT_VIEW(doc->view),
442
451
                                        offset, innerblock, &so, &eo)) {
443
452
                DEBUG_MSG("select_between_matching_block_boundaries, no block, return\n");
444
453
                return;
446
455
        if (innerblock && gtk_text_iter_equal(&so, &eo)) {
447
456
                DEBUG_MSG("select_between_matching_block_boundaries, iters are equal, request innerblock=FALSE\n");
448
457
                innerblock = FALSE;
449
 
                if (!bluefish_text_view_get_active_block_boundaries(BLUEFISH_TEXT_VIEW(doc->view), 
 
458
                if (!bluefish_text_view_get_active_block_boundaries(BLUEFISH_TEXT_VIEW(doc->view),
450
459
                                                offset, innerblock, &so, &eo)) {
451
460
                        DEBUG_MSG("select_between_matching_block_boundaries, innerblock=FALSE, no block, return\n");
452
461
                        return;
453
 
                }       
 
462
                }
454
463
        }
455
464
        gtk_text_buffer_select_range(doc->buffer, &so, &eo);
456
465
}
485
494
}
486
495
 
487
496
void
488
 
doc_move_selection(Tdocument *doc, gboolean up)
 
497
doc_move_selection(Tdocument *doc, gboolean up, gboolean curline_if_no_selection)
489
498
{
490
499
        GtkTextIter so, eo;
491
500
        gchar *text;
492
501
        gint offset, size;
493
502
        if (!gtk_text_buffer_get_selection_bounds(doc->buffer, &so, &eo)) {
494
 
                return;
 
503
                DEBUG_MSG("doc_move_selection, no selection, select the current line!\n");
 
504
                if (curline_if_no_selection) {
 
505
                        gtk_text_buffer_get_iter_at_mark(doc->buffer,&so,gtk_text_buffer_get_insert(doc->buffer));
 
506
                        eo = so;
 
507
                } else {
 
508
                        return;
 
509
                }
495
510
        }
496
511
        /* so and eo are guaranteed to be in ascending order */
 
512
        if (gtk_text_iter_equal(&so, &eo)) {
 
513
                gtk_text_iter_forward_char(&eo);
 
514
        }
 
515
        if (!gtk_text_iter_starts_line(&so))
 
516
                gtk_text_iter_set_line_offset(&so, 0);
 
517
        if (!gtk_text_iter_starts_line(&eo))
 
518
                gtk_text_iter_forward_line(&eo);
 
519
 
497
520
        doc_unre_new_group(doc);
498
521
        doc_block_undo_reg(doc);
499
 
        
 
522
 
500
523
        offset = gtk_text_iter_get_offset(&so);
 
524
        DEBUG_MSG("start moving text from %d:%d\n",gtk_text_iter_get_offset(&so),gtk_text_iter_get_offset(&eo));
501
525
        size = gtk_text_iter_get_offset(&eo)-offset;
502
526
        text = gtk_text_buffer_get_text(doc->buffer,&so,&eo,TRUE);
503
527
        /*g_print("doc_move_selection, got selection %d:%d\n",offset,offset+size);*/
504
528
        gtk_text_buffer_delete(doc->buffer, &so, &eo);
505
529
        doc_unre_add(doc, text, offset, offset+size, UndoDelete);
506
530
 
507
 
        /* now we have to move the cursor up */
 
531
        /* now we have to move the cursor up,
 
532
        because we changed the text we invalidated all iters, so get them again */
508
533
        gtk_text_buffer_get_iter_at_offset(doc->buffer, &so, offset);
509
534
        if (up) {
510
535
                gtk_text_iter_backward_line(&so);
 
536
                DEBUG_MSG("UP -> new start location is at %d\n",gtk_text_iter_get_offset(&so));
511
537
        } else {
512
538
                gtk_text_iter_forward_line(&so);
 
539
                DEBUG_MSG("DOWN -> new start location is at %d\n",gtk_text_iter_get_offset(&so));
513
540
        }
514
541
        offset = gtk_text_iter_get_offset(&so);
515
542
        gtk_text_buffer_insert(doc->buffer,&so,text,-1);
519
546
        doc_unblock_undo_reg(doc);
520
547
        doc_set_modified(doc, 1);
521
548
        doc_unre_new_group(doc);
522
 
        
 
549
 
523
550
        /* and select the text again */
524
 
        /*g_print("doc_move_selection, select %d:%d\n",offset,offset+size);*/
 
551
        DEBUG_MSG("doc_move_selection, select %d:%d\n",offset,offset+size);
525
552
        gtk_text_buffer_get_iter_at_offset(doc->buffer, &so, offset);
526
553
        gtk_text_buffer_get_iter_at_offset(doc->buffer, &eo, offset+size);
 
554
        DEBUG_MSG("select new location %d:%d\n",gtk_text_iter_get_offset(&so),gtk_text_iter_get_offset(&eo));
527
555
        gtk_text_buffer_select_range(doc->buffer,&so,&eo);
528
556
}
529
557
 
537
565
        tmp = run_file_select_dialog(GTK_WINDOW(BFWIN(doc->bfwin)->main_window)
538
566
                                                        , NULL, relativeto,GTK_FILE_CHOOSER_ACTION_OPEN);
539
567
        if (tmp)
540
 
                doc_insert_two_strings(doc, tmp, NULL); 
 
568
                doc_insert_two_strings(doc, tmp, NULL);
541
569
        g_free(relativeto);
542
570
        g_free(tmp);
543
571
}