mirror of
https://github.com/rfivet/uemacs.git
synced 2025-09-25 22:54:02 -04:00
Make cursor movement (largely) understand UTF-8 character boundaries
Ok, so it may do odd things if it's not truly utf-8, and when moving up and down lines that have utf-8 the cursor moves oddly (because the byte offset within the line stays constant, rather than the character offset), but with this you can actually open the UTF8 example file and move around it, and at least some of the movement makes sense. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
26
basic.c
26
basic.c
@@ -15,6 +15,7 @@
|
||||
#include "edef.h"
|
||||
#include "efunc.h"
|
||||
#include "line.h"
|
||||
#include "utf8.h"
|
||||
|
||||
/*
|
||||
* This routine, given a pointer to a struct line, and the current cursor goal
|
||||
@@ -74,8 +75,15 @@ int backchar(int f, int n)
|
||||
curwp->w_dotp = lp;
|
||||
curwp->w_doto = llength(lp);
|
||||
curwp->w_flag |= WFMOVE;
|
||||
} else
|
||||
curwp->w_doto--;
|
||||
} else {
|
||||
do {
|
||||
unsigned char c;
|
||||
curwp->w_doto--;
|
||||
c = lgetc(curwp->w_dotp, curwp->w_doto);
|
||||
if (is_beginning_utf8(c))
|
||||
break;
|
||||
} while (curwp->w_doto);
|
||||
}
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
@@ -100,14 +108,22 @@ int forwchar(int f, int n)
|
||||
if (n < 0)
|
||||
return backchar(f, -n);
|
||||
while (n--) {
|
||||
if (curwp->w_doto == llength(curwp->w_dotp)) {
|
||||
int len = llength(curwp->w_dotp);
|
||||
if (curwp->w_doto == len) {
|
||||
if (curwp->w_dotp == curbp->b_linep)
|
||||
return FALSE;
|
||||
curwp->w_dotp = lforw(curwp->w_dotp);
|
||||
curwp->w_doto = 0;
|
||||
curwp->w_flag |= WFMOVE;
|
||||
} else
|
||||
curwp->w_doto++;
|
||||
} else {
|
||||
do {
|
||||
unsigned char c;
|
||||
curwp->w_doto++;
|
||||
c = lgetc(curwp->w_dotp, curwp->w_doto);
|
||||
if (is_beginning_utf8(c))
|
||||
break;
|
||||
} while (curwp->w_doto < len);
|
||||
}
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
Reference in New Issue
Block a user