Skip to content

Commit 790aaaf

Browse files
committed
improve word wrap for indents and bullet lists
Not perfect, but an improvement
1 parent 9a42f7d commit 790aaaf

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

Buffer.c

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -902,7 +902,18 @@ void Buffer_nextPage(Buffer* this) {
902902
this->selecting = false;
903903
}
904904

905-
void Buffer_wordWrap(Buffer* this, int wrap) {
905+
void Buffer_wordWrap(Buffer* this, int wrap, int indent) {
906+
if (indent == -1) {
907+
indent = 0;
908+
for (int i = 0; i < last_x(this); i++) {
909+
int ch = Line_charAt(this->line, i);
910+
if (ch == ' ' || ch == '*') {
911+
indent++;
912+
} else {
913+
break;
914+
}
915+
}
916+
}
906917
Undo_beginGroup(this->undo, this->x, this->y);
907918
int minLen = this->dosLineBreaks ? 1 : 0;
908919
while (this->line->super.next && Line_chars((Line*)this->line->super.next) > minLen) {
@@ -919,7 +930,7 @@ void Buffer_wordWrap(Buffer* this, int wrap) {
919930
Buffer_deleteChar(this);
920931
}
921932
this->line = (Line*) Panel_getSelected(this->panel);
922-
Buffer_wordWrap(this, wrap);
933+
Buffer_wordWrap(this, wrap, indent);
923934
}
924935
while (last_x(this) > wrap) {
925936
Line* oldLine = this->line;
@@ -928,6 +939,11 @@ void Buffer_wordWrap(Buffer* this, int wrap) {
928939
this->x = i;
929940
Buffer_deleteChar(this);
930941
Buffer_breakLine(this);
942+
if (indent > 0) {
943+
for (int j = 0; j < indent; j++) {
944+
Buffer_defaultKeyHandler(this, ' ', false);
945+
}
946+
}
931947
break;
932948
}
933949
}

Prototypes.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ void Buffer_endOfFile(Buffer* this);
167167
int Buffer_size(Buffer* this);
168168
void Buffer_previousPage(Buffer* this);
169169
void Buffer_nextPage(Buffer* this);
170-
void Buffer_wordWrap(Buffer* this, int wrap);
170+
void Buffer_wordWrap(Buffer* this, int wrap, int indent);
171171
void Buffer_deleteBlock(Buffer* this);
172172
char* Buffer_copyBlock(Buffer* this, int *len);
173173
void Buffer_pasteBlock(Buffer* this, Text block);

dit.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1028,7 +1028,7 @@ static void Dit_find(Buffer* buffer, TabManager* tabs) {
10281028

10291029
static void Dit_wordWrap(Buffer* buffer) {
10301030
buffer->selecting = false;
1031-
Buffer_wordWrap(buffer, 78);
1031+
Buffer_wordWrap(buffer, 78, -1);
10321032
}
10331033

10341034
static void Dit_undo(Buffer* buffer, TabManager* tabs) {

0 commit comments

Comments
 (0)