[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [41839] trunk/blender/source/blender/ blenkernel/intern/text.c: Text Editor: implement space-as-tab navigation
Dalai Felinto
dfelinto at gmail.com
Mon Nov 14 18:33:32 CET 2011
Revision: 41839
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=41839
Author: dfelinto
Date: 2011-11-14 17:33:32 +0000 (Mon, 14 Nov 2011)
Log Message:
-----------
Text Editor: implement space-as-tab navigation
When "use tab as space" is on we will jump the spaces as if they were one single tab when navigating (left/right).
Tabsize still is hardcoded to 4, but this is a separate design issue left for another patch.
* patch done in the airplane while expaining the Text Editor code for a potencial new coder @ Blender PRO 2011 *
Modified Paths:
--------------
trunk/blender/source/blender/blenkernel/intern/text.c
Modified: trunk/blender/source/blender/blenkernel/intern/text.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/text.c 2011-11-14 17:31:47 UTC (rev 41838)
+++ trunk/blender/source/blender/blenkernel/intern/text.c 2011-11-14 17:33:32 UTC (rev 41839)
@@ -796,6 +796,7 @@
{
TextLine **linep;
int *charp, oundoing= undoing;
+ int tabsize = 1, i=0;
if (!text) return;
if(sel) txt_curs_sel(text, &linep, &charp);
@@ -803,14 +804,34 @@
if (!*linep) return;
undoing= 1;
+
+ // do nice left only if there are only spaces
+ // TXT_TABSIZE hardcoded in DNA_text_types.h
+ if (text->flags & TXT_TABSTOSPACES) {
+ tabsize = TXT_TABSIZE;
+
+ if (*charp < tabsize)
+ tabsize = *charp;
+ else {
+ for (i=0;i<(*charp);i++)
+ if ((*linep)->line[i] != ' ') {
+ tabsize = 1;
+ break;
+ }
+ // if in the middle of the space-tab
+ if ((*charp) % tabsize != 0)
+ tabsize = ((*charp) % tabsize);
+ }
+ }
+
if (*charp== 0) {
if ((*linep)->prev) {
txt_move_up(text, sel);
*charp= (*linep)->len;
}
- } else {
- (*charp)--;
}
+ else (*charp)-= tabsize;
+
undoing= oundoing;
if(!undoing) txt_undo_add_op(text, sel?UNDO_SLEFT:UNDO_CLEFT);
@@ -821,6 +842,7 @@
{
TextLine **linep;
int *charp, oundoing= undoing;
+ int tabsize=1, i=0;
if (!text) return;
if(sel) txt_curs_sel(text, &linep, &charp);
@@ -828,13 +850,32 @@
if (!*linep) return;
undoing= 1;
+
+ // do nice right only if there are only spaces
+ // spaces hardcoded in DNA_text_types.h
+ if (text->flags & TXT_TABSTOSPACES) {
+ tabsize = TXT_TABSIZE;
+
+ if ((*charp) + tabsize > (*linep)->len)
+ tabsize = 1;
+ else {
+ for (i=0;i<(*charp) + tabsize - ((*charp) % tabsize);i++)
+ if ((*linep)->line[i] != ' ') {
+ tabsize = 1;
+ break;
+ }
+ // if in the middle of the space-tab
+ tabsize -= (*charp) % tabsize;
+ }
+ }
+
if (*charp== (*linep)->len) {
if ((*linep)->next) {
txt_move_down(text, sel);
*charp= 0;
}
} else {
- (*charp)++;
+ (*charp)+=tabsize;
}
undoing= oundoing;
if(!undoing) txt_undo_add_op(text, sel?UNDO_SRIGHT:UNDO_CRIGHT);
More information about the Bf-blender-cvs
mailing list